first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+289
View File
@@ -0,0 +1,289 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides base converter classes
*
* @package core
* @subpackage backup-convert
* @copyright 2011 Mark Nielsen <mark@moodlerooms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/backup/util/includes/convert_includes.php');
/**
* Base converter class
*
* All Moodle backup converters are supposed to extend this base class.
*
* @throws convert_exception
*/
abstract class base_converter implements loggable {
/** @var string unique identifier of this converter instance */
protected $id;
/** @var string the name of the directory containing the unpacked backup being converted */
protected $tempdir;
/** @var string the name of the directory where the backup is converted to */
protected $workdir;
/** @var null|base_logger logger to use during the conversion */
protected $logger = null;
/**
* Constructor
*
* @param string $tempdir the relative path to the directory containing the unpacked backup to convert
* @param null|base_logger logger to use during the conversion
*/
public function __construct($tempdir, $logger = null) {
$this->tempdir = $tempdir;
$this->id = convert_helper::generate_id($tempdir);
$this->workdir = $tempdir . '_' . $this->get_name() . '_' . $this->id;
$this->set_logger($logger);
$this->log('instantiating '.$this->get_name().' converter '.$this->get_id(), backup::LOG_DEBUG);
$this->log('conversion source directory', backup::LOG_DEBUG, $this->tempdir);
$this->log('conversion target directory', backup::LOG_DEBUG, $this->workdir);
$this->init();
}
/**
* Sets the logger to use during the conversion
*
* @param null|base_logger $logger
*/
public function set_logger($logger) {
if (is_null($logger) or ($logger instanceof base_logger)) {
$this->logger = $logger;
}
}
/**
* If the logger was set for the converter, log the message
*
* If the $display is enabled, the spaces in the $message text are removed
* and the text is used as a string identifier in the core_backup language file.
*
* @see backup_helper::log()
* @param string $message message text
* @param int $level message level {@example backup::LOG_WARNING}
* @param null|mixed $a additional information
* @param null|int $depth the message depth
* @param bool $display whether the message should be sent to the output, too
*/
public function log($message, $level, $a = null, $depth = null, $display = false) {
if ($this->logger instanceof base_logger) {
backup_helper::log($message, $level, $a, $depth, $display, $this->logger);
}
}
/**
* Get instance identifier
*
* @return string the unique identifier of this converter instance
*/
public function get_id() {
return $this->id;
}
/**
* Get converter name
*
* @return string the system name of the converter
*/
public function get_name() {
$parts = explode('_', get_class($this));
return array_shift($parts);
}
/**
* Converts the backup directory
*/
public function convert() {
try {
$this->log('creating the target directory', backup::LOG_DEBUG);
$this->create_workdir();
$this->log('executing the conversion', backup::LOG_DEBUG);
$this->execute();
$this->log('replacing the source directory with the converted version', backup::LOG_DEBUG);
$this->replace_tempdir();
} catch (Exception $e) {
}
// clean-up stuff if needed
$this->destroy();
// eventually re-throw the execution exception
if (isset($e) and ($e instanceof Exception)) {
throw $e;
}
}
/**
* @return string the full path to the working directory
*/
public function get_workdir_path() {
global $CFG;
return make_backup_temp_directory($this->workdir);
}
/**
* @return string the full path to the directory with the source backup
*/
public function get_tempdir_path() {
global $CFG;
return make_backup_temp_directory($this->tempdir);
}
/// 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 boolean true if this converter should be considered as available
*/
public static function is_available() {
return true;
}
/**
* 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 {@link backup::FORMAT_MOODLE} then they should be able to
* detect both source and target formats.
*
* @param string $tempdir the name of the backup directory
* @return null|string null if not recognized, backup::FORMAT_xxx otherwise
*/
public static function detect_format($tempdir) {
return null;
}
/**
* 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
*/
public static function description() {
return array(
'from' => null,
'to' => null,
'cost' => null,
);
}
/// end of public API //////////////////////////////////////////////////////
/**
* Initialize the instance if needed, called by the constructor
*/
protected function init() {
}
/**
* Converts the contents of the tempdir into the target format in the workdir
*/
abstract protected function execute();
/**
* Prepares a new empty working directory
*/
protected function create_workdir() {
fulldelete($this->get_workdir_path());
if (!check_dir_exists($this->get_workdir_path())) {
throw new convert_exception('failed_create_workdir');
}
}
/**
* 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.
*/
protected function replace_tempdir() {
global $CFG;
$tempdir = $this->get_tempdir_path();
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($tempdir);
} else {
if (!rename($tempdir, $tempdir . '_' . $this->get_name() . '_' . $this->id . '_source')) {
throw new convert_exception('failed_rename_source_tempdir');
}
}
if (!rename($this->get_workdir_path(), $tempdir)) {
throw new convert_exception('failed_move_converted_into_place');
}
}
/**
* 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.
*/
protected function destroy() {
global $CFG;
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($this->get_workdir_path());
}
}
}
/**
* General convert-related exception
*
* @author David Mudrak <david@moodle.com>
*/
class convert_exception extends moodle_exception {
/**
* Constructor
*
* @param string $errorcode key for the corresponding error string
* @param object $a extra words and phrases that might be required in the error string
* @param string $debuginfo optional debugging information
*/
public function __construct($errorcode, $a = null, $debuginfo = null) {
parent::__construct($errorcode, '', '', $a, $debuginfo);
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
require_once($CFG->dirroot . '/backup/converter/convertlib.php');
class imscc1_export_converter extends base_converter {
public static function is_available() {
return false;
}
protected function execute() {
}
}
+131
View File
@@ -0,0 +1,131 @@
<?php
/**
* Provides Common Cartridge v1 converter class
*
* @package core
* @subpackage backup-convert
* @copyright 2011 Darko Miletic <dmiletic@moodlerooms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot.'/backup/converter/convertlib.php');
require_once($CFG->dirroot.'/backup/cc/includes/constants.php');
require_once($CFG->dirroot.'/backup/cc/cc2moodle.php');
require_once($CFG->dirroot.'/backup/cc/validator.php');
class imscc1_converter extends base_converter {
/**
* Log a message
*
* @see parent::log()
* @param string $message message text
* @param int $level message level {@example backup::LOG_WARNING}
* @param null|mixed $a additional information
* @param null|int $depth the message depth
* @param bool $display whether the message should be sent to the output, too
*/
public function log($message, $level, $a = null, $depth = null, $display = false) {
parent::log('(imscc1) '.$message, $level, $a, $depth, $display);
}
/**
* Detects the Common Cartridge 1.0 format of the backup directory
*
* @param string $tempdir the name of the backup directory
* @return null|string backup::FORMAT_IMSCC1 if the Common Cartridge 1.0 is detected, null otherwise
*/
public static function detect_format($tempdir) {
$filepath = make_backup_temp_directory($tempdir, false);
if (!is_dir($filepath)) {
throw new convert_helper_exception('tmp_backup_directory_not_found', $filepath);
}
$manifest = cc2moodle::get_manifest($filepath);
if (!empty($manifest)) {
// Looks promising, lets load some information.
$handle = fopen($manifest, 'r');
$xml_snippet = fread($handle, 1024);
fclose($handle);
// Check if it has the required strings.
$xml_snippet = strtolower($xml_snippet);
$xml_snippet = preg_replace('/\s*/m', '', $xml_snippet);
$xml_snippet = str_replace("'", '', $xml_snippet);
$xml_snippet = str_replace('"', '', $xml_snippet);
$search_string = "xmlns=http://www.imsglobal.org/xsd/imscc/imscp_v1p1";
if (strpos($xml_snippet, $search_string) !== false) {
return backup::FORMAT_IMSCC1;
}
}
return null;
}
/**
* 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
*/
public static function description() {
return array(
'from' => backup::FORMAT_IMSCC1,
'to' => backup::FORMAT_MOODLE1,
'cost' => 10
);
}
protected function execute() {
global $CFG;
$manifest = cc2moodle::get_manifest($this->get_tempdir_path());
if (empty($manifest)) {
throw new imscc1_convert_exception('No Manifest detected!');
}
$this->log('validating manifest', backup::LOG_DEBUG, null, 1);
$validator = new manifest10_validator($CFG->dirroot . '/backup/cc/schemas');
if (!$validator->validate($manifest)) {
$this->log('validation error(s): '.PHP_EOL.error_messages::instance(), backup::LOG_DEBUG, null, 2);
throw new imscc1_convert_exception(error_messages::instance()->to_string(true));
}
$manifestdir = dirname($manifest);
$cc2moodle = new cc2moodle($manifest);
if ($cc2moodle->is_auth()) {
throw new imscc1_convert_exception('protected_cc_not_supported');
}
$status = $cc2moodle->generate_moodle_xml();
// Final cleanup.
$xml_error = new libxml_errors_mgr(true);
$mdoc = new DOMDocument();
$mdoc->preserveWhiteSpace = false;
$mdoc->formatOutput = true;
$mdoc->validateOnParse = false;
$mdoc->strictErrorChecking = false;
if ($mdoc->load($manifestdir.'/moodle.xml', LIBXML_NONET)) {
$mdoc->save($this->get_workdir_path().'/moodle.xml', LIBXML_NOEMPTYTAG);
} else {
$xml_error->collect();
$this->log('validation error(s): '.PHP_EOL.error_messages::instance(), backup::LOG_DEBUG, null, 2);
throw new imscc1_convert_exception(error_messages::instance()->to_string(true));
}
// Move the files to the workdir.
rename($manifestdir.'/course_files', $this->get_workdir_path().'/course_files');
}
}
/**
* Exception thrown by this converter
*/
class imscc1_convert_exception extends convert_exception {
}
+165
View File
@@ -0,0 +1,165 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides {@link imscc11_export_converter} class
*
* @package core
* @subpackage backup-convert
* @copyright 2011 Darko Miletic <dmiletic@moodlerooms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/backup/converter/convertlib.php');
class imscc11_export_converter extends base_converter {
public static function get_deps() {
global $CFG;
require_once($CFG->dirroot . '/backup/util/settings/setting_dependency.class.php');
return array(
'users' => setting_dependency::DISABLED_VALUE,
'filters' => setting_dependency::DISABLED_VALUE,
'blocks' => setting_dependency::DISABLED_VALUE
);
}
protected function execute() {
}
public static function description() {
return array(
'from' => backup::FORMAT_MOODLE,
'to' => backup::FORMAT_IMSCC11,
'cost' => 10
);
}
}
class imscc11_store_backup_file extends backup_execution_step {
protected function define_execution() {
// Get basepath
$basepath = $this->get_basepath();
// Calculate the zip fullpath (in OS temp area it's always backup.imscc)
$zipfile = $basepath . '/backup.imscc';
// Perform storage and return it (TODO: shouldn't be array but proper result object)
// Let's send the file to file storage, everything already defined
// First of all, get some information from the backup_controller to help us decide
list($dinfo, $cinfo, $sinfo) = backup_controller_dbops::get_moodle_backup_information($this->get_backupid());
// Extract useful information to decide
$file = $sinfo['filename']->value;
$filename = basename($file,'.'.pathinfo($file, PATHINFO_EXTENSION)).'.imscc'; // Backup filename
$userid = $dinfo[0]->userid; // User->id executing the backup
$id = $dinfo[0]->id; // Id of activity/section/course (depends of type)
$courseid = $dinfo[0]->courseid; // Id of the course
$ctxid = context_user::instance($userid)->id;
$component = 'user';
$filearea = 'backup';
$itemid = 0;
$fs = get_file_storage();
$fr = array(
'contextid' => $ctxid,
'component' => $component,
'filearea' => $filearea,
'itemid' => $itemid,
'filepath' => '/',
'filename' => $filename,
'userid' => $userid,
'timecreated' => time(),
'timemodified'=> time());
// If file already exists, delete if before
// creating it again. This is BC behaviour - copy()
// overwrites by default
if ($fs->file_exists($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename'])) {
$pathnamehash = $fs->get_pathname_hash($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename']);
$sf = $fs->get_file_by_hash($pathnamehash);
$sf->delete();
}
return array('backup_destination' => $fs->create_file_from_pathname($fr, $zipfile));
}
}
class imscc11_zip_contents extends backup_execution_step {
protected function define_execution() {
// Get basepath
$basepath = $this->get_basepath();
// Get the list of files in directory
$filestemp = get_directory_list($basepath, '', false, true, true);
$files = array();
foreach ($filestemp as $file) {
// Add zip paths and fs paths to all them
$files[$file] = $basepath . '/' . $file;
}
// Calculate the zip fullpath (in OS temp area it's always backup.mbz)
$zipfile = $basepath . '/backup.imscc';
// Get the zip packer
$zippacker = get_file_packer('application/zip');
// Zip files
$zippacker->archive_to_pathname($files, $zipfile);
}
}
class imscc11_backup_convert extends backup_execution_step {
protected function define_execution() {
global $CFG;
// Get basepath
$basepath = $this->get_basepath();
require_once($CFG->dirroot . '/backup/cc/cc_includes.php');
$tempdir = $CFG->backuptempdir . '/' . uniqid('', true);
if (mkdir($tempdir, $CFG->directorypermissions, true)) {
cc_convert_moodle2::convert($basepath, $tempdir);
//Switch the directories
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($basepath);
} else {
if (!rename($basepath, $basepath . '_moodle2_source')) {
throw new backup_task_exception('failed_rename_source_tempdir');
}
}
if (!rename($tempdir, $basepath)) {
throw new backup_task_exception('failed_move_converted_into_place');
}
}
}
}
+131
View File
@@ -0,0 +1,131 @@
<?php
/**
* Provides Common Cartridge v1.1 converter class
*
* @package core
* @subpackage backup-convert
* @copyright 2011 Darko Miletic <dmiletic@moodlerooms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot.'/backup/converter/convertlib.php');
require_once($CFG->dirroot.'/backup/cc/includes/constants.php');
require_once($CFG->dirroot.'/backup/cc/cc112moodle.php');
require_once($CFG->dirroot.'/backup/cc/validator.php');
class imscc11_converter extends base_converter {
/**
* Log a message
*
* @see parent::log()
* @param string $message message text
* @param int $level message level {@example backup::LOG_WARNING}
* @param null|mixed $a additional information
* @param null|int $depth the message depth
* @param bool $display whether the message should be sent to the output, too
*/
public function log($message, $level, $a = null, $depth = null, $display = false) {
parent::log('(imscc1) '.$message, $level, $a, $depth, $display);
}
/**
* Detects the Common Cartridge 1.0 format of the backup directory
*
* @param string $tempdir the name of the backup directory
* @return null|string backup::FORMAT_IMSCC11 if the Common Cartridge 1.1 is detected, null otherwise
*/
public static function detect_format($tempdir) {
$filepath = make_backup_temp_directory($tempdir, false);
if (!is_dir($filepath)) {
throw new convert_helper_exception('tmp_backup_directory_not_found', $filepath);
}
$manifest = cc112moodle::get_manifest($filepath);
if (file_exists($manifest)) {
// Looks promising, lets load some information.
$handle = fopen($manifest, 'r');
$xml_snippet = fread($handle, 1024);
fclose($handle);
// Check if it has the required strings.
$xml_snippet = strtolower($xml_snippet);
$xml_snippet = preg_replace('/\s*/m', '', $xml_snippet);
$xml_snippet = str_replace("'", '', $xml_snippet);
$xml_snippet = str_replace('"', '', $xml_snippet);
$search_string = "xmlns=http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1";
if (strpos($xml_snippet, $search_string) !== false) {
return backup::FORMAT_IMSCC11;
}
}
return null;
}
/**
* 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
*/
public static function description() {
return array(
'from' => backup::FORMAT_IMSCC11,
'to' => backup::FORMAT_MOODLE1,
'cost' => 10
);
}
protected function execute() {
global $CFG;
$manifest = cc112moodle::get_manifest($this->get_tempdir_path());
if (empty($manifest)) {
throw new imscc11_convert_exception('No Manifest detected!');
}
$this->log('validating manifest', backup::LOG_DEBUG, null, 1);
$validator = new manifest_validator($CFG->dirroot . '/backup/cc/schemas11');
if (!$validator->validate($manifest)) {
$this->log('validation error(s): '.PHP_EOL.error_messages::instance(), backup::LOG_DEBUG, null, 2);
throw new imscc11_convert_exception(error_messages::instance()->to_string(true));
}
$manifestdir = dirname($manifest);
$cc112moodle = new cc112moodle($manifest);
if ($cc112moodle->is_auth()) {
throw new imscc11_convert_exception('protected_cc_not_supported');
}
$status = $cc112moodle->generate_moodle_xml();
// Final cleanup.
$xml_error = new libxml_errors_mgr(true);
$mdoc = new DOMDocument();
$mdoc->preserveWhiteSpace = false;
$mdoc->formatOutput = true;
$mdoc->validateOnParse = false;
$mdoc->strictErrorChecking = false;
if ($mdoc->load($manifestdir.'/moodle.xml', LIBXML_NONET)) {
$mdoc->save($this->get_workdir_path().'/moodle.xml', LIBXML_NOEMPTYTAG);
} else {
$xml_error->collect();
$this->log('validation error(s): '.PHP_EOL.error_messages::instance(), backup::LOG_DEBUG, null, 2);
throw new imscc11_convert_exception(error_messages::instance()->to_string(true));
}
// Move the files to the workdir.
rename($manifestdir.'/course_files', $this->get_workdir_path().'/course_files');
}
}
/**
* Exception thrown by this converter
*/
class imscc11_convert_exception extends convert_exception {
}
+13
View File
@@ -0,0 +1,13 @@
<?php
require_once($CFG->dirroot . '/backup/converter/convertlib.php');
class moodle1_export_converter extends base_converter {
public static function is_available() {
return false;
}
protected function execute() {
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 127 B

+602
View File
@@ -0,0 +1,602 @@
<?xml version="1.0" encoding="UTF-8"?>
<MOODLE_BACKUP>
<INFO>
<NAME>restore.zip</NAME>
<MOODLE_VERSION>2007101520</MOODLE_VERSION>
<MOODLE_RELEASE>1.9.2 (Build: 20080711)</MOODLE_RELEASE>
<BACKUP_VERSION>2008030300</BACKUP_VERSION>
<BACKUP_RELEASE>1.9</BACKUP_RELEASE>
<DATE>1299774017</DATE>
<ORIGINAL_WWWROOT>http://elearning-testadam.uss.lsu.edu/moodle</ORIGINAL_WWWROOT>
<ZIP_METHOD>internal</ZIP_METHOD>
<DETAILS>
<MOD>
<NAME>forum</NAME>
<INCLUDED>true</INCLUDED>
<USERINFO>false</USERINFO>
<INSTANCES>
<INSTANCE>
<ID>57</ID>
<NAME>News forum</NAME>
<INCLUDED>true</INCLUDED>
<USERINFO>false</USERINFO>
</INSTANCE>
</INSTANCES>
</MOD>
<METACOURSE>false</METACOURSE>
<USERS>course</USERS>
<LOGS>false</LOGS>
<USERFILES>true</USERFILES>
<COURSEFILES>true</COURSEFILES>
<SITEFILES>true</SITEFILES>
<GRADEBOOKHISTORIES>false</GRADEBOOKHISTORIES>
<MESSAGES>false</MESSAGES>
<BLOGS>false</BLOGS>
<BLOCKFORMAT>instances</BLOCKFORMAT>
</DETAILS>
</INFO>
<ROLES>
</ROLES>
<COURSE>
<HEADER>
<ID>33</ID>
<CATEGORY>
<ID>1</ID>
<NAME>Category 1</NAME>
</CATEGORY>
<PASSWORD></PASSWORD>
<FULLNAME>Moodle 2.0 Test Restore</FULLNAME>
<SHORTNAME>M2TR</SHORTNAME>
<IDNUMBER></IDNUMBER>
<SUMMARY>Cazzin'</SUMMARY>
<FORMAT>weeks</FORMAT>
<SHOWGRADES>1</SHOWGRADES>
<NEWSITEMS>5</NEWSITEMS>
<TEACHER>Teacher</TEACHER>
<TEACHERS>Teachers</TEACHERS>
<STUDENT>Student</STUDENT>
<STUDENTS>Students</STUDENTS>
<GUEST>0</GUEST>
<STARTDATE>1299823200</STARTDATE>
<NUMSECTIONS>10</NUMSECTIONS>
<MAXBYTES>52428800</MAXBYTES>
<SHOWREPORTS>0</SHOWREPORTS>
<GROUPMODE>0</GROUPMODE>
<GROUPMODEFORCE>0</GROUPMODEFORCE>
<DEFAULTGROUPINGID>0</DEFAULTGROUPINGID>
<LANG></LANG>
<THEME></THEME>
<COST></COST>
<CURRENCY>USD</CURRENCY>
<MARKER>0</MARKER>
<VISIBLE>1</VISIBLE>
<HIDDENSECTIONS>0</HIDDENSECTIONS>
<TIMECREATED>1299773769</TIMECREATED>
<TIMEMODIFIED>1299773769</TIMEMODIFIED>
<METACOURSE>0</METACOURSE>
<EXPIRENOTIFY>0</EXPIRENOTIFY>
<NOTIFYSTUDENTS>0</NOTIFYSTUDENTS>
<EXPIRYTHRESHOLD>864000</EXPIRYTHRESHOLD>
<ENROLLABLE>1</ENROLLABLE>
<ENROLSTARTDATE>0</ENROLSTARTDATE>
<ENROLENDDATE>0</ENROLENDDATE>
<ENROLPERIOD>0</ENROLPERIOD>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</HEADER>
<BLOCKS>
<BLOCK>
<ID>314</ID>
<NAME>participants</NAME>
<PAGEID>33</PAGEID>
<PAGETYPE>course-view</PAGETYPE>
<POSITION>l</POSITION>
<WEIGHT>0</WEIGHT>
<VISIBLE>1</VISIBLE>
<CONFIGDATA>Tjs=</CONFIGDATA>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</BLOCK>
<BLOCK>
<ID>315</ID>
<NAME>activity_modules</NAME>
<PAGEID>33</PAGEID>
<PAGETYPE>course-view</PAGETYPE>
<POSITION>l</POSITION>
<WEIGHT>1</WEIGHT>
<VISIBLE>1</VISIBLE>
<CONFIGDATA>Tjs=</CONFIGDATA>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</BLOCK>
<BLOCK>
<ID>316</ID>
<NAME>search_forums</NAME>
<PAGEID>33</PAGEID>
<PAGETYPE>course-view</PAGETYPE>
<POSITION>l</POSITION>
<WEIGHT>2</WEIGHT>
<VISIBLE>1</VISIBLE>
<CONFIGDATA>Tjs=</CONFIGDATA>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</BLOCK>
<BLOCK>
<ID>317</ID>
<NAME>admin</NAME>
<PAGEID>33</PAGEID>
<PAGETYPE>course-view</PAGETYPE>
<POSITION>l</POSITION>
<WEIGHT>3</WEIGHT>
<VISIBLE>1</VISIBLE>
<CONFIGDATA>Tjs=</CONFIGDATA>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</BLOCK>
<BLOCK>
<ID>318</ID>
<NAME>course_list</NAME>
<PAGEID>33</PAGEID>
<PAGETYPE>course-view</PAGETYPE>
<POSITION>l</POSITION>
<WEIGHT>4</WEIGHT>
<VISIBLE>1</VISIBLE>
<CONFIGDATA>Tjs=</CONFIGDATA>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</BLOCK>
<BLOCK>
<ID>319</ID>
<NAME>news_items</NAME>
<PAGEID>33</PAGEID>
<PAGETYPE>course-view</PAGETYPE>
<POSITION>r</POSITION>
<WEIGHT>0</WEIGHT>
<VISIBLE>1</VISIBLE>
<CONFIGDATA>Tjs=</CONFIGDATA>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</BLOCK>
<BLOCK>
<ID>320</ID>
<NAME>calendar_upcoming</NAME>
<PAGEID>33</PAGEID>
<PAGETYPE>course-view</PAGETYPE>
<POSITION>r</POSITION>
<WEIGHT>1</WEIGHT>
<VISIBLE>1</VISIBLE>
<CONFIGDATA>Tjs=</CONFIGDATA>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</BLOCK>
<BLOCK>
<ID>321</ID>
<NAME>recent_activity</NAME>
<PAGEID>33</PAGEID>
<PAGETYPE>course-view</PAGETYPE>
<POSITION>r</POSITION>
<WEIGHT>2</WEIGHT>
<VISIBLE>1</VISIBLE>
<CONFIGDATA>Tjs=</CONFIGDATA>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</BLOCK>
</BLOCKS>
<SECTIONS>
<SECTION>
<ID>436</ID>
<NUMBER>0</NUMBER>
<SUMMARY>$@NULL@$</SUMMARY>
<VISIBLE>1</VISIBLE>
<MODS>
<MOD>
<ID>250</ID>
<TYPE>forum</TYPE>
<INSTANCE>57</INSTANCE>
<ADDED>1299773780</ADDED>
<SCORE>0</SCORE>
<INDENT>0</INDENT>
<VISIBLE>1</VISIBLE>
<GROUPMODE>0</GROUPMODE>
<GROUPINGID>0</GROUPINGID>
<GROUPMEMBERSONLY>0</GROUPMEMBERSONLY>
<IDNUMBER>$@NULL@$</IDNUMBER>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</MOD>
</MODS>
</SECTION>
<SECTION>
<ID>437</ID>
<NUMBER>1</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
<SECTION>
<ID>438</ID>
<NUMBER>2</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
<SECTION>
<ID>439</ID>
<NUMBER>3</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
<SECTION>
<ID>440</ID>
<NUMBER>4</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
<SECTION>
<ID>441</ID>
<NUMBER>5</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
<SECTION>
<ID>442</ID>
<NUMBER>6</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
<SECTION>
<ID>443</ID>
<NUMBER>7</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
<SECTION>
<ID>444</ID>
<NUMBER>8</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
<SECTION>
<ID>445</ID>
<NUMBER>9</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
<SECTION>
<ID>446</ID>
<NUMBER>10</NUMBER>
<SUMMARY></SUMMARY>
<VISIBLE>1</VISIBLE>
</SECTION>
</SECTIONS>
<USERS>
<USER>
<ID>2</ID>
<AUTH>manual</AUTH>
<CONFIRMED>1</CONFIRMED>
<POLICYAGREED>0</POLICYAGREED>
<DELETED>0</DELETED>
<USERNAME>admin</USERNAME>
<PASSWORD>ea557cf33bda866d97b07465f1ea3867</PASSWORD>
<IDNUMBER>891220979</IDNUMBER>
<FIRSTNAME>Admin</FIRSTNAME>
<LASTNAME>User</LASTNAME>
<EMAIL>adamzap@example.com</EMAIL>
<EMAILSTOP>0</EMAILSTOP>
<ICQ></ICQ>
<SKYPE></SKYPE>
<YAHOO></YAHOO>
<AIM></AIM>
<MSN></MSN>
<PHONE1></PHONE1>
<PHONE2></PHONE2>
<INSTITUTION></INSTITUTION>
<DEPARTMENT></DEPARTMENT>
<ADDRESS></ADDRESS>
<CITY>br</CITY>
<COUNTRY>US</COUNTRY>
<LANG>en_utf8</LANG>
<THEME></THEME>
<TIMEZONE>99</TIMEZONE>
<FIRSTACCESS>0</FIRSTACCESS>
<LASTACCESS>1265755409</LASTACCESS>
<LASTLOGIN>1265658108</LASTLOGIN>
<CURRENTLOGIN>1265741271</CURRENTLOGIN>
<LASTIP>130.39.194.172</LASTIP>
<SECRET>lknsJoSw0S6myJA</SECRET>
<PICTURE>1</PICTURE>
<URL></URL>
<DESCRIPTION></DESCRIPTION>
<MAILFORMAT>1</MAILFORMAT>
<MAILDIGEST>0</MAILDIGEST>
<MAILDISPLAY>1</MAILDISPLAY>
<HTMLEDITOR>1</HTMLEDITOR>
<AJAX>1</AJAX>
<AUTOSUBSCRIBE>1</AUTOSUBSCRIBE>
<TRACKFORUMS>0</TRACKFORUMS>
<TIMEMODIFIED>1265216036</TIMEMODIFIED>
<ROLES>
<ROLE>
<TYPE>needed</TYPE>
</ROLE>
</ROLES>
<USER_PREFERENCES>
<USER_PREFERENCE>
<NAME>email_bounce_count</NAME>
<VALUE>1</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>email_send_count</NAME>
<VALUE>1</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>user_editadvanced_form_showadvanced</NAME>
<VALUE>1</VALUE>
</USER_PREFERENCE>
</USER_PREFERENCES>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</USER>
<USER>
<ID>3</ID>
<AUTH>cas</AUTH>
<CONFIRMED>1</CONFIRMED>
<POLICYAGREED>0</POLICYAGREED>
<DELETED>0</DELETED>
<USERNAME>azaple1</USERNAME>
<PASSWORD>fb005bdc5fb1b23ea95d238fb5ecb9e2</PASSWORD>
<IDNUMBER>891111111</IDNUMBER>
<FIRSTNAME>Adam</FIRSTNAME>
<LASTNAME>Zapletal</LASTNAME>
<EMAIL>azaple1@example.com</EMAIL>
<EMAILSTOP>0</EMAILSTOP>
<ICQ></ICQ>
<SKYPE></SKYPE>
<YAHOO></YAHOO>
<AIM></AIM>
<MSN></MSN>
<PHONE1></PHONE1>
<PHONE2></PHONE2>
<INSTITUTION></INSTITUTION>
<DEPARTMENT></DEPARTMENT>
<ADDRESS></ADDRESS>
<CITY>asdf</CITY>
<COUNTRY>AL</COUNTRY>
<LANG>en_utf8</LANG>
<THEME></THEME>
<TIMEZONE>99</TIMEZONE>
<FIRSTACCESS>0</FIRSTACCESS>
<LASTACCESS>1299774054</LASTACCESS>
<LASTLOGIN>1297979000</LASTLOGIN>
<CURRENTLOGIN>1299773727</CURRENTLOGIN>
<LASTIP>173.253.129.223</LASTIP>
<SECRET></SECRET>
<PICTURE>1</PICTURE>
<URL></URL>
<DESCRIPTION></DESCRIPTION>
<MAILFORMAT>1</MAILFORMAT>
<MAILDIGEST>0</MAILDIGEST>
<MAILDISPLAY>2</MAILDISPLAY>
<HTMLEDITOR>1</HTMLEDITOR>
<AJAX>1</AJAX>
<AUTOSUBSCRIBE>1</AUTOSUBSCRIBE>
<TRACKFORUMS>0</TRACKFORUMS>
<TIMEMODIFIED>1288033285</TIMEMODIFIED>
<ROLES>
<ROLE>
<TYPE>needed</TYPE>
</ROLE>
</ROLES>
<USER_PREFERENCES>
<USER_PREFERENCE>
<NAME>assignment_mailinfo</NAME>
<VALUE>1</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>assignment_perpage</NAME>
<VALUE>10</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>assignment_quickgrade</NAME>
<VALUE>0</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>auth_forcepasswordchange</NAME>
<VALUE>0</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>forum_displaymode</NAME>
<VALUE>3</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>grader_report_preferences_form_showadvanced</NAME>
<VALUE>1</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>grade_report_simple_aggregationview51</NAME>
<VALUE>0</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>grade_report_simple_grader_collapsed_categories</NAME>
<VALUE>a:2:{s:14:&quot;aggregatesonly&quot;;a:4:{i:0;s:2:&quot;70&quot;;i:1;s:2:&quot;71&quot;;i:2;s:2:&quot;72&quot;;i:3;s:2:&quot;73&quot;;}s:10:&quot;gradesonly&quot;;a:0:{}}</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>grade_report_simple_meanselection</NAME>
<VALUE>2</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>grade_report_simple_showranges</NAME>
<VALUE>1</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>grade_report_simple_showstickytab</NAME>
<VALUE>0</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>lesson_view</NAME>
<VALUE>collapsed</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>mod_resource_mod_form_showadvanced</NAME>
<VALUE>1</VALUE>
</USER_PREFERENCE>
<USER_PREFERENCE>
<NAME>user_editadvanced_form_showadvanced</NAME>
<VALUE>1</VALUE>
</USER_PREFERENCE>
</USER_PREFERENCES>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</USER>
<USER>
<ID>6</ID>
<AUTH>cas</AUTH>
<CONFIRMED>1</CONFIRMED>
<POLICYAGREED>0</POLICYAGREED>
<DELETED>0</DELETED>
<USERNAME>pcali1</USERNAME>
<PASSWORD>fb005bdc5fb1b23ea95d238fb5ecb9e2</PASSWORD>
<IDNUMBER></IDNUMBER>
<FIRSTNAME>Philip</FIRSTNAME>
<LASTNAME>Cali</LASTNAME>
<EMAIL>pcali1@example.com</EMAIL>
<EMAILSTOP>0</EMAILSTOP>
<ICQ></ICQ>
<SKYPE></SKYPE>
<YAHOO></YAHOO>
<AIM></AIM>
<MSN></MSN>
<PHONE1></PHONE1>
<PHONE2></PHONE2>
<INSTITUTION></INSTITUTION>
<DEPARTMENT></DEPARTMENT>
<ADDRESS></ADDRESS>
<CITY></CITY>
<COUNTRY></COUNTRY>
<LANG>en_utf8</LANG>
<THEME></THEME>
<TIMEZONE>99</TIMEZONE>
<FIRSTACCESS>0</FIRSTACCESS>
<LASTACCESS>1268662392</LASTACCESS>
<LASTLOGIN>0</LASTLOGIN>
<CURRENTLOGIN>1268662284</CURRENTLOGIN>
<LASTIP>68.105.37.237</LASTIP>
<SECRET></SECRET>
<PICTURE>1</PICTURE>
<URL></URL>
<DESCRIPTION>$@NULL@$</DESCRIPTION>
<MAILFORMAT>1</MAILFORMAT>
<MAILDIGEST>0</MAILDIGEST>
<MAILDISPLAY>2</MAILDISPLAY>
<HTMLEDITOR>1</HTMLEDITOR>
<AJAX>1</AJAX>
<AUTOSUBSCRIBE>1</AUTOSUBSCRIBE>
<TRACKFORUMS>0</TRACKFORUMS>
<TIMEMODIFIED>1268662284</TIMEMODIFIED>
<ROLES>
<ROLE>
<TYPE>needed</TYPE>
</ROLE>
</ROLES>
<ROLES_OVERRIDES>
</ROLES_OVERRIDES>
<ROLES_ASSIGNMENTS>
</ROLES_ASSIGNMENTS>
</USER>
</USERS>
<GRADEBOOK>
<GRADE_CATEGORIES>
<GRADE_CATEGORY>
<ID>90</ID>
<PARENT>$@NULL@$</PARENT>
<FULLNAME>?</FULLNAME>
<AGGREGATION>11</AGGREGATION>
<KEEPHIGH>0</KEEPHIGH>
<DROPLOW>0</DROPLOW>
<AGGREGATEONLYGRADED>1</AGGREGATEONLYGRADED>
<AGGREGATEOUTCOMES>0</AGGREGATEOUTCOMES>
<AGGREGATESUBCATS>0</AGGREGATESUBCATS>
<TIMECREATED>1299774068</TIMECREATED>
<TIMEMODIFIED>1299774068</TIMEMODIFIED>
</GRADE_CATEGORY>
</GRADE_CATEGORIES>
<GRADE_ITEMS>
<GRADE_ITEM>
<ID>410</ID>
<CATEGORYID>$@NULL@$</CATEGORYID>
<ITEMNAME>$@NULL@$</ITEMNAME>
<ITEMTYPE>course</ITEMTYPE>
<ITEMMODULE>$@NULL@$</ITEMMODULE>
<ITEMINSTANCE>90</ITEMINSTANCE>
<ITEMNUMBER>$@NULL@$</ITEMNUMBER>
<ITEMINFO>$@NULL@$</ITEMINFO>
<IDNUMBER>$@NULL@$</IDNUMBER>
<CALCULATION>$@NULL@$</CALCULATION>
<GRADETYPE>1</GRADETYPE>
<GRADEMAX>100.00000</GRADEMAX>
<GRADEMIN>0.00000</GRADEMIN>
<SCALEID>$@NULL@$</SCALEID>
<OUTCOMEID>$@NULL@$</OUTCOMEID>
<GRADEPASS>0.00000</GRADEPASS>
<MULTFACTOR>1.00000</MULTFACTOR>
<PLUSFACTOR>0.00000</PLUSFACTOR>
<AGGREGATIONCOEF>1.00000</AGGREGATIONCOEF>
<DISPLAY>0</DISPLAY>
<DECIMALS>$@NULL@$</DECIMALS>
<HIDDEN>0</HIDDEN>
<LOCKED>0</LOCKED>
<LOCKTIME>0</LOCKTIME>
<NEEDSUPDATE>0</NEEDSUPDATE>
<TIMECREATED>1299774068</TIMECREATED>
<TIMEMODIFIED>1299774068</TIMEMODIFIED>
</GRADE_ITEM>
</GRADE_ITEMS>
</GRADEBOOK>
<MODULES>
<MOD>
<ID>57</ID>
<MODTYPE>forum</MODTYPE>
<TYPE>news</TYPE>
<NAME>News forum</NAME>
<INTRO>General news and announcements</INTRO>
<ASSESSED>0</ASSESSED>
<ASSESSTIMESTART>0</ASSESSTIMESTART>
<ASSESSTIMEFINISH>0</ASSESSTIMEFINISH>
<MAXBYTES>0</MAXBYTES>
<SCALE>0</SCALE>
<FORCESUBSCRIBE>1</FORCESUBSCRIBE>
<TRACKINGTYPE>1</TRACKINGTYPE>
<RSSTYPE>0</RSSTYPE>
<RSSARTICLES>0</RSSARTICLES>
<TIMEMODIFIED>1299773780</TIMEMODIFIED>
<WARNAFTER>0</WARNAFTER>
<BLOCKAFTER>0</BLOCKAFTER>
<BLOCKPERIOD>0</BLOCKPERIOD>
</MOD>
</MODULES>
<FORMATDATA>
</FORMATDATA>
</COURSE>
</MOODLE_BACKUP>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,593 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_backup;
use backup;
use convert_path;
use convert_path_exception;
use convert_factory;
use convert_helper;
use moodle1_converter;
use moodle1_convert_empty_storage_exception;
use moodle1_convert_exception;
use moodle1_convert_storage_exception;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/backup/converter/moodle1/lib.php');
/**
* Unit tests for the moodle1 converter
*
* @package core_backup
* @subpackage backup-convert
* @category test
* @copyright 2011 Mark Nielsen <mark@moodlerooms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodle1_converter_test extends \advanced_testcase {
/** @var string the name of the directory containing the unpacked Moodle 1.9 backup */
protected $tempdir;
/** @var string the full name of the directory containing the unpacked Moodle 1.9 backup */
protected $tempdirpath;
/** @var string saved hash of an icon file used during testing */
protected $iconhash;
protected function setUp(): void {
global $CFG;
$this->tempdir = convert_helper::generate_id('unittest');
$this->tempdirpath = make_backup_temp_directory($this->tempdir);
check_dir_exists("$this->tempdirpath/course_files/sub1");
check_dir_exists("$this->tempdirpath/moddata/unittest/4/7");
copy(
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/moodle.xml",
"$this->tempdirpath/moodle.xml"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$this->tempdirpath/course_files/file1.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$this->tempdirpath/course_files/sub1/file2.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$this->tempdirpath/moddata/unittest/4/file1.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$this->tempdirpath/moddata/unittest/4/icon.gif"
);
$this->iconhash = \file_storage::hash_from_path($this->tempdirpath.'/moddata/unittest/4/icon.gif');
copy(
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$this->tempdirpath/moddata/unittest/4/7/icon.gif"
);
}
protected function tearDown(): void {
global $CFG;
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($this->tempdirpath);
}
}
public function test_detect_format(): void {
$detected = moodle1_converter::detect_format($this->tempdir);
$this->assertEquals(backup::FORMAT_MOODLE1, $detected);
}
public function test_convert_factory(): void {
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$this->assertInstanceOf('moodle1_converter', $converter);
}
public function test_stash_storage_not_created(): void {
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$this->expectException(moodle1_convert_storage_exception::class);
$converter->set_stash('tempinfo', 12);
}
public function test_stash_requiring_empty_stash(): void {
$this->resetAfterTest(true);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->create_stash_storage();
$converter->set_stash('tempinfo', 12);
try {
$converter->get_stash('anothertempinfo');
} catch (moodle1_convert_empty_storage_exception $e) {
// we must drop the storage here so we are able to re-create it in the next test
$this->expectException(moodle1_convert_empty_storage_exception::class);
$converter->drop_stash_storage();
throw new moodle1_convert_empty_storage_exception('rethrowing');
}
}
public function test_stash_storage(): void {
$this->resetAfterTest(true);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->create_stash_storage();
// no implicit stashes
$stashes = $converter->get_stash_names();
$this->assertEquals(gettype($stashes), 'array');
$this->assertTrue(empty($stashes));
// test stashes without itemid
$converter->set_stash('tempinfo1', 12);
$converter->set_stash('tempinfo2', array('a' => 2, 'b' => 3));
$stashes = $converter->get_stash_names();
$this->assertEquals('array', gettype($stashes));
$this->assertEquals(2, count($stashes));
$this->assertTrue(in_array('tempinfo1', $stashes));
$this->assertTrue(in_array('tempinfo2', $stashes));
$this->assertEquals(12, $converter->get_stash('tempinfo1'));
$this->assertEquals(array('a' => 2, 'b' => 3), $converter->get_stash('tempinfo2'));
// overwriting a stashed value is allowed
$converter->set_stash('tempinfo1', '13');
$this->assertNotSame(13, $converter->get_stash('tempinfo1'));
$this->assertSame('13', $converter->get_stash('tempinfo1'));
// repeated reading is allowed
$this->assertEquals('13', $converter->get_stash('tempinfo1'));
// storing empty array
$converter->set_stash('empty_array_stash', array());
$restored = $converter->get_stash('empty_array_stash');
//$this->assertEquals(gettype($restored), 'array'); // todo return null now, this needs MDL-27713 to be fixed, then uncomment
$this->assertTrue(empty($restored));
// test stashes with itemid
$converter->set_stash('tempinfo', 'Hello', 1);
$converter->set_stash('tempinfo', 'World', 2);
$this->assertSame('Hello', $converter->get_stash('tempinfo', 1));
$this->assertSame('World', $converter->get_stash('tempinfo', 2));
// test get_stash_itemids()
$ids = $converter->get_stash_itemids('course_fileref');
$this->assertEquals(gettype($ids), 'array');
$this->assertTrue(empty($ids));
$converter->set_stash('course_fileref', null, 34);
$converter->set_stash('course_fileref', null, 52);
$ids = $converter->get_stash_itemids('course_fileref');
$this->assertEquals(2, count($ids));
$this->assertTrue(in_array(34, $ids));
$this->assertTrue(in_array(52, $ids));
$converter->drop_stash_storage();
}
public function test_get_stash_or_default(): void {
$this->resetAfterTest(true);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->create_stash_storage();
$this->assertTrue(is_null($converter->get_stash_or_default('stashname')));
$this->assertTrue(is_null($converter->get_stash_or_default('stashname', 7)));
$this->assertTrue('default' === $converter->get_stash_or_default('stashname', 0, 'default'));
$this->assertTrue(array('foo', 'bar') === $converter->get_stash_or_default('stashname', 42, array('foo', 'bar')));
//$converter->set_stash('stashname', 0);
//$this->assertFalse(is_null($converter->get_stash_or_default('stashname'))); // todo returns true now, this needs MDL-27713 to be fixed
//$converter->set_stash('stashname', '');
//$this->assertFalse(is_null($converter->get_stash_or_default('stashname'))); // todo returns true now, this needs MDL-27713 to be fixed
//$converter->set_stash('stashname', array());
//$this->assertFalse(is_null($converter->get_stash_or_default('stashname'))); // todo returns true now, this needs MDL-27713 to be fixed
$converter->set_stash('stashname', 42);
$this->assertTrue(42 === $converter->get_stash_or_default('stashname'));
$this->assertTrue(is_null($converter->get_stash_or_default('stashname', 1)));
$this->assertTrue(42 === $converter->get_stash_or_default('stashname', 0, 61));
$converter->set_stash('stashname', array(42 => (object)array('id' => 42)), 18);
$stashed = $converter->get_stash_or_default('stashname', 18, 1984);
$this->assertEquals(gettype($stashed), 'array');
$this->assertTrue(is_object($stashed[42]));
$this->assertTrue($stashed[42]->id === 42);
$converter->drop_stash_storage();
}
public function test_get_contextid(): void {
$this->resetAfterTest(true);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
// stash storage must be created in advance
$converter->create_stash_storage();
// ids are generated on the first call
$id1 = $converter->get_contextid(CONTEXT_BLOCK, 10);
$id2 = $converter->get_contextid(CONTEXT_BLOCK, 11);
$id3 = $converter->get_contextid(CONTEXT_MODULE, 10);
$this->assertNotEquals($id1, $id2);
$this->assertNotEquals($id1, $id3);
$this->assertNotEquals($id2, $id3);
// and then re-used if called with the same params
$this->assertEquals($id1, $converter->get_contextid(CONTEXT_BLOCK, 10));
$this->assertEquals($id2, $converter->get_contextid(CONTEXT_BLOCK, 11));
$this->assertEquals($id3, $converter->get_contextid(CONTEXT_MODULE, 10));
// for system and course level, the instance is irrelevant
// as we need only one system and one course
$id1 = $converter->get_contextid(CONTEXT_COURSE);
$id2 = $converter->get_contextid(CONTEXT_COURSE, 10);
$id3 = $converter->get_contextid(CONTEXT_COURSE, 14);
$this->assertEquals($id1, $id2);
$this->assertEquals($id1, $id3);
$id1 = $converter->get_contextid(CONTEXT_SYSTEM);
$id2 = $converter->get_contextid(CONTEXT_SYSTEM, 11);
$id3 = $converter->get_contextid(CONTEXT_SYSTEM, 15);
$this->assertEquals($id1, $id2);
$this->assertEquals($id1, $id3);
$converter->drop_stash_storage();
}
public function test_get_nextid(): void {
$this->resetAfterTest(true);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$id1 = $converter->get_nextid();
$id2 = $converter->get_nextid();
$id3 = $converter->get_nextid();
$this->assertTrue(0 < $id1);
$this->assertTrue($id1 < $id2);
$this->assertTrue($id2 < $id3);
}
public function test_migrate_file(): void {
$this->resetAfterTest(true);
// set-up the file manager
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->create_stash_storage();
$contextid = $converter->get_contextid(CONTEXT_MODULE, 32);
$fileman = $converter->get_file_manager($contextid, 'mod_unittest', 'testarea');
// this fileman has not converted anything yet
$fileids = $fileman->get_fileids();
$this->assertEquals(gettype($fileids), 'array');
$this->assertEquals(0, count($fileids));
// try to migrate an invalid file
$fileman->itemid = 1;
$thrown = false;
try {
$fileman->migrate_file('/../../../../../../../../../../../../../../etc/passwd');
} catch (moodle1_convert_exception $e) {
$thrown = true;
}
$this->assertTrue($thrown);
// migrate a single file
$fileman->itemid = 4;
$fileman->migrate_file('moddata/unittest/4/icon.gif');
$subdir = substr($this->iconhash, 0, 2);
$this->assertTrue(is_file($converter->get_workdir_path().'/files/'.$subdir.'/'.$this->iconhash));
// get the file id
$fileids = $fileman->get_fileids();
$this->assertEquals(gettype($fileids), 'array');
$this->assertEquals(1, count($fileids));
// migrate another single file into another file area
$fileman->filearea = 'anotherarea';
$fileman->itemid = 7;
$fileman->migrate_file('moddata/unittest/4/7/icon.gif', '/', 'renamed.gif');
// get the file records
$filerecordids = $converter->get_stash_itemids('files');
foreach ($filerecordids as $filerecordid) {
$filerecord = $converter->get_stash('files', $filerecordid);
$this->assertEquals($this->iconhash, $filerecord['contenthash']);
$this->assertEquals($contextid, $filerecord['contextid']);
$this->assertEquals('mod_unittest', $filerecord['component']);
if ($filerecord['filearea'] === 'testarea') {
$this->assertEquals(4, $filerecord['itemid']);
$this->assertEquals('icon.gif', $filerecord['filename']);
}
}
// explicitly clear the list of migrated files
$this->assertTrue(count($fileman->get_fileids()) > 0);
$fileman->reset_fileids();
$this->assertTrue(count($fileman->get_fileids()) == 0);
$converter->drop_stash_storage();
}
public function test_migrate_directory(): void {
$this->resetAfterTest(true);
// Set-up the file manager.
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->create_stash_storage();
$contextid = $converter->get_contextid(CONTEXT_MODULE, 32);
$fileman = $converter->get_file_manager($contextid, 'mod_unittest', 'testarea');
// This fileman has not converted anything yet.
$fileids = $fileman->get_fileids();
$this->assertEquals(gettype($fileids), 'array');
$this->assertEquals(0, count($fileids));
// Try to migrate a non-existing directory.
$returned = $fileman->migrate_directory('not/existing/directory');
$this->assertEquals(gettype($returned), 'array');
$this->assertEquals(0, count($returned));
$fileids = $fileman->get_fileids();
$this->assertEquals(gettype($fileids), 'array');
$this->assertEquals(0, count($fileids));
// Try to migrate whole course_files.
$returned = $fileman->migrate_directory('course_files');
$this->assertEquals(gettype($returned), 'array');
$this->assertEquals(4, count($returned)); // Two files, two directories.
$fileids = $fileman->get_fileids();
$this->assertEquals(gettype($fileids), 'array');
$this->assertEquals(4, count($fileids));
$subdir = substr($this->iconhash, 0, 2);
$this->assertTrue(is_file($converter->get_workdir_path().'/files/'.$subdir.'/'.$this->iconhash));
// Check the file records.
$files = array();
$filerecordids = $converter->get_stash_itemids('files');
foreach ($filerecordids as $filerecordid) {
$filerecord = $converter->get_stash('files', $filerecordid);
$files[$filerecord['filepath'].$filerecord['filename']] = $filerecord;
}
$this->assertEquals('array', gettype($files['/.']));
$this->assertEquals('array', gettype($files['/file1.gif']));
$this->assertEquals('array', gettype($files['/sub1/.']));
$this->assertEquals('array', gettype($files['/sub1/file2.gif']));
$this->assertEquals(\file_storage::hash_from_string(''), $files['/.']['contenthash']);
$this->assertEquals(\file_storage::hash_from_string(''), $files['/sub1/.']['contenthash']);
$this->assertEquals($this->iconhash, $files['/file1.gif']['contenthash']);
$this->assertEquals($this->iconhash, $files['/sub1/file2.gif']['contenthash']);
$converter->drop_stash_storage();
}
public function test_migrate_directory_with_trailing_slash(): void {
$this->resetAfterTest(true);
// Set-up the file manager.
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->create_stash_storage();
$contextid = $converter->get_contextid(CONTEXT_MODULE, 32);
$fileman = $converter->get_file_manager($contextid, 'mod_unittest', 'testarea');
// Try to migrate a subdirectory passed with the trailing slash.
$returned = $fileman->migrate_directory('course_files/sub1/');
// Debugging message must be thrown in this case.
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
$this->assertEquals(gettype($returned), 'array');
$this->assertEquals(2, count($returned)); // One file, one directory.
$converter->drop_stash_storage();
}
public function test_convert_path(): void {
$path = new convert_path('foo_bar', '/ROOT/THINGS/FOO/BAR');
$this->assertEquals('foo_bar', $path->get_name());
$this->assertEquals('/ROOT/THINGS/FOO/BAR', $path->get_path());
$this->assertEquals('process_foo_bar', $path->get_processing_method());
$this->assertEquals('on_foo_bar_start', $path->get_start_method());
$this->assertEquals('on_foo_bar_end', $path->get_end_method());
}
public function test_convert_path_implicit_recipes(): void {
$path = new convert_path('foo_bar', '/ROOT/THINGS/FOO/BAR');
$data = array(
'ID' => 76,
'ELOY' => 'stronk7',
'MARTIN' => 'moodler',
'EMPTY' => null,
);
// apply default recipes (converting keys to lowercase)
$data = $path->apply_recipes($data);
$this->assertEquals(4, count($data));
$this->assertEquals(76, $data['id']);
$this->assertEquals('stronk7', $data['eloy']);
$this->assertEquals('moodler', $data['martin']);
$this->assertSame(null, $data['empty']);
}
public function test_convert_path_explicit_recipes(): void {
$path = new convert_path(
'foo_bar', '/ROOT/THINGS/FOO/BAR',
array(
'newfields' => array(
'david' => 'mudrd8mz',
'petr' => 'skodak',
),
'renamefields' => array(
'empty' => 'nothing',
),
'dropfields' => array(
'id'
),
)
);
$data = array(
'ID' => 76,
'ELOY' => 'stronk7',
'MARTIN' => 'moodler',
'EMPTY' => null,
);
$data = $path->apply_recipes($data);
$this->assertEquals(5, count($data));
$this->assertFalse(array_key_exists('id', $data));
$this->assertEquals('stronk7', $data['eloy']);
$this->assertEquals('moodler', $data['martin']);
$this->assertEquals('mudrd8mz', $data['david']);
$this->assertEquals('skodak', $data['petr']);
$this->assertSame(null, $data['nothing']);
}
public function test_grouped_data_on_nongrouped_convert_path(): void {
// prepare some grouped data
$data = array(
'ID' => 77,
'NAME' => 'Pale lagers',
'BEERS' => array(
array(
'BEER' => array(
'ID' => 67,
'NAME' => 'Pilsner Urquell',
)
),
array(
'BEER' => array(
'ID' => 34,
'NAME' => 'Heineken',
)
),
)
);
// declare a non-grouped path
$path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE');
// an attempt to apply recipes throws exception because we do not expect grouped data
$this->expectException(convert_path_exception::class);
$data = $path->apply_recipes($data);
}
public function test_grouped_convert_path_with_recipes(): void {
// prepare some grouped data
$data = array(
'ID' => 77,
'NAME' => 'Pale lagers',
'BEERS' => array(
array(
'BEER' => array(
'ID' => 67,
'NAME' => 'Pilsner Urquell',
)
),
array(
'BEER' => array(
'ID' => 34,
'NAME' => 'Heineken',
)
),
)
);
// implict recipes work for grouped data if the path is declared as grouped
$path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE', array(), true);
$data = $path->apply_recipes($data);
$this->assertEquals('Heineken', $data['beers'][1]['beer']['name']);
// an attempt to provide explicit recipes on grouped elements throws exception
$this->expectException(convert_path_exception::class);
$path = new convert_path(
'beer_style', '/ROOT/BEER_STYLES/BEER_STYLE',
array(
'renamefields' => array(
'name' => 'beername', // note this is confusing recipe because the 'name' is used for both
// beer-style name ('Pale lagers') and beer name ('Pilsner Urquell')
)
), true);
}
public function test_referenced_course_files(): void {
$text = 'This is a text containing links to file.php
as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif" /><a href="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif$@FORCEDOWNLOAD@$">download image</a><br />
<div><a href=\'$@FILEPHP@$/../../../../../../../../../../../../../../../etc/passwd\'>download passwords</a></div>
<div><a href=\'$@FILEPHP@$$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$etc$@SLASH@$shadow\'>download shadows</a></div>
<br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />';
$files = moodle1_converter::find_referenced_files($text);
$this->assertEquals(gettype($files), 'array');
$this->assertEquals(2, count($files));
$this->assertTrue(in_array('/pics/news.gif', $files));
$this->assertTrue(in_array('/MANUAL.DOC', $files));
$text = moodle1_converter::rewrite_filephp_usage($text, array('/pics/news.gif', '/another/file/notused.txt'));
$this->assertEquals($text, 'This is a text containing links to file.php
as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="@@PLUGINFILE@@/pics/news.gif" /><a href="@@PLUGINFILE@@/pics/news.gif?forcedownload=1">download image</a><br />
<div><a href=\'$@FILEPHP@$/../../../../../../../../../../../../../../../etc/passwd\'>download passwords</a></div>
<div><a href=\'$@FILEPHP@$$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$etc$@SLASH@$shadow\'>download shadows</a></div>
<br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />');
}
public function test_referenced_files_urlencoded(): void {
$text = 'This is a text containing links to file.php
as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif" /><a href="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif$@FORCEDOWNLOAD@$">no space</a><br />
<br /><a href=\'$@FILEPHP@$$@SLASH@$pics$@SLASH@$news%20with%20spaces.gif$@FORCEDOWNLOAD@$\'>with urlencoded spaces</a><br />
<a href="$@FILEPHP@$$@SLASH@$illegal%20pics%2Bmovies$@SLASH@$romeo%2Bjuliet.avi">Download the full AVI for free! (space and plus encoded)</a>
<a href="$@FILEPHP@$$@SLASH@$illegal pics+movies$@SLASH@$romeo+juliet.avi">Download the full AVI for free! (none encoded)</a>
<a href="$@FILEPHP@$$@SLASH@$illegal%20pics+movies$@SLASH@$romeo+juliet.avi">Download the full AVI for free! (only space encoded)</a>
<a href="$@FILEPHP@$$@SLASH@$illegal pics%2Bmovies$@SLASH@$romeo%2Bjuliet.avi">Download the full AVI for free! (only plus)</a>';
$files = moodle1_converter::find_referenced_files($text);
$this->assertEquals(gettype($files), 'array');
$this->assertEquals(3, count($files));
$this->assertTrue(in_array('/pics/news.gif', $files));
$this->assertTrue(in_array('/pics/news with spaces.gif', $files));
$this->assertTrue(in_array('/illegal pics+movies/romeo+juliet.avi', $files));
$text = moodle1_converter::rewrite_filephp_usage($text, $files);
$this->assertEquals('This is a text containing links to file.php
as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="@@PLUGINFILE@@/pics/news.gif" /><a href="@@PLUGINFILE@@/pics/news.gif?forcedownload=1">no space</a><br />
<br /><a href=\'@@PLUGINFILE@@/pics/news%20with%20spaces.gif?forcedownload=1\'>with urlencoded spaces</a><br />
<a href="@@PLUGINFILE@@/illegal%20pics%2Bmovies/romeo%2Bjuliet.avi">Download the full AVI for free! (space and plus encoded)</a>
<a href="@@PLUGINFILE@@/illegal%20pics%2Bmovies/romeo%2Bjuliet.avi">Download the full AVI for free! (none encoded)</a>
<a href="$@FILEPHP@$$@SLASH@$illegal%20pics+movies$@SLASH@$romeo+juliet.avi">Download the full AVI for free! (only space encoded)</a>
<a href="$@FILEPHP@$$@SLASH@$illegal pics%2Bmovies$@SLASH@$romeo%2Bjuliet.avi">Download the full AVI for free! (only plus)</a>', $text);
}
public function test_question_bank_conversion(): void {
global $CFG;
$this->resetAfterTest(true);
copy(
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/questions.xml",
"$this->tempdirpath/moodle.xml"
);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->convert();
}
public function test_convert_run_convert(): void {
$this->resetAfterTest(true);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->convert();
}
public function test_inforef_manager(): void {
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$inforef = $converter->get_inforef_manager('unittest');
$inforef->add_ref('file', 45);
$inforef->add_refs('file', array(46, 47));
// todo test the write_refs() via some dummy xml_writer
$this->expectException('coding_exception');
$inforef->add_ref('unknown_referenced_item_name', 76);
}
}