1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - https://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Define all the restore steps that will be used by the restore_stickynotes_activity_task
|
|
|
19 |
*
|
|
|
20 |
* @package mod_stickynotes
|
|
|
21 |
* @copyright 2021 Olivier VALENTIN
|
|
|
22 |
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Structure step to restore one stickynotes activity
|
|
|
29 |
*
|
|
|
30 |
* @package mod_stickynotes
|
|
|
31 |
* @copyright 2021 Olivier VALENTIN
|
|
|
32 |
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class restore_stickynotes_activity_structure_step extends restore_activity_structure_step {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Define the structure of the restore workflow.
|
|
|
38 |
*
|
|
|
39 |
* @return restore_path_element $structure
|
|
|
40 |
* @throws base_step_exception
|
|
|
41 |
*/
|
|
|
42 |
protected function define_structure() {
|
|
|
43 |
|
|
|
44 |
$paths = array();
|
|
|
45 |
$userinfo = $this->get_setting_value('userinfo');
|
|
|
46 |
|
|
|
47 |
$paths[] = new restore_path_element('stickynotes', '/activity/stickynotes');
|
|
|
48 |
$paths[] = new restore_path_element('stickynotescolumn',
|
|
|
49 |
'/activity/stickynotes/stickynotescolumns/stickynotescolumn');
|
|
|
50 |
|
|
|
51 |
if ($userinfo) {
|
|
|
52 |
$paths[] = new restore_path_element('stickynotesnote',
|
|
|
53 |
'/activity/stickynotes/stickynotescolumns/stickynotescolumn/stickynotesnotes/stickynotesnote');
|
|
|
54 |
$paths[] = new restore_path_element('stickynotesvote',
|
|
|
55 |
'/activity/stickynotes/stickynotescolumns/stickynotescolumn/stickynotesnotes/stickynotesnote/stickynotesvotes/stickynotesvote');
|
|
|
56 |
}
|
|
|
57 |
// Return the paths wrapped into standard activity structure.
|
|
|
58 |
return $this->prepare_activity_structure($paths);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Process a stickynotes restore.
|
|
|
63 |
* @param object $data The data in object form
|
|
|
64 |
* @return void
|
|
|
65 |
*/
|
|
|
66 |
protected function process_stickynotes($data) {
|
|
|
67 |
global $DB;
|
|
|
68 |
$data = (object)$data;
|
|
|
69 |
$data->course = $this->get_courseid();
|
|
|
70 |
// Insert the page record.
|
|
|
71 |
$newitemid = $DB->insert_record('stickynotes', $data);
|
|
|
72 |
// Immediately after inserting "activity" record, call this.
|
|
|
73 |
$this->apply_activity_instance($newitemid);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Process stickynotes
|
|
|
78 |
* @param object $data The data in object form
|
|
|
79 |
* @return void
|
|
|
80 |
* @throws dml_exception
|
|
|
81 |
*/
|
|
|
82 |
protected function process_stickynotescolumn($data) {
|
|
|
83 |
global $DB;
|
|
|
84 |
$data = (object)$data;
|
|
|
85 |
$oldid = $data->id;
|
|
|
86 |
$data->stickyid = $this->get_new_parentid('stickynotes');
|
|
|
87 |
|
|
|
88 |
$newitemid = $DB->insert_record('stickynotes_column', $data);
|
|
|
89 |
$this->set_mapping('stickynotescolumn', $oldid, $newitemid);
|
|
|
90 |
}
|
|
|
91 |
/**
|
|
|
92 |
* Process stickynotes_note
|
|
|
93 |
* @param object $data The data in object form
|
|
|
94 |
* @return void
|
|
|
95 |
* @throws dml_exception
|
|
|
96 |
*/
|
|
|
97 |
protected function process_stickynotesnote($data) {
|
|
|
98 |
global $DB;
|
|
|
99 |
$data = (object)$data;
|
|
|
100 |
$oldid = $data->id;
|
|
|
101 |
$data->stickyid = $this->get_new_parentid('stickynotes');
|
|
|
102 |
$data->stickycolid = $this->get_new_parentid('stickynotescolumn');
|
|
|
103 |
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
104 |
|
|
|
105 |
$newitemid = $DB->insert_record('stickynotes_note', $data);
|
|
|
106 |
$this->set_mapping('stickynotesnote', $oldid, $newitemid);
|
|
|
107 |
}
|
|
|
108 |
/**
|
|
|
109 |
* Process stickynotes_vote
|
|
|
110 |
* @param object $data The data in object form
|
|
|
111 |
* @return void
|
|
|
112 |
* @throws dml_exception
|
|
|
113 |
*/
|
|
|
114 |
protected function process_stickynotesvote($data) {
|
|
|
115 |
global $DB;
|
|
|
116 |
$data = (object)$data;
|
|
|
117 |
$oldid = $data->id;
|
|
|
118 |
$data->stickyid = $this->get_new_parentid('stickynotes');
|
|
|
119 |
$data->stickynoteid = $this->get_new_parentid('stickynotesnote');
|
|
|
120 |
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
121 |
|
|
|
122 |
$newitemid = $DB->insert_record('stickynotes_vote', $data);
|
|
|
123 |
$this->set_mapping('stickynotesvote', $oldid, $newitemid);
|
|
|
124 |
}
|
|
|
125 |
/**
|
|
|
126 |
* Post-execution actions
|
|
|
127 |
*/
|
|
|
128 |
protected function after_execute() {
|
|
|
129 |
// Add page related files, no need to match by itemname (just internally handled context).
|
|
|
130 |
$this->add_related_files('mod_stickynotes', 'intro', null);
|
|
|
131 |
}
|
|
|
132 |
}
|