/** * 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; $this->currentworkshop['conclusion'] = ''; $this->currentworkshop['conclusionformat'] = FORMAT_HTML; 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; }
/** * Copies the records from workshop_old into workshop table * * @return void */ function workshop_upgrade_module_instances() { global $CFG, $DB; upgrade_set_timeout(); $moduleid = $DB->get_field('modules', 'id', array('name' => 'workshop'), MUST_EXIST); $rs = $DB->get_recordset_select('workshop_old', 'newid IS NULL'); foreach ($rs as $old) { $new = workshop_upgrade_transform_instance($old); $newid = $DB->insert_record('workshop', $new, true, true); $DB->set_field('course_modules', 'instance', $newid, array('module' => $moduleid, 'instance' => $old->id)); $DB->set_field('workshop_old', 'newplugin', 'workshop', array('id' => $old->id)); $DB->set_field('workshop_old', 'newid', $newid, array('id' => $old->id)); } $rs->close(); }
/** * Copies the records from workshop_old into workshop table * * @return void */ function workshop_upgrade_module_instances() { global $CFG, $DB; upgrade_set_timeout(); $moduleid = $DB->get_field('modules', 'id', array('name' => 'workshop'), MUST_EXIST); $rs = $DB->get_recordset_select('workshop_old', 'newid IS NULL', null, 'id'); foreach ($rs as $old) { $new = workshop_upgrade_transform_instance($old); $new->id = $old->id; $DB->import_record('workshop', $new); $DB->set_field('workshop_old', 'newplugin', 'workshop', array('id' => $old->id)); $DB->set_field('workshop_old', 'newid', $new->id, array('id' => $old->id)); } $rs->close(); $dbman = $DB->get_manager(); $dbman->reset_sequence('workshop'); }