-
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.
* release/1.2.0: fix (version): last bugfixes and preparing for new release that fixes #2 fix (uninstall): uninstalling the plugin now deletes groupings connected with plugin instances fix (backup): more fixes for backup api group handling fix (backup): more fixes for backup api group handling fix (backup): fixes for backup api fix (backup): Fix for backup api fix (backup): Fixes for backup and privacy api feat (backup): added backup api support and fixed minor bugs fix(files): removed unnecessary moodle_internal constants
- Loading branch information
Showing
37 changed files
with
748 additions
and
136 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,74 @@ | ||
<?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/>. | ||
|
||
/** | ||
* The task that provides all the steps to perform a complete backup is defined here. | ||
* | ||
* @package mod_discourse | ||
* @category backup | ||
* @copyright 2022 coactum GmbH | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot.'/mod/discourse/backup/moodle2/backup_discourse_stepslib.php'); | ||
|
||
/** | ||
* The class provides all the settings and steps to perform one complete backup of mod_discourse. | ||
*/ | ||
class backup_discourse_activity_task extends backup_activity_task { | ||
|
||
/** | ||
* Defines particular settings for the plugin. | ||
*/ | ||
protected function define_my_settings() { | ||
// No particular settings for this activity. | ||
} | ||
|
||
/** | ||
* Defines particular steps for the backup process. | ||
*/ | ||
protected function define_my_steps() { | ||
$this->add_step(new backup_discourse_activity_structure_step('discourse_structure', 'discourse.xml')); | ||
} | ||
|
||
/** | ||
* Codes the transformations to perform in the activity in order to get transportable (encoded) links. | ||
* | ||
* @param string $content content. | ||
* @return string $content content. | ||
*/ | ||
public static function encode_content_links($content) { | ||
global $CFG; | ||
|
||
$base = preg_quote($CFG->wwwroot, "/"); | ||
|
||
// Link to the list of discourses. | ||
$search = "/(".$base."\/mod\/discourse\/index.php\?id\=)([0-9]+)/"; | ||
$content = preg_replace($search, '$@DISCOURSEINDEX*$2@$', $content); | ||
|
||
// Link to discourse view by moduleid. | ||
$search = "/(".$base."\/mod\/discourse\/view.php\?id\=)([0-9]+)/"; | ||
$content = preg_replace($search, '$@DISCOURSEVIEWBYID*$2@$', $content); | ||
|
||
// Link to discourse group view by moduleid, group and userid. | ||
$search = "/(".$base."\/mod\/discourse\/groupview.php\?id\=)([0-9]+)(&|&)group=([0-9]+)(&|&)userid=([0-9]+)/"; | ||
$content = preg_replace($search, '$@DISCOURSEGROUPVIEW*$2*$4*$6@$', $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,89 @@ | ||
<?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_discourse are defined here. | ||
* | ||
* @package mod_discourse | ||
* @category backup | ||
* @copyright 2022 coactum GmbH | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
/** | ||
* Define the complete structure for backup, with file and id annotations. | ||
*/ | ||
class backup_discourse_activity_structure_step extends backup_activity_structure_step { | ||
|
||
/** | ||
* Defines the structure of the resulting xml file. | ||
* | ||
* @return backup_nested_element The structure wrapped by the common 'activity' element. | ||
*/ | ||
protected function define_structure() { | ||
$userinfo = $this->get_setting_value('userinfo'); | ||
$groupinfo = $this->get_setting_value('groups'); | ||
|
||
// Replace with the attributes and final elements that the element will handle. | ||
$discourse = new backup_nested_element('discourse', array('id'), array( | ||
'name', 'intro', 'introformat', 'timecreated', 'timemodified', | ||
'autoswitch', 'activephase', 'hintphaseone', 'hintphasetwo', | ||
'hintphasethree', 'hintphasefour', 'deadlinephaseone', 'deadlinephasetwo', | ||
'deadlinephasethree', 'deadlinephasefour', 'groupingid')); | ||
|
||
$participants = new backup_nested_element('participants'); | ||
|
||
$participant = new backup_nested_element('participant', array('id'), array('userid', 'groupids')); | ||
|
||
$submissions = new backup_nested_element('submissions'); | ||
|
||
$submission = new backup_nested_element('submission', array('id'), array( | ||
'groupid', 'submission', 'currentversion', 'format', 'timecreated', 'timemodified')); | ||
|
||
// Build the tree with these elements with $discourse as the root of the backup tree. | ||
|
||
$discourse->add_child($participants); | ||
$participants->add_child($participant); | ||
|
||
$discourse->add_child($submissions); | ||
$submissions->add_child($submission); | ||
|
||
// Define the source tables for the elements. | ||
|
||
$discourse->set_source_table('discourse', array('id' => backup::VAR_ACTIVITYID)); | ||
|
||
if ($userinfo && $groupinfo) { | ||
$participant->set_source_table('discourse_participants', array('discourse' => backup::VAR_PARENTID)); | ||
|
||
$submission->set_source_table('discourse_submissions', array('discourse' => backup::VAR_PARENTID)); | ||
} | ||
|
||
// Define id annotations. | ||
|
||
$discourse->annotate_ids('grouping', 'groupingid'); | ||
|
||
if ($userinfo && $groupinfo) { | ||
$participant->annotate_ids('user', 'userid'); | ||
$submission->annotate_ids('group', 'groupid'); | ||
} | ||
|
||
// Define file annotations. | ||
|
||
$discourse->annotate_files('mod_discourse', 'intro', null); // This file area has no itemid. | ||
|
||
return $this->prepare_activity_structure($discourse); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
backup/moodle2/restore_discourse_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,118 @@ | ||
<?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/>. | ||
|
||
/** | ||
* The task that provides a complete restore of mod_discourse is defined here. | ||
* | ||
* @package mod_discourse | ||
* @copyright 2022 coactum GmbH | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot.'/mod/discourse/backup/moodle2/restore_discourse_stepslib.php'); | ||
|
||
/** | ||
* Restore task for mod_discourse. | ||
*/ | ||
class restore_discourse_activity_task extends restore_activity_task { | ||
|
||
/** | ||
* Defines particular settings that this activity can have. | ||
*/ | ||
protected function define_my_settings() { | ||
return; | ||
} | ||
|
||
/** | ||
* Defines particular steps that this activity can have. | ||
* | ||
* @return base_step. | ||
*/ | ||
protected function define_my_steps() { | ||
$this->add_step(new restore_discourse_activity_structure_step('discourse_structure', 'discourse.xml')); | ||
} | ||
|
||
/** | ||
* Defines the contents in the activity that must be processed by the link decoder. | ||
* | ||
* @return array. | ||
*/ | ||
public static function define_decode_contents() { | ||
$contents = array(); | ||
|
||
// Define the contents (files in textareas). | ||
$contents[] = new restore_decode_content('discourse', array('intro'), 'discourse'); | ||
$contents[] = new restore_decode_content('discourse_submissions', array('submission'), 'discourse_submission'); | ||
|
||
return $contents; | ||
} | ||
|
||
/** | ||
* Defines the decoding rules for links belonging to the activity to be executed by the link decoder. | ||
* | ||
* @return array. | ||
*/ | ||
public static function define_decode_rules() { | ||
$rules = array(); | ||
|
||
// Define the rules. | ||
|
||
$rules[] = new restore_decode_rule('DISCOURSEINDEX', '/mod/discourse/index.php?id=$1', 'course'); | ||
$rules[] = new restore_decode_rule('DISCOURSEVIEWBYID', '/mod/discourse/view.php?id=$1', 'course_module'); | ||
$rules[] = new restore_decode_rule('DISCOURSEGROUPVIEW', '/mod/discourse/groupview.php?id=$1&group=$2&userid=$3', | ||
array('course_module', 'groupid', 'userid')); | ||
|
||
return $rules; | ||
} | ||
|
||
/** | ||
* Defines the restore log rules that will be applied by the | ||
* restore_logs_processor when restoring mod_discourse logs. It | ||
* must return one array of restore_log_rule objects. | ||
* | ||
* @return array. | ||
*/ | ||
public static function define_restore_log_rules() { | ||
$rules = array(); | ||
|
||
// Define the rules. | ||
$rules[] = new restore_log_rule('discourse', 'add', 'view.php?id={course_module}', '{discourse}'); | ||
$rules[] = new restore_log_rule('discourse', 'update', 'view.php?id={course_module}', '{discourse}'); | ||
$rules[] = new restore_log_rule('discourse', 'view', 'view.php?id={course_module}', '{discourse}'); | ||
|
||
return $rules; | ||
} | ||
|
||
/** | ||
* Define the restore log rules that will be applied | ||
* by the restore_logs_processor when restoring | ||
* course logs. It must return one array | ||
* of restore_log_rule objects | ||
* | ||
* Note this rules are applied when restoring course logs | ||
* by the restore final task, but are defined here at | ||
* activity level. All them are rules not linked to any module instance (cmid = 0) | ||
*/ | ||
public static function define_restore_log_rules_for_course() { | ||
$rules = array(); | ||
|
||
$rules[] = new restore_log_rule('discourse', 'view all', 'index.php?id={course}', null); | ||
|
||
return $rules; | ||
} | ||
} |
Oops, something went wrong.