This patch (it is the first I try to make) alters the /course package, adding the possibility to move any course module from a course to another, relocating it in the target course. The course module is moved after checking the module is moveable.
Module moveability is actually proposed as a course/lib.php additional function, that should proxy the implementation of how a module will tell the course it may be moveable or not.
Course module is moved along with its attached resources, pursuant they are stored within the moodledata/<courseid>/moddata/<coursemoduleid>/ directory. Original resources are cleaned out. All metadata
are correctly fixed, so are section assignements. The instance itself IS NOT renumbered so it remains unchanged.
A callback to an aditional module API is optional (called if exists in the module's lib). This callback will allow a module to perform additional custom data relocating. In case the callback is used, it overrides standard move of physical resources. The module programmer should procede himself to the physical resources relocation. Using a black callback code can disable the attempt to relocate physical files.
I tried moveability between two "topic" formated courses, but moveability relies on sections, so it should work between both course formats.
Moveability relies on two additional capabilities :
moodle/course:exportmodule : the capability the user has to export out a course module
moodle/course:importmodule : the capability the user has to import in a course module
The user MUST have both capabilities (export on source course, import on target course) to be allowed to perform the move.
STILL TO TODO : check inocuity of the move for complex modules. I tried with resources and forums, but some particular modules may be not so easy to move. Moveability check will disable this feature if there is no known moving strategy available.
Check what's the consequence over grades and logs.
FROM A END USER POINT OF VUE :
Moving a single resource is very interesting when a teacher (mainly the editing teacher needs to move resources) arranges a set of courses and reorganizes teaching materials. There is till now no easy way to do this unless destroying the resource and recreating it elsewhere (copy/cut content). This discourages using Moodle as the "major" authoring environment (so I use it !!), having all ressource (in work, in progress and published) as relocatable objects in courses.
Many people asked on forum the way to perform that kind of relocation. This patch may be an answer to that requirements.