-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from mebis-lp/Backup
Backup
- Loading branch information
Showing
9 changed files
with
528 additions
and
2 deletions.
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,59 @@ | ||
<?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/>. | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
global $CFG; | ||
require_once($CFG->dirroot . '/mod/mootimeter/backup/moodle2/backup_mootimeter_stepslib.php'); | ||
|
||
/** | ||
* Backup class for mod_mootimeter | ||
* | ||
* @package mod_mootimeter | ||
* @copyright 2023, ISB Bayern | ||
* @author Stefan Hanauska <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class backup_mootimeter_activity_task extends backup_activity_task { | ||
|
||
/** | ||
* No specific settings for this activity | ||
*/ | ||
protected function define_my_settings(): void { | ||
} | ||
|
||
/** | ||
* Defines a backup step to store the instance data in the mootimeter.xml file | ||
*/ | ||
protected function define_my_steps(): void { | ||
$this->add_step(new backup_mootimeter_activity_structure_step('mootimeter_structure', 'mootimeter.xml')); | ||
} | ||
|
||
/** | ||
* Encodes the links to view.php for backup | ||
* | ||
* @param string $content | ||
* @return string | ||
*/ | ||
public static function encode_content_links($content): string { | ||
global $CFG; | ||
|
||
$base = preg_quote($CFG->wwwroot . '/mod/mootimeter', '#'); | ||
|
||
$pattern = "#(" . $base . "\/view.php\?id\=)([0-9]+)#"; | ||
$content = preg_replace($pattern, '$@MOOTIMETERVIEWBYID*$2@$', $content); | ||
return $content; | ||
} | ||
} |
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,63 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Backup steps for mod_mootimeter | ||
* | ||
* @package mod_mootimeter | ||
* @copyright 2023, ISB Bayern | ||
* @author Stefan Hanauska <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class backup_mootimeter_activity_structure_step extends backup_activity_structure_step { | ||
/** | ||
* Defines the XML structure for mootimeter backups | ||
* | ||
* @return backup_nested_element | ||
*/ | ||
protected function define_structure(): backup_nested_element { | ||
$mootimeter = new backup_nested_element( | ||
'mootimeter', | ||
['id'], | ||
['course', 'name', 'intro', 'introformat', 'timecreated', 'timemodified'] | ||
); | ||
$mootimeter->set_source_table('mootimeter', ['id' => backup::VAR_ACTIVITYID]); | ||
$mootimeter->annotate_files('mod_mootimeter', 'intro', null); | ||
|
||
$pages = new backup_nested_element('pages'); | ||
$page = new backup_nested_element( | ||
'page', | ||
['id'], | ||
['instance', 'tool', 'title', 'sortorder', 'timecreated', 'timemodified'] | ||
); | ||
$mootimeter->add_child($pages); | ||
$pages->add_child($page); | ||
$this->add_subplugin_structure('mootimetertool', $page, false); | ||
$page->set_source_table('mootimeter_pages', ['instance' => backup::VAR_PARENTID]); | ||
|
||
$tool_settings = new backup_nested_element('tool_settings'); | ||
$tool_setting = new backup_nested_element( | ||
'tool_setting', | ||
['id'], | ||
['tool', 'pageid', 'name', 'value'] | ||
); | ||
$page->add_child($tool_settings); | ||
$tool_settings->add_child($tool_setting); | ||
$tool_setting->set_source_table('mootimeter_tool_settings', ['pageid' => backup::VAR_PARENTID]); | ||
|
||
return $this->prepare_activity_structure($mootimeter); | ||
} | ||
} |
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,69 @@ | ||
<?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/>. | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
global $CFG; | ||
require_once($CFG->dirroot . '/mod/mootimeter/backup/moodle2/restore_mootimeter_stepslib.php'); | ||
|
||
/** | ||
* Restore class for mod_mootimeter | ||
* | ||
* @package mod_mootimeter | ||
* @copyright 2023, ISB Bayern | ||
* @author Stefan Hanauska <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class restore_mootimeter_activity_task extends restore_activity_task { | ||
|
||
/** | ||
* No specific settings for this activity | ||
* | ||
* @return void | ||
*/ | ||
protected function define_my_settings(): void { | ||
} | ||
|
||
/** | ||
* Defines the restore step for mootimeter | ||
* | ||
* @return void | ||
*/ | ||
protected function define_my_steps(): void { | ||
$this->add_step(new restore_mootimeter_activity_structure_step('mootimeter_structure', 'mootimeter.xml')); | ||
} | ||
|
||
/** | ||
* Calls decode functions of other plugins for the intro field. | ||
* | ||
* @return array | ||
*/ | ||
public static function define_decode_contents(): array { | ||
$contents = []; | ||
$contents[] = new restore_decode_content('mootimeter', ['intro'], 'mootimeter'); | ||
return $contents; | ||
} | ||
|
||
/** | ||
* Defines rules for decoding links to view.php in restore step | ||
* | ||
* @return array | ||
*/ | ||
public static function define_decode_rules(): array { | ||
$rules = []; | ||
$rules[] = new restore_decode_rule('MOOTIMETERVIEWBYID', '/mod/mootimeter/view.php?id=$1', 'course_module'); | ||
return $rules; | ||
} | ||
} |
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,100 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Restore steps for mod_mootimeter | ||
* | ||
* @package mod_mootimeter | ||
* @copyright 2023, ISB Bayern | ||
* @author Stefan Hanauska <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class restore_mootimeter_activity_structure_step extends restore_activity_structure_step { | ||
|
||
/** | ||
* List of elements that can be restored | ||
* | ||
* @return array | ||
* @throws base_step_exception | ||
*/ | ||
protected function define_structure(): array { | ||
$paths = []; | ||
$paths[] = new restore_path_element('mootimeter', '/activity/mootimeter'); | ||
|
||
$paths[] = new restore_path_element('page', '/activity/mootimeter/pages/page'); | ||
$paths[] = new restore_path_element('tool_setting', '/activity/mootimeter/pages/page/tool_settings/tool_setting'); | ||
|
||
return $this->prepare_activity_structure($paths); | ||
} | ||
|
||
/** | ||
* Restore a mootimeter record. | ||
* | ||
* @param array|object $data | ||
* @throws base_step_exception | ||
* @throws dml_exception | ||
* @throws restore_step_exception | ||
*/ | ||
protected function process_mootimeter($data): void { | ||
global $DB; | ||
|
||
$data = (object) $data; | ||
$oldid = $data->id; | ||
$data->course = $this->get_courseid(); | ||
|
||
$newid = $DB->insert_record('mootimeter', $data); | ||
$this->set_mapping('mootimeter_id', $oldid, $newid); | ||
$this->apply_activity_instance($newid); | ||
} | ||
|
||
/** | ||
* Restore a page record. | ||
* | ||
* @param array|object $data | ||
* @throws base_step_exception | ||
* @throws dml_exception | ||
* @throws restore_step_exception | ||
*/ | ||
protected function process_page($data): void { | ||
global $DB; | ||
|
||
$data = (object) $data; | ||
$oldid = $data->id; | ||
$data->instance = $this->get_mappingid('mootimeter_id', $data->instance); | ||
$newid = $DB->insert_record('mootimeter_pages', $data); | ||
$this->set_mapping('mootimeter_page_id', $oldid, $newid); | ||
} | ||
|
||
/** | ||
* Restore a tool_settings record. | ||
* | ||
* @param array|object $data | ||
* @throws base_step_exception | ||
* @throws dml_exception | ||
* @throws restore_step_exception | ||
*/ | ||
protected function process_tool_setting($data): void { | ||
global $DB; | ||
|
||
$data = (object) $data; | ||
$oldid = $data->id; | ||
|
||
$data->pageid = $this->get_mappingid('mootimeter_page_id', $data->pageid); | ||
|
||
$newid = $DB->insert_record('mootimeter_tool_settings', $data); | ||
$this->set_mapping('mootimeter_tool_settings_id', $oldid, $newid); | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
tools/quiz/backup/moodle2/backup_mootimetertool_quiz_subplugin.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,56 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Backup definition for this tool | ||
* @package mootimetertool_quiz | ||
* @copyright 2023, ISB Bayern | ||
* @author Stefan Hanauska <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class backup_mootimetertool_quiz_subplugin extends backup_subplugin { | ||
|
||
/** | ||
* Returns the nested structure of this content type | ||
* @return \backup_subplugin_element | ||
*/ | ||
protected function define_mootimeter_subplugin_structure() { | ||
$userinfo = $this->get_setting_value('userinfo'); | ||
|
||
$subplugin = $this->get_subplugin_element(); | ||
$subpluginwrapper = new backup_nested_element($this->get_recommended_name()); | ||
$subpluginquizoptions = new backup_nested_element( | ||
'mtmt_quiz_options', | ||
['id'], | ||
['pageid', 'optiontext', 'optioniscorrect', 'timecreated', 'timemodified'] | ||
); | ||
$subplugin->add_child($subpluginwrapper); | ||
$subpluginwrapper->add_child($subpluginquizoptions); | ||
$subpluginquizoptions->set_source_table('mtmt_quiz_options', ['pageid' => backup::VAR_PARENTID]); | ||
|
||
if ($userinfo) { | ||
$subpluginquizanswers = new backup_nested_element( | ||
'mtmt_quiz_answers', | ||
['id'], | ||
['pageid', 'usermodified', 'optionid', 'timecreated', 'timemodified'] | ||
); | ||
$subpluginquizanswers->set_source_table('mtmt_quiz_answers', ['pageid' => backup::VAR_PARENTID]); | ||
$subpluginwrapper->add_child($subpluginquizanswers); | ||
} | ||
|
||
return $subplugin; | ||
} | ||
} |
Oops, something went wrong.