forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-27448 resource conversion support to restore 1.9 backup to 2.1
- Loading branch information
1 parent
c818e2d
commit 5da3af5
Showing
6 changed files
with
712 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?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 support for the conversion of moodle1 backup to the moodle2 format | ||
* | ||
* @package mod | ||
* @subpackage folder | ||
* @copyright 2011 Andrew Davis <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Folder conversion handler. This resource handler is called by moodle1_mod_resource_handler | ||
*/ | ||
class moodle1_mod_folder_handler extends moodle1_mod_handler { | ||
/** @var array in-memory cache for the course module information */ | ||
protected $currentcminfo = null; | ||
/** @var moodle1_file_manager instance */ | ||
protected $fileman = null; | ||
|
||
/** | ||
* Declare the paths in moodle.xml we are able to convert | ||
* | ||
* @return array of {@link convert_path} instances | ||
*/ | ||
public function get_paths() { | ||
return array(); | ||
} | ||
|
||
/** | ||
* Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data | ||
* Called by moodle1_mod_resource_handler::process_resource() | ||
*/ | ||
public function process_resource($data) { | ||
// get the course module id and context id | ||
$instanceid = $data['id']; | ||
$this->currentcminfo = $this->get_cminfo($instanceid); | ||
$moduleid = $this->currentcminfo['id']; | ||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid); | ||
|
||
// we now have all information needed to start writing into the file | ||
$this->open_xml_writer("activities/folder_{$moduleid}/folder.xml"); | ||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, | ||
'modulename' => 'folder', 'contextid' => $contextid)); | ||
$this->xmlwriter->begin_tag('folder', array('id' => $instanceid)); | ||
|
||
unset($data['id']); // we already write it as attribute, do not repeat it as child element | ||
foreach ($data as $field => $value) { | ||
$this->xmlwriter->full_tag($field, $value); | ||
} | ||
|
||
// prepare file manager for migrating the folder | ||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_folder', 'content'); | ||
$this->fileman->migrate_directory('course_files/'.$data['reference']); | ||
} | ||
|
||
public function on_resource_end() { | ||
// close folder.xml | ||
$this->xmlwriter->end_tag('folder'); | ||
$this->xmlwriter->end_tag('activity'); | ||
$this->close_xml_writer(); | ||
|
||
// write inforef.xml for migrated folder | ||
$this->open_xml_writer("activities/folder_{$this->currentcminfo['id']}/inforef.xml"); | ||
$this->xmlwriter->begin_tag('inforef'); | ||
$this->xmlwriter->begin_tag('fileref'); | ||
foreach ($this->fileman->get_fileids() as $fileid) { | ||
$this->write_xml('file', array('id' => $fileid)); | ||
} | ||
$this->xmlwriter->end_tag('fileref'); | ||
$this->xmlwriter->end_tag('inforef'); | ||
$this->close_xml_writer(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?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 support for the conversion of moodle1 backup to the moodle2 format | ||
* | ||
* @package mod | ||
* @subpackage imscp | ||
* @copyright 2011 Andrew Davis <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* imscp conversion handler. This resource handler is called by moodle1_mod_resource_handler | ||
*/ | ||
class moodle1_mod_imscp_handler extends moodle1_mod_handler { | ||
/** @var array in-memory cache for the course module information for the current imscp */ | ||
protected $currentcminfo = null; | ||
|
||
//there are two file manager instances as we need to put files in two file areas | ||
|
||
/** @var moodle1_file_manager the file manager instance */ | ||
protected $fileman = null; | ||
|
||
/** | ||
* Declare the paths in moodle.xml we are able to convert | ||
* | ||
* @return array of {@link convert_path} instances | ||
*/ | ||
public function get_paths() { | ||
return array(); | ||
} | ||
|
||
/** | ||
* Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data | ||
* Called by moodle1_mod_resource_handler::process_resource() | ||
*/ | ||
public function process_resource($data) { | ||
global $CFG; | ||
|
||
$instanceid = $data['id']; | ||
$this->currentcminfo = $this->get_cminfo($instanceid); | ||
$moduleid = $this->currentcminfo['id']; | ||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid); | ||
|
||
if ($CFG->texteditors !== 'textarea') { | ||
$data['intro'] = text_to_html($data['intro'], false, false, true); | ||
$data['introformat'] = FORMAT_HTML; | ||
} else { | ||
$data['intro'] = $data['intro']; | ||
$data['introformat'] = FORMAT_MOODLE; | ||
} | ||
|
||
$data['revision'] = 1; | ||
$data['keepold'] = 1; | ||
|
||
//Prepare to migrate the deployed (ie extracted) version of the content package | ||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_imscp', 'content', $data['revision']); | ||
$this->fileman->migrate_directory('moddata/resource/'.$data['id']); | ||
|
||
// parse manifest | ||
$structure = $this->parse_structure($data, $contextid); | ||
$data['structure'] = is_array($structure) ? serialize($structure) : null; | ||
|
||
// we now have all information needed to start writing into the module file | ||
|
||
$this->open_xml_writer("activities/imscp_{$moduleid}/imscp.xml"); | ||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, | ||
'modulename' => 'imscp', 'contextid' => $contextid)); | ||
$this->xmlwriter->begin_tag('imscp', array('id' => $instanceid)); | ||
|
||
unset($data['id']); // we already write it as attribute, do not repeat it as child element | ||
foreach ($data as $field => $value) { | ||
$this->xmlwriter->full_tag($field, $value); | ||
} | ||
|
||
/* We currently do not support undeployed IMS packages | ||
* They need to be deployed (unzipped) to the mod data area then have the ims structure figured out | ||
*/ | ||
} | ||
|
||
public function on_resource_end() { | ||
//close imscp.xml | ||
$this->xmlwriter->end_tag('imscp'); | ||
$this->xmlwriter->end_tag('activity'); | ||
$this->close_xml_writer(); | ||
|
||
// write inforef.xml for migrated imscp files | ||
$this->open_xml_writer("activities/imscp_{$this->currentcminfo['id']}/inforef.xml"); | ||
$this->xmlwriter->begin_tag('inforef'); | ||
$this->xmlwriter->begin_tag('fileref'); | ||
foreach ($this->fileman->get_fileids() as $fileid) { | ||
$this->write_xml('file', array('id' => $fileid)); | ||
} | ||
$this->xmlwriter->end_tag('fileref'); | ||
$this->xmlwriter->end_tag('inforef'); | ||
$this->close_xml_writer(); | ||
} | ||
|
||
/// internal implementation details follow ///////////////////////////////// | ||
|
||
/** | ||
* Parse the IMS package structure for the $imscp->structure field | ||
* @param array $data the array of ims package data | ||
*/ | ||
protected function parse_structure($data, $contextid) { | ||
global $CFG; | ||
|
||
$temppath = $this->converter->get_tempdir_path(); | ||
$manifestfilecontents = file_get_contents($temppath.'/moddata/resource/'.$data['id'].'/imsmanifest.xml'); | ||
if (empty($manifestfilecontents)) { | ||
return null; | ||
} | ||
|
||
require_once($CFG->dirroot.'/mod/imscp/locallib.php'); | ||
return imscp_parse_manifestfile($manifestfilecontents); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?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 support for the conversion of moodle1 backup to the moodle2 format | ||
* | ||
* @package mod | ||
* @subpackage page | ||
* @copyright 2011 Andrew Davis <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Page conversion handler. This resource handler is called by moodle1_mod_resource_handler | ||
*/ | ||
class moodle1_mod_page_handler extends moodle1_mod_handler { | ||
/** @var array in-memory cache for the course module information */ | ||
protected $currentcminfo = null; | ||
/** @var moodle1_file_manager instance */ | ||
protected $fileman = null; | ||
|
||
/** | ||
* Declare the paths in moodle.xml we are able to convert | ||
* | ||
* @return array of {@link convert_path} instances | ||
*/ | ||
public function get_paths() { | ||
return array(); | ||
} | ||
|
||
/** | ||
* Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data | ||
* Called by moodle1_mod_resource_handler::process_resource() | ||
*/ | ||
public function process_resource($data) { | ||
global $CFG; | ||
|
||
// get the course module id and context id | ||
$instanceid = $data['id']; | ||
$cminfo = $this->get_cminfo($instanceid, 'resource'); | ||
$moduleid = $cminfo['id']; | ||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid); | ||
|
||
//we now only support html intros | ||
if ($data['type'] == 'text') { | ||
$data['intro'] = text_to_html($data['intro'], false, false, true); | ||
$data['introformat'] = FORMAT_HTML; | ||
} | ||
|
||
$data['contentformat'] = (int)$data['reference']; | ||
if ($data['contentformat'] < 0 || $data['contentformat'] > 4) { | ||
$data['contentformat'] = FORMAT_MOODLE; | ||
} | ||
|
||
$data['content'] = $data['alltext']; | ||
$data['revision'] = 1; | ||
$data['timemodified'] = time(); | ||
|
||
// convert links to old course files | ||
$originalcourseinfo = $this->converter->get_stash('original_course_info'); | ||
if (!empty($originalcourseinfo) && array_key_exists('original_course_id', $originalcourseinfo)) { | ||
$courseid = $originalcourseinfo['original_course_id']; | ||
|
||
$usedfiles = array("$CFG->wwwroot/file.php/$courseid/", "$CFG->wwwroot/file.php?file=/$courseid/"); | ||
$data['content'] = str_ireplace($usedfiles, '@@PLUGINFILE@@/', $data['content']); | ||
if (strpos($data['content'], '@@PLUGINFILE@@/') === false) { | ||
$data['legacyfiles'] = RESOURCELIB_LEGACYFILES_NO; | ||
} else { | ||
$data['legacyfiles'] = RESOURCELIB_LEGACYFILES_ACTIVE; | ||
} | ||
} else { | ||
$data['legacyfiles'] = RESOURCELIB_LEGACYFILES_NO; | ||
} | ||
|
||
$options = array('printheading'=>0, 'printintro'=>0); | ||
if ($data['popup']) { | ||
$data['display'] = RESOURCELIB_DISPLAY_POPUP; | ||
if ($data['popup']) { | ||
$rawoptions = explode(',', $data['popup']); | ||
foreach ($rawoptions as $rawoption) { | ||
list($name, $value) = explode('=', trim($rawoption), 2); | ||
if ($value > 0 and ($name == 'width' or $name == 'height')) { | ||
$options['popup'.$name] = $value; | ||
continue; | ||
} | ||
} | ||
} | ||
} else { | ||
$data['display'] = RESOURCELIB_DISPLAY_OPEN; | ||
} | ||
$data['displayoptions'] = serialize($options); | ||
|
||
// prepare file manager for migrating the folder | ||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_page', 'content', 0); | ||
$this->fileman->migrate_directory('moddata/page/'.$data['id']); | ||
|
||
// we now have all information needed to start writing into the file | ||
$this->open_xml_writer("activities/page_{$moduleid}/page.xml"); | ||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, | ||
'modulename' => 'page', 'contextid' => $contextid)); | ||
$this->xmlwriter->begin_tag('page', array('id' => $instanceid)); | ||
|
||
unset($data['id']); // we already write it as attribute, do not repeat it as child element | ||
foreach ($data as $field => $value) { | ||
$this->xmlwriter->full_tag($field, $value); | ||
} | ||
} | ||
|
||
public function on_resource_end($data) { | ||
// close page.xml | ||
$this->xmlwriter->end_tag('page'); | ||
$this->xmlwriter->end_tag('activity'); | ||
$this->close_xml_writer(); | ||
} | ||
} |
Oops, something went wrong.