Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
base_converter Class Reference

Base converter class. More...

Inheritance diagram for base_converter:
loggable imscc11_converter imscc11_export_converter imscc1_converter imscc1_export_converter moodle1_converter moodle1_export_converter

Public Member Functions

 __construct ($tempdir, $logger=null)
 Constructor.
 
 convert ()
 Converts the backup directory.
 
 get_id ()
 Get instance identifier.
 
 get_name ()
 Get converter name.
 
 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.
 
 set_logger ($logger)
 Sets the logger to use during the conversion.
 

Static Public Member Functions

static description ()
 Returns the basic information about the converter.
 
static detect_format ($tempdir)
 Detects the format of the backup directory.
 
static is_available ()
 public static methods //////////////////////////////////////////////////
 

Protected Member Functions

 create_workdir ()
 Prepares a new empty working directory.
 
 destroy ()
 Cleans up stuff after the execution.
 
 execute ()
 Converts the contents of the tempdir into the target format in the workdir.
 
 init ()
 end of public API //////////////////////////////////////////////////////
 
 replace_tempdir ()
 Replaces the source backup directory with the converted version.
 

Protected Attributes

string $id
 unique identifier of this converter instance
 
null base_logger $logger = null
 logger to use during the conversion
 
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
 

Detailed Description

Base converter class.

All Moodle backup converters are supposed to extend this base class.

Exceptions
convert_exception

Constructor & Destructor Documentation

◆ __construct()

base_converter::__construct ( $tempdir,
$logger = null )

Constructor.

Parameters
string$tempdirthe relative path to the directory containing the unpacked backup to convert
null|base_loggerlogger to use during the conversion

Member Function Documentation

◆ description()

static base_converter::description ( )
static

Returns the basic information about the converter.

The returned array must contain the following keys: 'from' - the supported source format, eg. backup\FORMAT_MOODLE1 'to' - the supported target format, eg. backup\FORMAT_MOODLE 'cost' - the cost of the conversion, non-negative non-zero integer

Reimplemented in imscc11_converter, imscc11_export_converter, imscc1_converter, and moodle1_converter.

◆ destroy()

base_converter::destroy ( )
protected

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 base_converter::detect_format ( $tempdir)
static

Detects the format of the backup directory.

Moodle 2.x format is being detected by the core itself. The converters are therefore supposed to detect the source format. Eventually, if the target format os not backup::FORMAT_MOODLE then they should be able to detect both source and target formats.

Parameters
string$tempdirthe name of the backup directory
Return values
null|stringnull if not recognized, backup\FORMAT_xxx otherwise

Reimplemented in imscc11_converter, imscc1_converter, and moodle1_converter.

◆ execute()

base_converter::execute ( )
abstractprotected

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

Reimplemented in imscc11_converter, imscc11_export_converter, imscc1_converter, imscc1_export_converter, moodle1_converter, and moodle1_export_converter.

◆ get_id()

base_converter::get_id ( )

Get instance identifier.

Return values
stringthe unique identifier of this converter instance

◆ get_name()

base_converter::get_name ( )

Get converter name.

Return values
stringthe system name of the converter

◆ get_tempdir_path()

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

◆ get_workdir_path()

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

◆ init()

base_converter::init ( )
protected

end of public API //////////////////////////////////////////////////////

Initialize the instance if needed, called by the constructor

Reimplemented in moodle1_converter.

◆ is_available()

static base_converter::is_available ( )
static

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()

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

Implements loggable.

Reimplemented in imscc11_converter, imscc1_converter, and moodle1_converter.

◆ replace_tempdir()

base_converter::replace_tempdir ( )
protected

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.

◆ set_logger()

base_converter::set_logger ( $logger)

Sets the logger to use during the conversion.

Parameters
null | base_logger$logger

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