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-23479 backup - glossary restore & old code deleted (but restore l…
…ogs)
- Loading branch information
Showing
4 changed files
with
228 additions
and
1,149 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
mod/glossary/backup/moodle2/restore_glossary_activity_task.class.php
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,76 @@ | ||
<?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/>. | ||
|
||
/** | ||
* @package moodlecore | ||
* @subpackage backup-moodle2 | ||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot . '/mod/glossary/backup/moodle2/restore_glossary_stepslib.php'); // Because it exists (must) | ||
|
||
/** | ||
* glossary restore task that provides all the settings and steps to perform one | ||
* complete restore of the activity | ||
*/ | ||
class restore_glossary_activity_task extends restore_activity_task { | ||
|
||
/** | ||
* Define (add) particular settings this activity can have | ||
*/ | ||
protected function define_my_settings() { | ||
// No particular settings for this activity | ||
} | ||
|
||
/** | ||
* Define (add) particular steps this activity can have | ||
*/ | ||
protected function define_my_steps() { | ||
// Choice only has one structure step | ||
$this->add_step(new restore_glossary_activity_structure_step('glossary_structure', 'glossary.xml')); | ||
} | ||
|
||
/** | ||
* Define the contents in the activity that must be | ||
* processed by the link decoder | ||
*/ | ||
static public function define_decode_contents() { | ||
$contents = array(); | ||
|
||
$contents[] = new restore_decode_content('glossary', array('intro'), 'glossary'); | ||
$contents[] = new restore_decode_content('glossary_entries', array('definition'), 'glossary_entry'); | ||
|
||
return $contents; | ||
} | ||
|
||
/** | ||
* Define the decoding rules for links belonging | ||
* to the activity to be executed by the link decoder | ||
*/ | ||
static public function define_decode_rules() { | ||
$rules = array(); | ||
|
||
$rules[] = new restore_decode_rule('GLOSSARYVIEWBYID', '/mod/glossary/view.php?id=$1', 'course_module'); | ||
$rules[] = new restore_decode_rule('GLOSSARYINDEX', '/mod/glossary/index.php?id=$1', 'course'); | ||
|
||
return $rules; | ||
|
||
} | ||
} |
152 changes: 152 additions & 0 deletions
152
mod/glossary/backup/moodle2/restore_glossary_stepslib.php
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,152 @@ | ||
<?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/>. | ||
|
||
/** | ||
* @package moodlecore | ||
* @subpackage backup-moodle2 | ||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
/** | ||
* Define all the restore steps that will be used by the restore_glossary_activity_task | ||
*/ | ||
|
||
/** | ||
* Structure step to restore one glossary activity | ||
*/ | ||
class restore_glossary_activity_structure_step extends restore_activity_structure_step { | ||
|
||
protected function define_structure() { | ||
|
||
$paths = array(); | ||
$userinfo = $this->get_setting_value('userinfo'); | ||
|
||
$paths[] = new restore_path_element('glossary', '/activity/glossary'); | ||
$paths[] = new restore_path_element('glossary_category', '/activity/glossary/categories/category'); | ||
if ($userinfo) { | ||
$paths[] = new restore_path_element('glossary_entry', '/activity/glossary/entries/entry'); | ||
$paths[] = new restore_path_element('glossary_alias', '/activity/glossary/entries/entry/aliases/alias'); | ||
$paths[] = new restore_path_element('glossary_rating', '/activity/glossary/entries/entry/ratings/rating'); | ||
$paths[] = new restore_path_element('glossary_category_entry', | ||
'/activity/glossary/categories/category/category_entries/category_entry'); | ||
} | ||
|
||
// Return the paths wrapped into standard activity structure | ||
return $this->prepare_activity_structure($paths); | ||
} | ||
|
||
protected function process_glossary($data) { | ||
global $DB; | ||
|
||
$data = (object)$data; | ||
$oldid = $data->id; | ||
$data->course = $this->get_courseid(); | ||
|
||
$data->assesstimestart = $this->apply_date_offset($data->assesstimestart); | ||
$data->assesstimefinish = $this->apply_date_offset($data->assesstimefinish); | ||
if ($data->scale < 0) { // scale found, get mapping | ||
$data->scale = -($this->get_mappingid('scale', abs($data->scale))); | ||
} | ||
$formats = get_list_of_plugins('mod/glossary/formats'); // Check format | ||
if (!in_array($data->displayformat, $formats)) { | ||
$data->displayformat = 'dictionary'; | ||
} | ||
|
||
// insert the glossary record | ||
$newitemid = $DB->insert_record('glossary', $data); | ||
$this->apply_activity_instance($newitemid); | ||
} | ||
|
||
protected function process_glossary_entry($data) { | ||
global $DB; | ||
|
||
$data = (object)$data; | ||
$oldid = $data->id; | ||
|
||
$data->glossaryid = $this->get_new_parentid('glossary'); | ||
$data->userid = $this->get_mappingid('user', $data->userid); | ||
$data->sourceglossaryid = $this->get_mappingid('glossary', $data->sourceglossaryid); | ||
|
||
$data->timecreated = $this->apply_date_offset($data->timecreated); | ||
$data->timemodified = $this->apply_date_offset($data->timemodified); | ||
|
||
// insert the entry record | ||
$newitemid = $DB->insert_record('glossary_entries', $data); | ||
$this->set_mapping('glossary_entry', $oldid, $newitemid, true); // childs and files by itemname | ||
} | ||
|
||
protected function process_glossary_alias($data) { | ||
global $DB; | ||
|
||
$data = (object)$data; | ||
$oldid = $data->id; | ||
|
||
$data->entryid = $this->get_new_parentid('glossary_entry'); | ||
$data->alias = $data->alias_text; | ||
$newitemid = $DB->insert_record('glossary_alias', $data); | ||
} | ||
|
||
protected function process_glossary_rating($data) { | ||
global $DB; | ||
|
||
$data = (object)$data; | ||
|
||
// Cannot use ratings API, cause, it's missing the ability to specify times (modified/created) | ||
$data->contextid = $this->task->get_contextid(); | ||
$data->itemid = $this->get_new_parentid('glossary_entry'); | ||
if ($data->scaleid < 0) { // scale found, get mapping | ||
$data->scaleid = -($this->get_mappingid('scale', abs($data->scaleid))); | ||
} | ||
$data->rating = $data->value; | ||
$data->userid = $this->get_mappingid('user', $data->userid); | ||
$data->timecreated = $this->apply_date_offset($data->timecreated); | ||
$data->timemodified = $this->apply_date_offset($data->timemodified); | ||
|
||
$newitemid = $DB->insert_record('rating', $data); | ||
} | ||
|
||
protected function process_glossary_category($data) { | ||
global $DB; | ||
|
||
$data = (object)$data; | ||
$oldid = $data->id; | ||
|
||
$data->glossaryid = $this->get_new_parentid('glossary'); | ||
$newitemid = $DB->insert_record('glossary_categories', $data); | ||
$this->set_mapping('glossary_category', $oldid, $newitemid); | ||
} | ||
|
||
protected function process_glossary_category_entry($data) { | ||
global $DB; | ||
|
||
$data = (object)$data; | ||
$oldid = $data->id; | ||
|
||
$data->categoryid = $this->get_new_parentid('glossary_category'); | ||
$data->entryid = $this->get_mappingid('glossary_entry', $data->entryid); | ||
$newitemid = $DB->insert_record('glossary_entries_categories', $data); | ||
} | ||
|
||
protected function after_execute() { | ||
// Add glossary related files, no need to match by itemname (just internally handled context) | ||
$this->add_related_files('mod_glossary', 'intro', null); | ||
// Add entries related files, matching by itemname (glossary_entry) | ||
$this->add_related_files('mod_glossary', 'entry', 'glossary_entry'); | ||
$this->add_related_files('mod_glossary', 'attachment', 'glossary_entry'); | ||
} | ||
} |
Oops, something went wrong.