From b346f7e63c9f105dc27fc47707349b90e172ad52 Mon Sep 17 00:00:00 2001 From: Mike Churchward Date: Mon, 5 Nov 2012 17:04:25 -0500 Subject: [PATCH] MDL-32880 - Adding generic block conversion handlers. --- backup/converter/moodle1/handlerlib.php | 27 +++++++- blocks/participants/backup/moodle1/lib.php | 81 ---------------------- 2 files changed, 24 insertions(+), 84 deletions(-) delete mode 100644 blocks/participants/backup/moodle1/lib.php diff --git a/backup/converter/moodle1/handlerlib.php b/backup/converter/moodle1/handlerlib.php index 3246046884781..e658237d18861 100644 --- a/backup/converter/moodle1/handlerlib.php +++ b/backup/converter/moodle1/handlerlib.php @@ -88,10 +88,16 @@ protected static function get_plugin_handlers($type, moodle1_converter $converte foreach ($plugins as $name => $dir) { $handlerfile = $dir . '/backup/moodle1/lib.php'; $handlerclass = "moodle1_{$type}_{$name}_handler"; - if (!file_exists($handlerfile)) { - continue; + if ($type != "block") { + if (!file_exists($handlerfile)) { + continue; + } + require_once($handlerfile); + } else { + if (!file_exists($handlerfile)) { + $handlerclass = "moodle1_block_generic_handler"; + } } - require_once($handlerfile); if (!class_exists($handlerclass)) { throw new moodle1_convert_exception('missing_handler_class', $handlerclass); @@ -1988,6 +1994,14 @@ public function on_legacy_resource_end(array $data) { * Base class for block handlers */ abstract class moodle1_block_handler extends moodle1_plugin_handler { + + public function get_paths() { + $blockname = strtoupper($this->pluginname); + return array( + new convert_path('block', "/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/{$blockname}"), + ); + } + public function process_block(array $data) { $newdata = array(); $instanceid = $data['id']; @@ -2047,6 +2061,13 @@ public function process_block(array $data) { } +/** + * Base class for block generic handler + */ +class moodle1_block_generic_handler extends moodle1_block_handler { + +} + /** * Base class for the activity modules' subplugins */ diff --git a/blocks/participants/backup/moodle1/lib.php b/blocks/participants/backup/moodle1/lib.php deleted file mode 100644 index 78ccad2dc8dea..0000000000000 --- a/blocks/participants/backup/moodle1/lib.php +++ /dev/null @@ -1,81 +0,0 @@ -. - -/** - * Provides support for the conversion of moodle1 backup to the moodle2 format - * - * @package block_participants - * @copyright 2012 Mike Churchward (mike@remote-learner.net) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Block Participants conversion handler - */ -class moodle1_block_participants_handler extends moodle1_block_handler { - - /** - * Declare the paths in moodle.xml we are able to convert - * - * The method returns list of {@link convert_path} instances. For each path returned, - * at least one of on_xxx_start(), process_xxx() and on_xxx_end() methods must be - * defined. The method process_xxx() is not executed if the associated path element is - * empty (i.e. it contains none elements or sub-paths only). - * - * Note that the path /MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/PARTICIPANT does not - * actually exist in the file. The last element with the module name was - * appended by the moodle1_converter class. - * - * @return array of {@link convert_path} instances - */ - public function get_paths() { - return array( - new convert_path( - 'participants', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/PARTICIPANTS', - array( - 'renamefields' => array( - 'name' => 'blockname' - ), - 'newfields' => array( - 'version' => '', - 'showinsubcontexts' => 0, - 'subpagepattern' => '$@NULL@S', - 'defaultregion' => 'side-pre', - 'defaultweight' => 2 - ) - ) - ), - ); - } - - /** - * This is executed every time we have one /MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/PARTICIPANTS - * data available - */ - public function process_participants($data) { - $instanceid = $data['id']; - $contextid = 0; - $parentcontextid = 0; - - // Start writing block.xml. - $this->open_xml_writer("blocks/part_{$this->moduleid}/quiz.xml"); - $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, - 'moduleid' => $this->moduleid, 'modulename' => 'quiz', - 'contextid' => $contextid)); - } -}