Currently the underlying backup/restore code does not differentiate null
and empty array data. So we have to explicitly check that we got array,
even though the correct set_stash() was called.
These static caches were bad idea of mine. Multiple conversion jobs
executed from a single PHP script share such variables, of course, which
is wrong. This patch removes one static cache completely and
reimplements the other two static caches as normal member variables.
Returning the converted array has no benefit here and makes the things
more complicated. From now on, the method is supposed to write what it
needs directly into the opened file, without returning anything.
This patch introduces a framework for the question bank conversion. It
deals with the common question data (that are not qtype-specific) and
the way how to make sure that the qtype plugins have access to the paths
they are interested in.
Grouped elements contain arrays with the sub-paths. This patch makes
sure that the sub-paths are pre-cooked recursively. However because the
recipes do not distinguish the full path to the element, only the
implicit recipe (making the tags lowecase) is applied. To avoid
potential data loss (for example dropfields recipe would delete all
fields from the whole grouped tree, not only the direct descendants of
the path where the recipe is declared), explicit recipes are forbidden
for grouped elements. The developer has to convert the $data manually as
needed.
In case the source $rootpath passed to the migrate_directory() does not
exist, an empty array is returned by the method. Note that if the
directory exists and is empty, the directory itself is converter so
there would be a new record created. However, the restore process
ignores these records anyway, as the directory records are created
automatically by certain file api methods.
The new file manager class is introduced. Once its public properties are
set, one can use it to migrate either a single file or a whole
directory. The course_files conversion reworked so that it uses the new
manager now. The files.xml written at the very end of the conversion,
giving all handlers a chance to migrate the files they need.
This is needed to give the modules a chance to actually rewrite course
modules related information. Resource module needs this so it is able to
split its own information into its successors (url, folder, page etc).
For system and course levels, we do not need itemid as we work with
single system context and single course context only. Thanks to this, we
can generate contextid for the restored course even we do not know its
original id yet.
This checks for the presence of moodle1 library in the module directory.
If there is no such file, the converter does not include the module in
the list of included modules.
Note that some files (like module.xml) are created for such skipped
modules anyway. But restore process seems to use the information from
moodle_backup.xml so it does not try to restore them.
It was realized that it is pretty common to register a convert_path just
to be able to attach on-start or on-end listeners to it, without actual
processing data. So now, the handler must provide at least one of these
three methods and the process_xxx() does not need to be there if it is
not needed.
The QUESTION_CATEGORIES tag is optional in moodle.xml but the file
questions.xml is required by the moodle2 restore process. So here we
make sure that at least an empty file is created.