1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Structure step to restore one edusharing activity
|
|
|
19 |
*
|
|
|
20 |
* @package mod_edusharing
|
|
|
21 |
* @copyright metaVentis GmbH — http://metaventis.com
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
use mod_edusharing\EduSharingService;
|
|
|
28 |
use mod_edusharing\RestoreHelper;
|
|
|
29 |
|
|
|
30 |
require_once(dirname(__FILE__).'/../../lib.php');
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* class restore_edusharing_activity_structure_step
|
|
|
34 |
*/
|
|
|
35 |
class restore_edusharing_activity_structure_step extends restore_activity_structure_step {
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Function define_structure
|
|
|
39 |
*
|
|
|
40 |
* @return mixed
|
|
|
41 |
*/
|
|
|
42 |
protected function define_structure() {
|
|
|
43 |
$paths = [];
|
|
|
44 |
$paths[] = new restore_path_element('edusharing', '/activity/edusharing');
|
|
|
45 |
|
|
|
46 |
// Return the paths wrapped into standard activity structure.
|
|
|
47 |
return $this->prepare_activity_structure($paths);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Function process_edusharing
|
|
|
52 |
*
|
|
|
53 |
* @param object $data
|
|
|
54 |
* @return void
|
|
|
55 |
*/
|
|
|
56 |
protected function process_edusharing($data) {
|
|
|
57 |
global $DB;
|
|
|
58 |
|
|
|
59 |
$data = (object)$data;
|
|
|
60 |
try {
|
|
|
61 |
$data->course = $this->get_courseid();
|
|
|
62 |
// Insert the edusharing record.
|
|
|
63 |
$newid = $DB->insert_record('edusharing', $data);
|
|
|
64 |
// Immediately after inserting "activity" record, call this.
|
|
|
65 |
$helper = new RestoreHelper(new EduSharingService());
|
|
|
66 |
$helper->add_usage($data, $newid);
|
|
|
67 |
$this->apply_activity_instance($newid);
|
|
|
68 |
} catch (Exception $exception) {
|
|
|
69 |
try {
|
|
|
70 |
isset($newid) && $DB->delete_records('edusharing', ['id' => $newid]);
|
|
|
71 |
$message = str_contains($exception->getMessage(), 'NO_CCPUBLISH_PERMISSION')
|
|
|
72 |
? get_string('exc_NO_PUBLISH_RIGHTS', 'edusharing') : $exception->getMessage();
|
|
|
73 |
$this->log($message, backup::LOG_ERROR, null, null, true);
|
|
|
74 |
} catch (Exception $stupidexception) {
|
|
|
75 |
// Well, there is only so much we can do...
|
|
|
76 |
unset($stupidexception);
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
* Function after_execute
|
|
|
83 |
*
|
|
|
84 |
* @return void
|
|
|
85 |
*/
|
|
|
86 |
protected function after_execute() {
|
|
|
87 |
}
|
|
|
88 |
}
|