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 |
* Description of book restore task
|
|
|
19 |
*
|
|
|
20 |
* @package mod_book
|
|
|
21 |
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
require_once($CFG->dirroot . '/mod/book/backup/moodle2/restore_book_stepslib.php'); // Because it exists (must)
|
|
|
28 |
|
|
|
29 |
class restore_book_activity_task extends restore_activity_task {
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Define (add) particular settings this activity can have
|
|
|
33 |
*
|
|
|
34 |
* @return void
|
|
|
35 |
*/
|
|
|
36 |
protected function define_my_settings() {
|
|
|
37 |
// No particular settings for this activity
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Define (add) particular steps this activity can have
|
|
|
42 |
*
|
|
|
43 |
* @return void
|
|
|
44 |
*/
|
|
|
45 |
protected function define_my_steps() {
|
|
|
46 |
// Choice only has one structure step
|
|
|
47 |
$this->add_step(new restore_book_activity_structure_step('book_structure', 'book.xml'));
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Define the contents in the activity that must be
|
|
|
52 |
* processed by the link decoder
|
|
|
53 |
*
|
|
|
54 |
* @return array
|
|
|
55 |
*/
|
|
|
56 |
public static function define_decode_contents() {
|
|
|
57 |
$contents = array();
|
|
|
58 |
|
|
|
59 |
$contents[] = new restore_decode_content('book', array('intro'), 'book');
|
|
|
60 |
$contents[] = new restore_decode_content('book_chapters', array('content'), 'book_chapter');
|
|
|
61 |
|
|
|
62 |
return $contents;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Define the decoding rules for links belonging
|
|
|
67 |
* to the activity to be executed by the link decoder
|
|
|
68 |
*
|
|
|
69 |
* @return array
|
|
|
70 |
*/
|
|
|
71 |
public static function define_decode_rules() {
|
|
|
72 |
$rules = array();
|
|
|
73 |
|
|
|
74 |
// List of books in course
|
|
|
75 |
$rules[] = new restore_decode_rule('BOOKINDEX', '/mod/book/index.php?id=$1', 'course');
|
|
|
76 |
|
|
|
77 |
// book by cm->id
|
|
|
78 |
$rules[] = new restore_decode_rule('BOOKVIEWBYID', '/mod/book/view.php?id=$1', 'course_module');
|
|
|
79 |
$rules[] = new restore_decode_rule('BOOKVIEWBYIDCH', '/mod/book/view.php?id=$1&chapterid=$2', array('course_module', 'book_chapter'));
|
|
|
80 |
|
|
|
81 |
// book by book->id
|
|
|
82 |
$rules[] = new restore_decode_rule('BOOKVIEWBYB', '/mod/book/view.php?b=$1', 'book');
|
|
|
83 |
$rules[] = new restore_decode_rule('BOOKVIEWBYBCH', '/mod/book/view.php?b=$1&chapterid=$2', array('book', 'book_chapter'));
|
|
|
84 |
|
|
|
85 |
// Convert old book links MDL-33362 & MDL-35007
|
|
|
86 |
$rules[] = new restore_decode_rule('BOOKSTART', '/mod/book/view.php?id=$1', 'course_module');
|
|
|
87 |
$rules[] = new restore_decode_rule('BOOKCHAPTER', '/mod/book/view.php?id=$1&chapterid=$2', array('course_module', 'book_chapter'));
|
|
|
88 |
|
|
|
89 |
return $rules;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
* Define the restore log rules that will be applied
|
|
|
94 |
* by the {@link restore_logs_processor} when restoring
|
|
|
95 |
* book logs. It must return one array
|
|
|
96 |
* of {@link restore_log_rule} objects
|
|
|
97 |
*
|
|
|
98 |
* @return array
|
|
|
99 |
*/
|
|
|
100 |
public static function define_restore_log_rules() {
|
|
|
101 |
$rules = array();
|
|
|
102 |
|
|
|
103 |
$rules[] = new restore_log_rule('book', 'add', 'view.php?id={course_module}', '{book}');
|
|
|
104 |
$rules[] = new restore_log_rule('book', 'update', 'view.php?id={course_module}&chapterid={book_chapter}', '{book}');
|
|
|
105 |
$rules[] = new restore_log_rule('book', 'update', 'view.php?id={course_module}', '{book}');
|
|
|
106 |
$rules[] = new restore_log_rule('book', 'view', 'view.php?id={course_module}&chapterid={book_chapter}', '{book}');
|
|
|
107 |
$rules[] = new restore_log_rule('book', 'view', 'view.php?id={course_module}', '{book}');
|
|
|
108 |
$rules[] = new restore_log_rule('book', 'print', 'tool/print/index.php?id={course_module}&chapterid={book_chapter}', '{book}');
|
|
|
109 |
$rules[] = new restore_log_rule('book', 'print', 'tool/print/index.php?id={course_module}', '{book}');
|
|
|
110 |
$rules[] = new restore_log_rule('book', 'exportimscp', 'tool/exportimscp/index.php?id={course_module}', '{book}');
|
|
|
111 |
// To convert old 'generateimscp' log entries
|
|
|
112 |
$rules[] = new restore_log_rule('book', 'generateimscp', 'tool/generateimscp/index.php?id={course_module}', '{book}',
|
|
|
113 |
'book', 'exportimscp', 'tool/exportimscp/index.php?id={course_module}', '{book}');
|
|
|
114 |
$rules[] = new restore_log_rule('book', 'print chapter', 'tool/print/index.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}');
|
|
|
115 |
$rules[] = new restore_log_rule('book', 'update chapter', 'view.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}');
|
|
|
116 |
$rules[] = new restore_log_rule('book', 'add chapter', 'view.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}');
|
|
|
117 |
$rules[] = new restore_log_rule('book', 'view chapter', 'view.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}');
|
|
|
118 |
|
|
|
119 |
return $rules;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
/**
|
|
|
123 |
* Define the restore log rules that will be applied
|
|
|
124 |
* by the {@link restore_logs_processor} when restoring
|
|
|
125 |
* course logs. It must return one array
|
|
|
126 |
* of {@link restore_log_rule} objects
|
|
|
127 |
*
|
|
|
128 |
* Note this rules are applied when restoring course logs
|
|
|
129 |
* by the restore final task, but are defined here at
|
|
|
130 |
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
|
|
131 |
*
|
|
|
132 |
* @return array
|
|
|
133 |
*/
|
|
|
134 |
public static function define_restore_log_rules_for_course() {
|
|
|
135 |
$rules = array();
|
|
|
136 |
|
|
|
137 |
$rules[] = new restore_log_rule('book', 'view all', 'index.php?id={course}', null);
|
|
|
138 |
|
|
|
139 |
return $rules;
|
|
|
140 |
}
|
|
|
141 |
}
|