Beispiel #1
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE
  * data available
  */
 public function process_facetoface($data)
 {
     global $CFG;
     // Get the course module id and context id.
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // Replay the upgrade step 2009042006.
     if ($CFG->texteditors !== 'textarea') {
         $data['intro'] = text_to_html($data['description'], false, false, true);
         $data['introformat'] = FORMAT_HTML;
     }
     // Get a fresh new file manager for this instance.
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_facetoface');
     // Convert course files embedded into the intro.
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // Start writing facetoface.xml.
     $this->open_xml_writer("activities/facetoface_{$this->moduleid}/facetoface.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'facetoface', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('facetoface', array('id' => $instanceid));
     unset($data['id']);
     foreach ($data as $field => $value) {
         $this->xmlwriter->full_tag($field, $value);
     }
     return $data;
 }
Beispiel #2
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/LABEL
  * data available
  */
 public function process_label($data)
 {
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
     // get a fresh new file manager for this instance
     $fileman = $this->converter->get_file_manager($contextid, 'mod_label');
     // convert course files embedded into the intro
     $fileman->filearea = 'intro';
     $fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $fileman);
     // write inforef.xml
     $this->open_xml_writer("activities/label_{$moduleid}/inforef.xml");
     $this->xmlwriter->begin_tag('inforef');
     $this->xmlwriter->begin_tag('fileref');
     foreach ($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();
     // write label.xml
     $this->open_xml_writer("activities/label_{$moduleid}/label.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 'modulename' => 'label', 'contextid' => $contextid));
     $this->write_xml('label', $data, array('/label/id'));
     $this->xmlwriter->end_tag('activity');
     $this->close_xml_writer();
     return $data;
 }
Beispiel #3
0
 /**
  * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM data
  */
 public function process_forum($data)
 {
     global $CFG;
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_forum');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // Convert the introformat if necessary.
     if ($CFG->texteditors !== 'textarea') {
         $data['intro'] = text_to_html($data['intro'], false, false, true);
         $data['introformat'] = FORMAT_HTML;
     }
     // start writing forum.xml
     $this->open_xml_writer("activities/forum_{$this->moduleid}/forum.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'forum', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('forum', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     $this->xmlwriter->begin_tag('discussions');
     return $data;
 }
 /**
  * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/HSUFORUM data
  */
 public function process_hsuforum($data)
 {
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_hsuforum');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     if (!array_key_exists('maxattachments', $data)) {
         $data['maxattachments'] = 1;
     }
     if (array_key_exists('multiattach', $data) && empty($data['multiattach'])) {
         $data['maxattachments'] = 0;
     }
     unset($data['multiattach']);
     // start writing forum.xml
     $this->open_xml_writer("activities/hsuforum_{$this->moduleid}/hsuforum.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'hsuforum', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('hsuforum', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     $this->xmlwriter->begin_tag('discussions');
     return $data;
 }
Beispiel #5
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/ASSIGNMENT
  * data available
  */
 public function process_assignment($data)
 {
     global $CFG;
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     //store assignment type for possible subplugin conversions.
     $this->currentsubpluginname = $data['assignmenttype'];
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_assignment');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // convert the introformat if necessary
     if ($CFG->texteditors !== 'textarea') {
         $data['intro'] = text_to_html($data['intro'], false, false, true);
         $data['introformat'] = FORMAT_HTML;
     }
     // start writing assignment.xml
     $this->open_xml_writer("activities/assignment_{$this->moduleid}/assignment.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'assignment', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('assignment', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     //after writing the assignment type element, let the subplugin add on whatever it wants.
     $this->handle_assignment_subplugin($data);
     $this->xmlwriter->begin_tag('submissions');
     return $data;
 }
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK
  * data available
  */
 public function process_feedback($data)
 {
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_feedback');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // start writing feedback.xml
     $this->open_xml_writer("activities/feedback_{$this->moduleid}/feedback.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'feedback', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('feedback', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     $this->xmlwriter->begin_tag('items');
     return $data;
 }
Beispiel #7
0
 /**
  * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
  * Called by moodle1_mod_resource_handler::process_resource()
  */
 public function process_legacy_resource(array $data, array $raw = null)
 {
     $instanceid = $data['id'];
     $currentcminfo = $this->get_cminfo($instanceid);
     $moduleid = $currentcminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
     // Prepare the new imscp instance record.
     $imscp = array();
     $imscp['id'] = $data['id'];
     $imscp['name'] = $data['name'];
     $imscp['intro'] = $data['intro'];
     $imscp['introformat'] = $data['introformat'];
     $imscp['revision'] = 1;
     $imscp['keepold'] = 1;
     $imscp['structure'] = null;
     $imscp['timemodified'] = $data['timemodified'];
     // Prepare a fresh new file manager for this instance.
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_imscp');
     // Convert course files embedded into the intro.
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $imscp['intro'] = moodle1_converter::migrate_referenced_files($imscp['intro'], $this->fileman);
     // Migrate package backup file.
     if ($data['reference']) {
         $packagename = basename($data['reference']);
         $packagepath = $this->converter->get_tempdir_path() . '/moddata/resource/' . $data['id'] . '/' . $packagename;
         if (file_exists($packagepath)) {
             $this->fileman->filearea = 'backup';
             $this->fileman->itemid = 1;
             $this->fileman->migrate_file('moddata/resource/' . $data['id'] . '/' . $packagename);
         } else {
             $this->log('missing imscp package', backup::LOG_WARNING, 'moddata/resource/' . $data['id'] . '/' . $packagename);
         }
     }
     // Migrate extracted package data.
     $this->fileman->filearea = 'content';
     $this->fileman->itemid = 1;
     $this->fileman->migrate_directory('moddata/resource/' . $data['id']);
     // Parse manifest.
     $structure = $this->parse_structure($this->converter->get_tempdir_path() . '/moddata/resource/' . $data['id'] . '/imsmanifest.xml', $imscp, $contextid);
     $imscp['structure'] = is_array($structure) ? serialize($structure) : null;
     // Write imscp.xml.
     $this->open_xml_writer("activities/imscp_{$moduleid}/imscp.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 'modulename' => 'imscp', 'contextid' => $contextid));
     $this->write_xml('imscp', $imscp, array('/imscp/id'));
     $this->xmlwriter->end_tag('activity');
     $this->close_xml_writer();
     // Write inforef.xml.
     $this->open_xml_writer("activities/imscp_{$moduleid}/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();
 }
Beispiel #8
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM
  * data available
  */
 public function process_scorm($data)
 {
     global $CFG;
     // get the course module id and context id
     $instanceid = $data['id'];
     $currentcminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $currentcminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // conditionally migrate to html format in intro
     if ($CFG->texteditors !== 'textarea') {
         $data['intro'] = text_to_html($data['intro'], false, false, true);
         $data['introformat'] = FORMAT_HTML;
     }
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // check 1.9 version where backup was created
     $backupinfo = $this->converter->get_stash('backup_info');
     if ($backupinfo['moodle_version'] < 2007110503) {
         // as we have no module version data, assume $currmodule->version <= $module->version
         // - fix data as the source 1.9 build hadn't yet at time of backing up.
         $data['grademethod'] = $data['grademethod'] % 10;
     }
     // update scormtype (logic is consistent as done in scorm/db/upgrade.php)
     $ismanifest = preg_match('/imsmanifest\\.xml$/', $data['reference']);
     $iszippif = preg_match('/.(zip|pif)$/', $data['reference']);
     $isurl = preg_match('/^((http|https):\\/\\/|www\\.)/', $data['reference']);
     if ($isurl) {
         if ($ismanifest) {
             $data['scormtype'] = 'external';
         } else {
             if ($iszippif) {
                 $data['scormtype'] = 'localtype';
             }
         }
     }
     // migrate scorm package file
     $this->fileman->filearea = 'package';
     $this->fileman->itemid = 0;
     $this->fileman->migrate_file('course_files/' . $data['reference']);
     // start writing scorm.xml
     $this->open_xml_writer("activities/scorm_{$this->moduleid}/scorm.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'scorm', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('scorm', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     $this->xmlwriter->begin_tag('scoes');
     return $data;
 }
Beispiel #9
0
 protected function convert_configdata(array $olddata)
 {
     $instanceid = $olddata['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_BLOCK, $olddata['id']);
     $configdata = unserialize(base64_decode($olddata['configdata']));
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'block_html');
     // convert course files embedded in the block content
     $this->fileman->filearea = 'content';
     $this->fileman->itemid = 0;
     $configdata->text = moodle1_converter::migrate_referenced_files($configdata->text, $this->fileman);
     $configdata->format = FORMAT_HTML;
     return base64_encode(serialize($configdata));
 }
Beispiel #10
0
    /**
     * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
     * Called by moodle1_mod_resource_handler::process_resource()
     */
    public function process_legacy_resource(array $data, array $raw = null) {
        // get the course module id and context id
        $instanceid     = $data['id'];
        $currentcminfo  = $this->get_cminfo($instanceid);
        $moduleid       = $currentcminfo['id'];
        $contextid      = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);

        // convert legacy data into the new folder record
        $folder                 = array();
        $folder['id']           = $data['id'];
        $folder['name']         = $data['name'];
        $folder['intro']        = $data['intro'];
        $folder['introformat']  = $data['introformat'];
        $folder['revision']     = 1;
        $folder['timemodified'] = $data['timemodified'];

        // get a fresh new file manager for this instance
        $this->fileman = $this->converter->get_file_manager($contextid, 'mod_folder');

        // migrate the files embedded into the intro field
        $this->fileman->filearea = 'intro';
        $this->fileman->itemid   = 0;
        $folder['intro'] = moodle1_converter::migrate_referenced_files($folder['intro'], $this->fileman);

        // migrate the folder files
        $this->fileman->filearea = 'content';
        $this->fileman->itemid   = 0;
        $this->fileman->migrate_directory('course_files/'.$data['reference']);

        // write folder.xml
        $this->open_xml_writer("activities/folder_{$moduleid}/folder.xml");
        $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
            'modulename' => 'folder', 'contextid' => $contextid));
        $this->write_xml('folder', $folder, array('/folder/id'));
        $this->xmlwriter->end_tag('activity');
        $this->close_xml_writer();

        // write inforef.xml
        $this->open_xml_writer("activities/folder_{$moduleid}/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();
    }
Beispiel #11
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/DATA
  * data available
  */
 public function process_data($data)
 {
     global $CFG;
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // replay the upgrade step 2007101512
     if (!array_key_exists('asearchtemplate', $data)) {
         $data['asearchtemplate'] = null;
     }
     // replay the upgrade step 2007101513
     if (is_null($data['notification'])) {
         $data['notification'] = 0;
     }
     // conditionally migrate to html format in intro
     if ($CFG->texteditors !== 'textarea') {
         $data['intro'] = text_to_html($data['intro'], false, false, true);
         $data['introformat'] = FORMAT_HTML;
     }
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_data');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // @todo: user data - upgrade content to new file storage
     // add 'export' tag to list and single template.
     $pattern = '/\\#\\#delete\\#\\#(\\s+)\\#\\#approve\\#\\#/';
     $replacement = '##delete##$1##approve##$1##export##';
     $data['listtemplate'] = preg_replace($pattern, $replacement, $data['listtemplate']);
     $data['singletemplate'] = preg_replace($pattern, $replacement, $data['singletemplate']);
     //@todo: user data - move data comments to comments table
     //@todo: user data - move data ratings to ratings table
     // start writing data.xml
     $this->open_xml_writer("activities/data_{$this->moduleid}/data.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'data', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('data', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     $this->xmlwriter->begin_tag('fields');
     return $data;
 }
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/CUSTOMLABEL
  * data available
  */
 public function process_customlabel($data)
 {
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
     // shifts content from name (moodle 1.9 label hacking location) to processed content and
     // computes a new explicit name
     $storedcontent = base64_decode($data['content']);
     $customlabel = json_decode($storedcontent);
     $data['processedcontent'] = $data['name'];
     $data['name'] = $customlabel->labelclass . $data['id'];
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_customlabel');
     // convert course files embedded into the content
     $this->fileman->filearea = 'content';
     $this->fileman->itemid = 0;
     // try get files and reencode from stored content stub.
     $storedcontent = moodle1_converter::migrate_referenced_files($storedcontent, $this->fileman);
     $data['content'] = base64_encode($storedcontent);
     $data['processedcontent'] = moodle1_converter::migrate_referenced_files($data['processedcontent'], $this->fileman);
     // write inforef.xml
     $this->open_xml_writer("activities/customlabel_{$moduleid}/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();
     // write customlabel.xml
     $this->open_xml_writer("activities/customlabel_{$moduleid}/customlabel.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 'modulename' => 'customlabel', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('customlabel', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     // finish writing customlabel.xml
     $this->xmlwriter->end_tag('customlabel');
     $this->xmlwriter->end_tag('activity');
     $this->close_xml_writer();
     return $data;
 }
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/GEOGEBRA
  * data available
  */
 public function process_geogebra($data)
 {
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_geogebra');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // migrate geogebra package file
     $this->fileman->filearea = 'content';
     $this->fileman->itemid = 0;
     // Migrate file
     parse_str($data['url'], $parsedVarsURL);
     try {
         $this->fileman->migrate_file('course_files/' . $parsedVarsURL['filename']);
     } catch (Exception $e) {
         echo 'Caught exception: ', $e->getMessage(), ' File: \'' . $parsedVarsURL['filename'] . '\' (from URL \'', $data['url'], '\') on GeoGebra activity \'' . $data['name'] . '\' <br>';
     }
     // From Moodle 2, URL field only contains information about the GGB file location
     $data['url'] = $parsedVarsURL['filename'];
     if (strrpos($data['url'], '/') !== FALSE) {
         // Remove folder path to leave only file name
         $data['url'] = substr($data['url'], strrpos($data['url'], '/') + 1);
     }
     // Remove filename from parsedVarsURL array (to avoid save twice)
     unset($parsedVarsURL['filename']);
     // Store other attributes in the new param
     $data['attributes'] = http_build_query($parsedVarsURL, '', '&');
     // start writing geogebra.xml
     $this->open_xml_writer("activities/geogebra_{$this->moduleid}/geogebra.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'geogebra', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('geogebra', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     return $data;
 }
Beispiel #14
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/JCLIC
  * data available
  */
 public function process_jclic($data)
 {
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_jclic');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // migrate jclic package file
     $this->fileman->filearea = 'content';
     $this->fileman->itemid = 0;
     if (!jclic_is_valid_external_url($data['url'])) {
         // Migrate file
         try {
             $this->fileman->migrate_file('course_files/' . $data['url']);
         } catch (Exception $e) {
             echo 'Caught exception: ', $e->getMessage(), ' File: \'', $data['url'], '\' on JClic activity \'' . $data['name'] . '\' <br>';
         }
     }
     // To avoid problems if maxgrade is null
     if ($data['maxgrade'] === NULL) {
         $data['maxgrade'] = 100;
     }
     // get grade value from maxgrade
     $data['grade'] = $data['maxgrade'];
     // start writing jclic.xml
     $this->open_xml_writer("activities/jclic_{$this->moduleid}/jclic.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'jclic', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('jclic', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     return $data;
 }
Beispiel #15
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/RCONTENT
  * data available
  */
 public function process_rcontent($data)
 {
     global $CFG;
     // get the course module id and context id
     $instanceid = $data['id'];
     $currentcminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $currentcminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // conditionally migrate to html format in summary
     if ($CFG->texteditors !== 'textarea') {
         $data['intro'] = text_to_html($data['intro'], false, false, true);
     }
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_rcontent');
     // convert course files embedded into the summary
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // check 1.9 version where backup was created
     $backupinfo = $this->converter->get_stash('backup_info');
     if ($backupinfo['moodle_version'] < 2007110503) {
         // as we have no module version data, assume $currmodule->version <= $module->version
         // - fix data as the source 1.9 build hadn't yet at time of backing up.
         if (isset($data['grademethod'])) {
             $data['grademethod'] = $data['grademethod'] % 10;
         }
     }
     // start writing rcontent.xml
     $this->open_xml_writer("activities/rcontent_{$this->moduleid}/rcontent.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'rcontent', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('rcontent', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     $this->xmlwriter->begin_tag('grades');
     return $data;
 }
Beispiel #16
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/LTI
  * data available
  */
 public function process_basiclti($data)
 {
     global $DB;
     // Get the course module id and context id.
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // Get a fresh new file manager for this instance.
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_lti');
     // Convert course files embedded into the intro.
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // Start writing assignment.xml.
     $this->open_xml_writer("activities/lti_{$this->moduleid}/lti.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'lti', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('lti', array('id' => $instanceid));
     $ignorefields = array('id', 'modtype');
     if (!$DB->record_exists('lti_types', array('id' => $data['typeid']))) {
         $ntypeid = $DB->get_field('lti_types_config', 'typeid', array('name' => 'toolurl', 'value' => $data['toolurl']), IGNORE_MULTIPLE);
         if ($ntypeid === false) {
             $ntypeid = $DB->get_field('lti_types_config', 'typeid', array(), IGNORE_MULTIPLE);
         }
         if ($ntypeid === false) {
             $ntypeid = 0;
         }
         $data['typeid'] = $ntypeid;
     }
     if (empty($data['servicesalt'])) {
         $data['servicesalt'] = uniqid('', true);
     }
     foreach ($data as $field => $value) {
         if (!in_array($field, $ignorefields)) {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     return $data;
 }
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ
  * data available
  */
 public function process_quiz($data)
 {
     global $CFG;
     // replay the upgrade step 2008081501
     if (is_null($data['sumgrades'])) {
         $data['sumgrades'] = 0;
         //@todo for user data: quiz_attempts SET sumgrades=0 WHERE sumgrades IS NULL
         //@todo for user data: quiz_grades.grade should be not be null , convert to default 0
     }
     // replay the upgrade step 2009042000
     if ($CFG->texteditors !== 'textarea') {
         $data['intro'] = text_to_html($data['intro'], false, false, true);
         $data['introformat'] = FORMAT_HTML;
     }
     // replay the upgrade step 2009031001
     $data['timelimit'] *= 60;
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_quiz');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // start writing quiz.xml
     $this->open_xml_writer("activities/quiz_{$this->moduleid}/quiz.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'quiz', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('quiz', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     return $data;
 }
Beispiel #18
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK/ITEMS/ITEM
  * data available
  */
 public function process_flashcard_deckdata($data)
 {
     $this->write_xml('deck', $data, array('/deck/id'));
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_flashcard');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'answertext';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['answertext'], $this->fileman);
     // convert course files embedded into the intro
     $this->fileman->filearea = 'responsetext';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['responsetext'], $this->fileman);
 }
Beispiel #19
0
    public function test_referenced_course_files()
    {
        $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 />
    <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'), $files);
        $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 />
    <br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />');
    }
 /**
  * Processes GRADE_OUTCOME tags progressively
  */
 public function process_gradebook_grade_outcome(array $data, array $raw)
 {
     global $CFG;
     // replay the upgrade step 2009110400
     if ($CFG->texteditors !== 'textarea') {
         $data['description'] = text_to_html($data['description'], false, false, true);
         $data['descriptionformat'] = FORMAT_HTML;
     }
     // convert course files embedded into the outcome description field
     $this->fileman->itemid = $data['id'];
     $data['description'] = moodle1_converter::migrate_referenced_files($data['description'], $this->fileman);
     // write the outcome data
     $this->write_xml('outcome', $data, array('/outcome/id'));
     return $data;
 }
Beispiel #21
0
    /**
     * This is executed every time we have one <SCALE> data available
     *
     * @param array $data
     * @param array $raw
     * @return array
     */
    public function process_scale(array $data, array $raw) {
        global $CFG;

        // replay upgrade step 2009110400
        if ($CFG->texteditors !== 'textarea') {
            $data['description'] = text_to_html($data['description'], false, false, true);
            $data['descriptionformat'] = FORMAT_HTML;
        }

        // convert course files embedded into the scale description field
        $this->fileman->itemid = $data['id'];
        $data['description'] = moodle1_converter::migrate_referenced_files($data['description'], $this->fileman);

        // stash the scale
        $this->converter->set_stash('scales', $data, $data['id']);
    }
Beispiel #22
0
 /**
  * Constructor optionally accepting some default values for the migrated files
  *
  * @param moodle1_converter $converter the converter instance we serve to
  * @param int $contextid initial context id of the files being migrated
  * @param string $component initial component name of the files being migrated
  * @param string $filearea initial file area of the files being migrated
  * @param int $itemid initial item id of the files being migrated
  * @param int $userid initial user id of the files being migrated
  */
 public function __construct(moodle1_converter $converter, $contextid = null, $component = null, $filearea = null, $itemid = 0, $userid = null) {
     // set the initial destination of the migrated files
     $this->converter = $converter;
     $this->contextid = $contextid;
     $this->component = $component;
     $this->filearea  = $filearea;
     $this->itemid    = $itemid;
     $this->userid    = $userid;
     // set other useful bits
     $this->basepath  = $converter->get_tempdir_path();
 }
Beispiel #23
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI
  * data available
  */
 public function process_wiki($data)
 {
     global $CFG;
     // We need to check a config setting.
     if (!empty($data['initialcontent'])) {
         //convert file in <INITIALCONTENT>filename</INITIALCONTENT> into a subwiki page if no entry created.
         $temppath = $this->converter->get_tempdir_path();
         $this->initialcontent = file_get_contents($temppath . '/course_files/' . $data['initialcontent']);
         $this->initialcontentfilename = $data['initialcontent'];
         $this->needinitpage = true;
     }
     unset($data['initialcontent']);
     if ($data['wikimode'] !== 'group') {
         $data['wikimode'] = 'individual';
         //@todo need to create extra subwikis due to individual wikimode?
         //this would then need to reference the users in the course that is being restored.(some parent class API needed)
     } else {
         $data['wikimode'] = 'collaborative';
     }
     if (empty($data['name'])) {
         $data['name'] = 'Wiki';
     }
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_wiki');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // convert the introformat if necessary
     if ($CFG->texteditors !== 'textarea') {
         $data['intro'] = text_to_html($data['intro'], false, false, true);
         $data['introformat'] = FORMAT_HTML;
     }
     // we now have all information needed to start writing into the file
     $this->open_xml_writer("activities/wiki_{$this->moduleid}/wiki.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'wiki', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('wiki', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     return $data;
 }
Beispiel #24
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/REFERENTIEL/ACTIVITES/ACTIVITE/DOCUMENTS/DOCUMENT
  * data available
  */
 public function process_document($data)
 {
     $this->write_xml('document', $data, array('/document/id'));
     $this->fileman->filearea = 'document';
     $this->fileman->itemid = $data['id'];
     $this->fileman->userid = $data['userid'];
     $data['document'] = moodle1_converter::migrate_referenced_files($data['document'], $this->fileman);
 }
Beispiel #25
0
 /**
  * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
  *
  * This methods detects the resource type and eventually re-dispatches it to the
  * corresponding resource successor (url, forum, page, imscp).
  */
 public function process_resource(array $data, array $raw)
 {
     global $CFG;
     require_once "{$CFG->libdir}/resourcelib.php";
     // replay the upgrade step 2009042001
     if ($CFG->texteditors !== 'textarea') {
         $data['intro'] = text_to_html($data['intro'], false, false, true);
         $data['introformat'] = FORMAT_HTML;
     }
     // fix invalid null popup and options data
     if (!array_key_exists('popup', $data) or is_null($data['popup'])) {
         $data['popup'] = '';
     }
     if (!array_key_exists('options', $data) or is_null($data['options'])) {
         $data['options'] = '';
     }
     // decide if the legacy resource should be handled by a successor module
     if ($successor = $this->get_successor($data['type'], $data['reference'])) {
         // the instance id will be kept
         $instanceid = $data['id'];
         // move the instance from the resource's modinfo stash to the successor's
         // modinfo stash
         $resourcemodinfo = $this->converter->get_stash('modinfo_resource');
         $successormodinfo = $this->converter->get_stash('modinfo_' . $successor->get_modname());
         $successormodinfo['instances'][$instanceid] = $resourcemodinfo['instances'][$instanceid];
         unset($resourcemodinfo['instances'][$instanceid]);
         $this->converter->set_stash('modinfo_resource', $resourcemodinfo);
         $this->converter->set_stash('modinfo_' . $successor->get_modname(), $successormodinfo);
         // get the course module information for the legacy resource module
         $cminfo = $this->get_cminfo($instanceid);
         // use the version of the successor instead of the current mod/resource
         // beware - the version.php declares info via $module object, do not use
         // a variable of such name here
         $plugin = new stdClass();
         $plugin->version = null;
         $module = $plugin;
         include $CFG->dirroot . '/mod/' . $successor->get_modname() . '/version.php';
         $cminfo['version'] = $plugin->version;
         // stash the new course module information for this successor
         $cminfo['modulename'] = $successor->get_modname();
         $this->converter->set_stash('cminfo_' . $cminfo['modulename'], $cminfo, $instanceid);
         // rewrite the coursecontents stash
         $coursecontents = $this->converter->get_stash('coursecontents');
         $coursecontents[$cminfo['id']]['modulename'] = $successor->get_modname();
         $this->converter->set_stash('coursecontents', $coursecontents);
         // delegate the processing to the successor handler
         return $successor->process_legacy_resource($data, $raw);
     }
     // no successor is interested in this record, convert it to the new mod_resource (aka File module)
     $resource = array();
     $resource['id'] = $data['id'];
     $resource['name'] = $data['name'];
     $resource['intro'] = $data['intro'];
     $resource['introformat'] = $data['introformat'];
     $resource['tobemigrated'] = 0;
     $resource['legacyfiles'] = RESOURCELIB_LEGACYFILES_ACTIVE;
     $resource['legacyfileslast'] = null;
     $resource['filterfiles'] = 0;
     $resource['revision'] = 1;
     $resource['timemodified'] = $data['timemodified'];
     // populate display and displayoptions fields
     $options = array('printintro' => 1);
     if ($data['options'] == 'frame') {
         $resource['display'] = RESOURCELIB_DISPLAY_FRAME;
     } else {
         if ($data['options'] == 'objectframe') {
             $resource['display'] = RESOURCELIB_DISPLAY_EMBED;
         } else {
             if ($data['options'] == 'forcedownload') {
                 $resource['display'] = RESOURCELIB_DISPLAY_DOWNLOAD;
             } else {
                 if ($data['popup']) {
                     $resource['display'] = RESOURCELIB_DISPLAY_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 {
                     $resource['display'] = RESOURCELIB_DISPLAY_AUTO;
                 }
             }
         }
     }
     $resource['displayoptions'] = serialize($options);
     // get the course module id and context id
     $instanceid = $resource['id'];
     $currentcminfo = $this->get_cminfo($instanceid);
     $moduleid = $currentcminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_resource');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $resource['intro'] = moodle1_converter::migrate_referenced_files($resource['intro'], $this->fileman);
     // convert the referenced file itself as a main file in the content area
     $reference = $data['reference'];
     if (strpos($reference, '$@FILEPHP@$') === 0) {
         $reference = str_replace(array('$@FILEPHP@$', '$@SLASH@$', '$@FORCEDOWNLOAD@$'), array('', '/', ''), $reference);
     }
     $this->fileman->filearea = 'content';
     $this->fileman->itemid = 0;
     // Rebuild the file path.
     $curfilepath = '/';
     if ($reference) {
         $curfilepath = pathinfo('/' . $reference, PATHINFO_DIRNAME);
         if ($curfilepath != '/') {
             $curfilepath .= '/';
         }
     }
     try {
         $this->fileman->migrate_file('course_files/' . $reference, $curfilepath, null, 1);
     } catch (moodle1_convert_exception $e) {
         // the file probably does not exist
         $this->log('error migrating the resource main file', backup::LOG_WARNING, 'course_files/' . $reference);
     }
     // write resource.xml
     $this->open_xml_writer("activities/resource_{$moduleid}/resource.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 'modulename' => 'resource', 'contextid' => $contextid));
     $this->write_xml('resource', $resource, array('/resource/id'));
     $this->xmlwriter->end_tag('activity');
     $this->close_xml_writer();
     // write inforef.xml
     $this->open_xml_writer("activities/resource_{$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 is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/WORKSHOP
  * data available
  */
 public function process_workshop($data, $raw)
 {
     // re-use the upgrade function to convert workshop record
     $fakerecord = (object) $data;
     $fakerecord->course = 12345678;
     $this->currentworkshop = (array) workshop_upgrade_transform_instance($fakerecord);
     unset($this->currentworkshop['course']);
     // add the new fields with the default values
     $this->currentworkshop['id'] = $data['id'];
     $this->currentworkshop['evaluation'] = 'best';
     $this->currentworkshop['examplesmode'] = workshop::EXAMPLES_VOLUNTARY;
     $this->currentworkshop['gradedecimals'] = 0;
     $this->currentworkshop['instructauthors'] = '';
     $this->currentworkshop['instructauthorsformat'] = FORMAT_HTML;
     $this->currentworkshop['instructreviewers'] = '';
     $this->currentworkshop['instructreviewersformat'] = FORMAT_HTML;
     $this->currentworkshop['latesubmissions'] = 0;
     foreach (array('submissionend', 'submissionstart', 'assessmentend', 'assessmentstart') as $field) {
         if (!array_key_exists($field, $this->currentworkshop)) {
             $this->currentworkshop[$field] = null;
         }
     }
     // 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);
     // get a fresh new inforef manager for this instance
     $this->inforefman = $this->converter->get_inforef_manager('activity', $moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_workshop');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $this->currentworkshop['intro'] = moodle1_converter::migrate_referenced_files($this->currentworkshop['intro'], $this->fileman);
     // write workshop.xml
     $this->open_xml_writer("activities/workshop_{$moduleid}/workshop.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 'modulename' => 'workshop', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('workshop', array('id' => $instanceid));
     foreach ($this->currentworkshop as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     return $this->currentworkshop;
 }
Beispiel #27
0
    /**
     * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
     * Called by moodle1_mod_resource_handler::process_resource()
     */
    public function process_legacy_resource(array $data, array $raw = null) {

        // 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);

        // convert the legacy data onto the new page record
        $page                       = array();
        $page['id']                 = $data['id'];
        $page['name']               = $data['name'];
        $page['intro']              = $data['intro'];
        $page['introformat']        = $data['introformat'];
        $page['content']            = $data['alltext'];

        if ($data['type'] === 'html') {
            // legacy Resource of the type Web page
            $page['contentformat'] = FORMAT_HTML;

        } else {
            // legacy Resource of the type Plain text page
            $page['contentformat'] = (int)$data['reference'];

            if ($page['contentformat'] < 0 or $page['contentformat'] > 4) {
                $page['contentformat'] = FORMAT_MOODLE;
            }
        }

        $page['legacyfiles']        = RESOURCELIB_LEGACYFILES_ACTIVE;
        $page['legacyfileslast']    = null;
        $page['revision']           = 1;
        $page['timemodified']       = $data['timemodified'];

        // populate display and displayoptions fields
        $options = array('printheading' => 0, 'printintro' => 0);
        if ($data['popup']) {
            $page['display'] = RESOURCELIB_DISPLAY_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 {
            $page['display'] = RESOURCELIB_DISPLAY_OPEN;
        }
        $page['displayoptions'] = serialize($options);

        // get a fresh new file manager for this instance
        $this->fileman = $this->converter->get_file_manager($contextid, 'mod_page');

        // convert course files embedded into the intro
        $this->fileman->filearea = 'intro';
        $this->fileman->itemid   = 0;
        $page['intro'] = moodle1_converter::migrate_referenced_files($page['intro'], $this->fileman);

        // convert course files embedded into the content
        $this->fileman->filearea = 'content';
        $this->fileman->itemid   = 0;
        $page['content'] = moodle1_converter::migrate_referenced_files($page['content'], $this->fileman);

        // write page.xml
        $this->open_xml_writer("activities/page_{$moduleid}/page.xml");
        $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
            'modulename' => 'page', 'contextid' => $contextid));
        $this->write_xml('page', $page, array('/page/id'));
        $this->xmlwriter->end_tag('activity');
        $this->close_xml_writer();

        // write inforef.xml for migrated resource file.
        $this->open_xml_writer("activities/page_{$moduleid}/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();
    }
Beispiel #28
0
 /**
  * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
  * Called by moodle1_mod_resource_handler::process_resource()
  */
 public function process_legacy_resource(array $data, array $raw = null)
 {
     // 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);
     // prepare the new url instance record
     $url = array();
     $url['id'] = $data['id'];
     $url['name'] = $data['name'];
     $url['intro'] = $data['intro'];
     $url['introformat'] = $data['introformat'];
     $url['externalurl'] = $data['reference'];
     $url['timemodified'] = $data['timemodified'];
     // populate display and displayoptions fields
     $options = array('printheading' => 0, 'printintro' => 1);
     if ($data['options'] == 'frame') {
         $url['display'] = RESOURCELIB_DISPLAY_FRAME;
     } else {
         if ($data['options'] == 'objectframe') {
             $url['display'] = RESOURCELIB_DISPLAY_EMBED;
         } else {
             if ($data['popup']) {
                 $url['display'] = RESOURCELIB_DISPLAY_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 {
                 $url['display'] = RESOURCELIB_DISPLAY_AUTO;
             }
         }
     }
     $url['displayoptions'] = serialize($options);
     // populate the parameters field
     $parameters = array();
     if ($data['alltext']) {
         $rawoptions = explode(',', $data['alltext']);
         foreach ($rawoptions as $rawoption) {
             list($variable, $parameter) = explode('=', trim($rawoption), 2);
             $parameters[$parameter] = $variable;
         }
     }
     $url['parameters'] = serialize($parameters);
     // convert course files embedded into the intro
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_url', 'intro');
     $url['intro'] = moodle1_converter::migrate_referenced_files($url['intro'], $this->fileman);
     // write url.xml
     $this->open_xml_writer("activities/url_{$moduleid}/url.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 'modulename' => 'url', 'contextid' => $contextid));
     $this->write_xml('url', $url, array('/url/id'));
     $this->xmlwriter->end_tag('activity');
     $this->close_xml_writer();
     // write inforef.xml
     $this->open_xml_writer("activities/url_{$moduleid}/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();
 }
Beispiel #29
0
 /**
  * Migrate files belonging to one qtype plugin text field.
  *
  * @param array $text the html fragment containing references to files
  * @param string $component the component for restored files
  * @param string $filearea the file area for restored files
  * @param int $itemid the itemid for restored files
  *
  * @return string the text for this field, after files references have been processed
  */
 protected function migrate_files($text, $component, $filearea, $itemid)
 {
     $context = $this->qbankhandler->get_current_category_context();
     $fileman = $this->qbankhandler->get_file_manager();
     $fileman->contextid = $context['contextid'];
     $fileman->component = $component;
     $fileman->filearea = $filearea;
     $fileman->itemid = $itemid;
     $text = moodle1_converter::migrate_referenced_files($text, $fileman);
     return $text;
 }
    public function test_referenced_files_urlencoded()
    {
        $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);
    }