Skip to content

Commit 021113d

Browse files
Add Backup and Restore functionality
1 parent 9fd5bc5 commit 021113d

File tree

6 files changed

+291
-2
lines changed

6 files changed

+291
-2
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
// This file is part of Moodle - http://moodle.org/
4+
//
5+
// Moodle is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Moodle is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17+
18+
/**
19+
* Defines backup_groupmebers_activity_task class
20+
*
21+
* @package mod_groupmembers
22+
* @category backup
23+
* @copyright 2019 Justus Dieckmann WWU
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
*/
26+
27+
defined('MOODLE_INTERNAL') || die();
28+
29+
require_once($CFG->dirroot . '/mod/groupmembers/backup/moodle2/backup_groupmembers_stepslib.php');
30+
31+
/**
32+
* Provides the steps to perform one complete backup of the Groupmembers instance
33+
*/
34+
class backup_groupmembers_activity_task extends backup_activity_task {
35+
36+
/**
37+
* No specific settings for this activity
38+
*/
39+
protected function define_my_settings() {
40+
}
41+
42+
/**
43+
* Defines a backup step to store the instance data in the groupmembers.xml file
44+
*/
45+
protected function define_my_steps() {
46+
$this->add_step(new backup_groupmembers_activity_structure_step('groupmembers_structure', 'groupmembers.xml'));
47+
}
48+
49+
/**
50+
* Encodes URLs to the index.php and view.php scripts
51+
*
52+
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
53+
* @return string the content with the URLs encoded
54+
*/
55+
static public function encode_content_links($content) {
56+
global $CFG;
57+
58+
$base = preg_quote($CFG->wwwroot,"/");
59+
60+
// Link to the list of groupmembers
61+
$search="/(".$base."\/mod\/groupmembers\/index.php\?id\=)([0-9]+)/";
62+
$content= preg_replace($search, '$@GROUPMEMBERINDEX*$2@$', $content);
63+
64+
// Link to view by moduleid
65+
$search="/(".$base."\/mod\/groupmembers\/view.php\?id\=)([0-9]+)/";
66+
$content= preg_replace($search, '$@GROUPMEMBERVIEWBYID*$2@$', $content);
67+
68+
return $content;
69+
}
70+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
// This file is part of Moodle - http://moodle.org/
4+
//
5+
// Moodle is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Moodle is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17+
18+
/**
19+
* Define all the backup steps that will be used by the backup_groupmembers_activity_task
20+
*
21+
* @package mod_groupmembers
22+
* @copyright 2019 Justus Dieckmann WWU
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
/**
29+
* Define the complete groupmembers structure for backup, with file and id annotations
30+
*/
31+
class backup_groupmembers_activity_structure_step extends backup_activity_structure_step {
32+
33+
protected function define_structure() {
34+
35+
// To know if we are including userinfo
36+
$userinfo = $this->get_setting_value('userinfo');
37+
38+
// Define each element separated
39+
$groupmembers = new backup_nested_element('groupmembers', array('id'),
40+
array('name', 'intro', 'introformat', 'listgroupingid', 'showgroups', 'showemail', 'timemodified'));
41+
42+
// Define sources
43+
$groupmembers->set_source_table('groupmembers', array('id' => backup::VAR_ACTIVITYID));
44+
45+
// Define id annotations
46+
47+
// Define file annotations
48+
$groupmembers->annotate_files('mod_groupmembers', 'intro', null);
49+
$groupmembers->annotate_files('mod_groupmembers', 'content', null);
50+
51+
// Return the root element (groupmembers), wrapped into standard activity structure
52+
return $this->prepare_activity_structure($groupmembers);
53+
}
54+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
// This file is part of Moodle - http://moodle.org/
4+
//
5+
// Moodle is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Moodle is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17+
18+
/**
19+
* @package mod_groupmembers
20+
* @copyright 2019 Justus Dieckmann WWU
21+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22+
*/
23+
24+
defined('MOODLE_INTERNAL') || die();
25+
26+
require_once($CFG->dirroot . '/mod/groupmembers/backup/moodle2/restore_groupmembers_stepslib.php'); // Because it exists (must)
27+
28+
/**
29+
* folder restore task that provides all the settings and steps to perform one
30+
* complete restore of the activity
31+
*/
32+
class restore_groupmembers_activity_task extends restore_activity_task {
33+
34+
/**
35+
* Define (add) particular settings this activity can have
36+
*/
37+
protected function define_my_settings() {
38+
}
39+
40+
/**
41+
* Define (add) particular steps this activity can have
42+
*/
43+
protected function define_my_steps() {
44+
// groupmembers only has one structure step
45+
$this->add_step(new restore_groupmembers_activity_structure_step('groupmembers_structure', 'groupmembers.xml'));
46+
}
47+
48+
/**
49+
* Define the contents in the activity that must be
50+
* processed by the link decoder
51+
*/
52+
static public function define_decode_contents() {
53+
$contents = array();
54+
55+
$contents[] = new restore_decode_content('groupmembers', array('intro'), 'groupmembers');
56+
57+
return $contents;
58+
}
59+
60+
/**
61+
* Define the decoding rules for links belonging
62+
* to the activity to be executed by the link decoder
63+
*/
64+
static public function define_decode_rules() {
65+
$rules = array();
66+
67+
$rules[] = new restore_decode_rule('GROUPMEMBERVIEWBYID', '/mod/groupmember/view.php?id=$1', 'course_module');
68+
$rules[] = new restore_decode_rule('GROUPMEMBERINDEX', '/mod/groupmember/index.php?id=$1', 'course');
69+
70+
return $rules;
71+
72+
}
73+
74+
/**
75+
* Define the restore log rules that will be applied
76+
* by the {@link restore_logs_processor} when restoring
77+
* folder logs. It must return one array
78+
* of {@link restore_log_rule} objects
79+
*/
80+
static public function define_restore_log_rules() {
81+
$rules = array();
82+
83+
$rules[] = new restore_log_rule('groupmembers', 'view', 'view.php?id={course_module}', '{groupmembers}');
84+
85+
return $rules;
86+
}
87+
88+
/**
89+
* Define the restore log rules that will be applied
90+
* by the {@link restore_logs_processor} when restoring
91+
* course logs. It must return one array
92+
* of {@link restore_log_rule} objects
93+
*
94+
* Note this rules are applied when restoring course logs
95+
* by the restore final task, but are defined here at
96+
* activity level. All them are rules not linked to any module instance (cmid = 0)
97+
*/
98+
static public function define_restore_log_rules_for_course() {
99+
$rules = array();
100+
101+
$rules[] = new restore_log_rule('groupmembers', 'view all', 'index.php?id={course}', null);
102+
103+
return $rules;
104+
}
105+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
// This file is part of Moodle - http://moodle.org/
4+
//
5+
// Moodle is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Moodle is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17+
18+
/**
19+
* @package mod_groupmembers
20+
* @copyright 2019 Justus Dieckmann WWU
21+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22+
*/
23+
24+
/**
25+
* Define all the restore steps that will be used by the restore_groupmembers_activity_task
26+
*/
27+
28+
/**
29+
* Structure step to restore one groupmembers activity
30+
*/
31+
class restore_groupmembers_activity_structure_step extends restore_activity_structure_step {
32+
33+
protected function define_structure() {
34+
35+
$paths = array();
36+
$paths[] = new restore_path_element('groupmembers', '/activity/groupmembers');
37+
38+
// Return the paths wrapped into standard activity structure
39+
return $this->prepare_activity_structure($paths);
40+
}
41+
42+
protected function process_groupmembers($data) {
43+
global $DB;
44+
45+
$data = (object)$data;
46+
$oldid = $data->id;
47+
$data->course = $this->get_courseid();
48+
49+
// insert the folder record
50+
$newitemid = $DB->insert_record('groupmembers', $data);
51+
// immediately after inserting "activity" record, call this
52+
$this->apply_activity_instance($newitemid);
53+
}
54+
55+
protected function after_execute() {
56+
// Add folder related files, no need to match by itemname (just internally handled context)
57+
$this->add_related_files('mod_groupmembers', 'intro', null);
58+
$this->add_related_files('mod_groupmembers', 'content', null);
59+
}
60+
}

lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function groupmembers_supports($feature) {
5656
case FEATURE_GRADE_OUTCOMES:
5757
return false;
5858
case FEATURE_BACKUP_MOODLE2:
59-
return false;
59+
return true;
6060
case FEATURE_SHOW_DESCRIPTION:
6161
return true;
6262
default:

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727

2828
$plugin->maturity = MATURITY_STABLE;
2929
$plugin->release = 'v3.6-r1';
30-
$plugin->version = 2018112000; // The current module version (Date: YYYYMMDDXX)
30+
$plugin->version = 2019061800; // The current module version (Date: YYYYMMDDXX)
3131
$plugin->requires = 2016120500; // Requires this Moodle version
3232
$plugin->component = 'mod_groupmembers'; // Full name of the plugin (used for diagnostics).

0 commit comments

Comments
 (0)