Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
moodle1_converter Class Reference

Converter of Moodle 1.9 backup into Moodle 2.x format. More...

Inheritance diagram for moodle1_converter:
base_converter loggable

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. More...
 
 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. More...
 
 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
 

Detailed Description

Converter of Moodle 1.9 backup into Moodle 2.x format.

Member Function Documentation

◆ create_stash_storage()

moodle1_converter::create_stash_storage ( )

Creates the temporary storage for stashed data.

This implementation uses backup_ids_temp table.

◆ description()

static moodle1_converter::description ( )
static
See also
parent::description()

Reimplemented from base_converter.

◆ destroy()

base_converter::destroy ( )
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.

◆ detect_format()

static moodle1_converter::detect_format (   $tempdir)
static

Detects the Moodle 1.9 format of the backup directory.

Parameters
string$tempdirthe name of the backup directory
Return values
null|stringbackup::FORMAT_MOODLE1 if the Moodle 1.9 is detected, null otherwise

Reimplemented from base_converter.

◆ drop_stash_storage()

moodle1_converter::drop_stash_storage ( )

Drops the temporary storage of stashed data.

This implementation uses backup_ids_temp table.

◆ execute()

moodle1_converter::execute ( )
protected

Converts the contents of the tempdir into the target format in the workdir.

Reimplemented from base_converter.

◆ find_referenced_files()

static moodle1_converter::find_referenced_files (   $text)
static

Detects all links to file.php encoded via $@FILEPHP$ and returns the files to migrate.

See also
self::migrate_referenced_files()
Parameters
string$text
Return values
array

◆ get_contextid()

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.

See also
context_system::instance()
context_course::instance()
Parameters
int$levelthe context level, like CONTEXT_COURSE or CONTEXT_MODULE
int$instancethe instance id, for example $course->id for courses or $cm->id for activity modules
Return values
intthe context id

◆ get_file_manager()

moodle1_converter::get_file_manager (   $contextid = null,
  $component = null,
  $filearea = null,
  $itemid = 0,
  $userid = null 
)

Creates and returns new instance of the file manager.

Parameters
int$contextidthe default context id of the files being migrated
string$componentthe default component name of the files being migrated
string$fileareathe default file area of the files being migrated
int$itemidthe default item id of the files being migrated
int$useridinitial user id of the files being migrated
Return values
moodle1_file_manager

◆ get_id()

base_converter::get_id ( )
inherited

Get instance identifier.

Return values
stringthe unique identifier of this converter instance

◆ get_inforef_manager()

moodle1_converter::get_inforef_manager (   $name,
  $id = 0 
)

Creates and returns new instance of the inforef manager.

Parameters
string$namethe name of the annotator (like course, section, activity, block)
int$idthe id of the annotator if required
Return values
moodle1_inforef_manager

◆ get_name()

base_converter::get_name ( )
inherited

Get converter name.

Return values
stringthe system name of the converter

◆ get_nextid()

moodle1_converter::get_nextid ( )

Simple autoincrement generator.

Return values
intthe next number in a row of numbers

◆ get_stash()

moodle1_converter::get_stash (   $stashname,
  $itemid = 0 
)

Restores a given stash stored previously by self::set_stash().

Parameters
string$stashnamename of the stash
int$itemidoptional id for multiple infos within the same stashname
Exceptions
moodle1_convert_empty_storage_exceptionif the info has not been stashed previously
Return values
mixedstashed data

◆ get_stash_itemids()

moodle1_converter::get_stash_itemids (   $stashname)

Returns the list of stashed $itemids in the given stash.

Parameters
string$stashname
Return values
array

◆ get_stash_names()

moodle1_converter::get_stash_names ( )

Returns the list of existing stashes.

Return values
array

◆ get_stash_or_default()

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.

Parameters
string$stashnamename of the stash
int$itemidoptional id for multiple infos within the same stashname
mixed$defaultinformation to return if the info has not been stashed previously
Return values
mixedstashed data or the default value

◆ get_tempdir_path()

base_converter::get_tempdir_path ( )
inherited
Return values
stringthe full path to the directory with the source backup

◆ get_workdir_path()

base_converter::get_workdir_path ( )
inherited
Return values
stringthe full path to the working directory

◆ grouped_parent_exists()

moodle1_converter::grouped_parent_exists (   $pelement,
  $elements 
)
protected

Helper method used by self::register_handler().

Parameters
convert_path$pelementpath element
arrayof convert_path instances
Return values
booltrue if grouped parent was found, false otherwise

◆ init()

moodle1_converter::init ( )
protected

Initialize the instance if needed, called by the constructor.

Here we create objects we need before the execution.

Reimplemented from base_converter.

◆ is_available()

static base_converter::is_available ( )
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.

Return values
booleantrue if this converter should be considered as available

Reimplemented in imscc1_export_converter, and moodle1_export_converter.

◆ log()

moodle1_converter::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.

Reimplemented from base_converter.

◆ migrate_referenced_files()

static moodle1_converter::migrate_referenced_files (   $text,
moodle1_file_manager  $fileman 
)
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.

Parameters
string$texthypertext containing $@FILEPHP$ referenced
moodle1_file_manager$filemanfile manager to use for the file migration
Return values
stringthe original $text with $@FILEPHP$ references replaced with the new @PLUGINFILE@

◆ path_end_reached()

moodle1_converter::path_end_reached (   $path)

Executes operations required at the end of a watched path.

Parameters
string$pathin the original file

◆ path_start_reached()

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.

Parameters
string$pathin the original file

◆ process_chunk()

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.

Parameters
array$data

◆ replace_tempdir()

base_converter::replace_tempdir ( )
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.

◆ rewrite_filephp_usage()

static moodle1_converter::rewrite_filephp_usage (   $text,
array  $files 
)
static

Given the list of migrated files, rewrites references to them from $@FILEPHP$ form to the @PLUGINFILE@ one.

See also
self::migrate_referenced_files()
Parameters
string$text
array$files
Return values
string

◆ set_logger()

base_converter::set_logger (   $logger)
inherited

Sets the logger to use during the conversion.

Parameters
null | base_logger$logger

◆ set_stash()

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.

Parameters
string$stashnamename of the stash
mixed$infoinformation to stash
int$itemidoptional id for multiple infos within the same stashname

The documentation for this class was generated from the following file: