Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Converter of Moodle 1.9 backup into Moodle 2.x format. More...
Public Member Functions | |
convert () | |
Converts the backup directory. | |
create_stash_storage () | |
Creates the temporary storage for stashed data. More... | |
drop_stash_storage () | |
Drops the temporary storage of stashed data. More... | |
get_contextid ($level, $instance=0) | |
Generates an artificial context id. More... | |
get_file_manager ($contextid=null, $component=null, $filearea=null, $itemid=0, $userid=null) | |
Creates and returns new instance of the file manager. More... | |
get_id () | |
Get instance identifier. More... | |
get_inforef_manager ($name, $id=0) | |
Creates and returns new instance of the inforef manager. More... | |
get_name () | |
Get converter name. More... | |
get_nextid () | |
Simple autoincrement generator. More... | |
get_stash ($stashname, $itemid=0) | |
Restores a given stash stored previously by self::set_stash(). More... | |
get_stash_itemids ($stashname) | |
Returns the list of stashed $itemids in the given stash. More... | |
get_stash_names () | |
Returns the list of existing stashes. More... | |
get_stash_or_default ($stashname, $itemid=0, $default=null) | |
Restores a given stash or returns the given default if there is no such stash. More... | |
get_tempdir_path () | |
get_workdir_path () | |
log ($message, $level, $a=null, $depth=null, $display=false) | |
This function will be responsible for handling the params, and to call to the corresponding logger->process() once all modifications in params have been performed. | |
path_end_reached ($path) | |
Executes operations required at the end of a watched path. More... | |
path_start_reached ($path) | |
Executes operations required at the start of a watched path. More... | |
process_chunk ($data) | |
Process the data obtained from the XML parser processor. More... | |
set_logger ($logger) | |
Sets the logger to use during the conversion. More... | |
set_stash ($stashname, $info, $itemid=0) | |
Stores some information for later processing. More... | |
Static Public Member Functions | |
static | description () |
static | detect_format ($tempdir) |
Detects the Moodle 1.9 format of the backup directory. More... | |
static | find_referenced_files ($text) |
Detects all links to file.php encoded via $@FILEPHP$ and returns the files to migrate. More... | |
static | is_available () |
public static methods ////////////////////////////////////////////////// More... | |
static | migrate_referenced_files ($text, moodle1_file_manager $fileman) |
Migrates all course files referenced from the hypertext using the given filemanager. More... | |
static | rewrite_filephp_usage ($text, array $files) |
Given the list of migrated files, rewrites references to them from $@FILEPHP$ form to the @PLUGINFILE@ one. More... | |
Public Attributes | |
const | SKIP_ALL_CHILDREN = -991399 |
Instructs the dispatcher to ignore all children below path processor returning it. | |
Protected Member Functions | |
create_workdir () | |
Prepares a new empty working directory. | |
destroy () | |
Cleans up stuff after the execution. More... | |
execute () | |
Converts the contents of the tempdir into the target format in the workdir. | |
grouped_parent_exists ($pelement, $elements) | |
Helper method used by self::register_handler(). More... | |
init () | |
Initialize the instance if needed, called by the constructor. More... | |
register_handler (moodle1_handler $handler, array $elements) | |
Register a handler for the given path elements. | |
replace_tempdir () | |
Replaces the source backup directory with the converted version. More... | |
Protected Attributes | |
null string | $currentblock = null |
the current block being processed - used to expand the BLOCK paths | |
null string | $currentmod = null |
the current module being processed - used to expand the MOD paths | |
string | $id |
unique identifier of this converter instance | |
null base_logger | $logger = null |
logger to use during the conversion | |
array | $pathelements = array() |
of convert_path to process | |
string | $pathlock |
path currently locking processing of children | |
string | $tempdir |
the name of the directory containing the unpacked backup being converted | |
string | $workdir |
the name of the directory where the backup is converted to | |
progressive_parser | $xmlparser |
moodle.xml file parser | |
moodle1_parser_processor | $xmlprocessor |
Converter of Moodle 1.9 backup into Moodle 2.x format.
moodle1_converter::create_stash_storage | ( | ) |
Creates the temporary storage for stashed data.
This implementation uses backup_ids_temp table.
|
static |
Reimplemented from base_converter.
|
protectedinherited |
Cleans up stuff after the execution.
Note that we do not know if the execution was successful or not. An exception might have been thrown.
|
static |
Detects the Moodle 1.9 format of the backup directory.
string | $tempdir | the name of the backup directory |
null|string | backup::FORMAT_MOODLE1 if the Moodle 1.9 is detected, null otherwise |
Reimplemented from base_converter.
moodle1_converter::drop_stash_storage | ( | ) |
Drops the temporary storage of stashed data.
This implementation uses backup_ids_temp table.
|
static |
Detects all links to file.php encoded via $@FILEPHP$ and returns the files to migrate.
string | $text |
array |
moodle1_converter::get_contextid | ( | $level, | |
$instance = 0 |
|||
) |
Generates an artificial context id.
Moodle 1.9 backups do not contain any context information. But we need them in Moodle 2.x format so here we generate fictive context id for every given context level + instance combo.
CONTEXT_SYSTEM and CONTEXT_COURSE ignore the $instance as they represent a single system or the course being restored.
int | $level | the context level, like CONTEXT_COURSE or CONTEXT_MODULE |
int | $instance | the instance id, for example $course->id for courses or $cm->id for activity modules |
int | the context id |
moodle1_converter::get_file_manager | ( | $contextid = null , |
|
$component = null , |
|||
$filearea = null , |
|||
$itemid = 0 , |
|||
$userid = null |
|||
) |
Creates and returns new instance of the file manager.
int | $contextid | the default context id of the files being migrated |
string | $component | the default component name of the files being migrated |
string | $filearea | the default file area of the files being migrated |
int | $itemid | the default item id of the files being migrated |
int | $userid | initial user id of the files being migrated |
moodle1_file_manager |
|
inherited |
Get instance identifier.
string | the unique identifier of this converter instance |
moodle1_converter::get_inforef_manager | ( | $name, | |
$id = 0 |
|||
) |
Creates and returns new instance of the inforef manager.
string | $name | the name of the annotator (like course, section, activity, block) |
int | $id | the id of the annotator if required |
moodle1_inforef_manager |
|
inherited |
Get converter name.
string | the system name of the converter |
moodle1_converter::get_nextid | ( | ) |
Simple autoincrement generator.
int | the next number in a row of numbers |
moodle1_converter::get_stash | ( | $stashname, | |
$itemid = 0 |
|||
) |
Restores a given stash stored previously by self::set_stash().
string | $stashname | name of the stash |
int | $itemid | optional id for multiple infos within the same stashname |
moodle1_convert_empty_storage_exception | if the info has not been stashed previously |
mixed | stashed data |
moodle1_converter::get_stash_itemids | ( | $stashname | ) |
Returns the list of stashed $itemids in the given stash.
string | $stashname |
array |
moodle1_converter::get_stash_names | ( | ) |
Returns the list of existing stashes.
array |
moodle1_converter::get_stash_or_default | ( | $stashname, | |
$itemid = 0 , |
|||
$default = null |
|||
) |
Restores a given stash or returns the given default if there is no such stash.
string | $stashname | name of the stash |
int | $itemid | optional id for multiple infos within the same stashname |
mixed | $default | information to return if the info has not been stashed previously |
mixed | stashed data or the default value |
|
inherited |
string | the full path to the directory with the source backup |
|
inherited |
string | the full path to the working directory |
|
protected |
Helper method used by self::register_handler().
convert_path | $pelement | path element |
array | of convert_path instances |
bool | true if grouped parent was found, false otherwise |
|
protected |
Initialize the instance if needed, called by the constructor.
Here we create objects we need before the execution.
Reimplemented from base_converter.
|
staticinherited |
public static methods //////////////////////////////////////////////////
Makes sure that this converter is available at this site
This is intended for eventual PHP extensions check, environment check etc. All checks that do not depend on actual backup data should be done here.
boolean | true if this converter should be considered as available |
Reimplemented in moodle1_export_converter, and imscc1_export_converter.
|
static |
Migrates all course files referenced from the hypertext using the given filemanager.
This is typically used to convert images embedded into the intro fields.
string | $text | hypertext containing $@FILEPHP$ referenced |
moodle1_file_manager | $fileman | file manager to use for the file migration |
string | the original $text with $@FILEPHP$ references replaced with the new @PLUGINFILE@ |
moodle1_converter::path_end_reached | ( | $path | ) |
Executes operations required at the end of a watched path.
string | $path | in the original file |
moodle1_converter::path_start_reached | ( | $path | ) |
Executes operations required at the start of a watched path.
For MOD and BLOCK paths, this is supported only for the sub-paths, not the root module/block element. For the illustration:
You CAN'T attach on_xxx_start() listener to a path like /MOODLE_BACKUP/COURSE/MODULES/MOD/WORKSHOP because the <MOD> must be processed first in self::process_chunk() where $this->currentmod is set.
You CAN attach some on_xxx_start() listener to a path like /MOODLE_BACKUP/COURSE/MODULES/MOD/WORKSHOP/SUBMISSIONS because it is a sub-path under <MOD> and we have $this->currentmod already set when the <SUBMISSIONS> is reached.
string | $path | in the original file |
moodle1_converter::process_chunk | ( | $data | ) |
Process the data obtained from the XML parser processor.
This methods receives one chunk of information from the XML parser processor and dispatches it, following the naming rules. We are expanding the modules and blocks paths here to include the plugin's name.
array | $data |
|
protectedinherited |
Replaces the source backup directory with the converted version.
If $CFG->keeptempdirectoriesonbackup is defined, the original source source backup directory is kept for debugging purposes.
|
static |
Given the list of migrated files, rewrites references to them from $@FILEPHP$ form to the @PLUGINFILE@ one.
string | $text | |
array | $files |
string |
|
inherited |
Sets the logger to use during the conversion.
null | base_logger | $logger |
moodle1_converter::set_stash | ( | $stashname, | |
$info, | |||
$itemid = 0 |
|||
) |
Stores some information for later processing.
This implementation uses backup_ids_temp table to store data. Make sure that the $stashname + $itemid combo is unique.
string | $stashname | name of the stash |
mixed | $info | information to stash |
int | $itemid | optional id for multiple infos within the same stashname |