MDL-33362 book: Parse links to book modules from 1.9 backups
[moodle.git] / mod / book / backup / moodle2 / restore_book_activity_task.class.php
blobd9ee50e1448ccf7435e8fdb9df8b1f7260517c78
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.
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/>.
17 /**
18 * Description of book restore task
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
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->dirroot . '/mod/book/backup/moodle2/restore_book_stepslib.php'); // Because it exists (must)
29 class restore_book_activity_task extends restore_activity_task {
31 /**
32 * Define (add) particular settings this activity can have
34 * @return void
36 protected function define_my_settings() {
37 // No particular settings for this activity
40 /**
41 * Define (add) particular steps this activity can have
43 * @return void
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'));
50 /**
51 * Define the contents in the activity that must be
52 * processed by the link decoder
54 * @return array
56 static public function define_decode_contents() {
57 $contents = array();
59 $contents[] = new restore_decode_content('book', array('intro'), 'book');
60 $contents[] = new restore_decode_content('book_chapters', array('content'), 'book_chapter');
62 return $contents;
65 /**
66 * Define the decoding rules for links belonging
67 * to the activity to be executed by the link decoder
69 * @return array
71 static public function define_decode_rules() {
72 $rules = array();
74 // List of books in course
75 $rules[] = new restore_decode_rule('BOOKINDEX', '/mod/book/index.php?id=$1', 'course');
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&amp;chapterid=$2', array('course_module', 'book_chapter'));
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&amp;chapterid=$2', array('book', 'book_chapter'));
85 // Convert old book links MDL-33362
86 $rules[] = new restore_decode_rule('BOOKSTART', '/mod/book/view.php?id=$1', 'course_module');
88 return $rules;
91 /**
92 * Define the restore log rules that will be applied
93 * by the {@link restore_logs_processor} when restoring
94 * book logs. It must return one array
95 * of {@link restore_log_rule} objects
97 * @return array
99 static public function define_restore_log_rules() {
100 $rules = array();
102 $rules[] = new restore_log_rule('book', 'add', 'view.php?id={course_module}', '{book}');
103 $rules[] = new restore_log_rule('book', 'update', 'view.php?id={course_module}&chapterid={book_chapter}', '{book}');
104 $rules[] = new restore_log_rule('book', 'update', 'view.php?id={course_module}', '{book}');
105 $rules[] = new restore_log_rule('book', 'view', 'view.php?id={course_module}&chapterid={book_chapter}', '{book}');
106 $rules[] = new restore_log_rule('book', 'view', 'view.php?id={course_module}', '{book}');
107 $rules[] = new restore_log_rule('book', 'print', 'tool/print/index.php?id={course_module}&chapterid={book_chapter}', '{book}');
108 $rules[] = new restore_log_rule('book', 'print', 'tool/print/index.php?id={course_module}', '{book}');
109 $rules[] = new restore_log_rule('book', 'exportimscp', 'tool/exportimscp/index.php?id={course_module}', '{book}');
110 // To convert old 'generateimscp' log entries
111 $rules[] = new restore_log_rule('book', 'generateimscp', 'tool/generateimscp/index.php?id={course_module}', '{book}',
112 'book', 'exportimscp', 'tool/exportimscp/index.php?id={course_module}', '{book}');
114 return $rules;
118 * Define the restore log rules that will be applied
119 * by the {@link restore_logs_processor} when restoring
120 * course logs. It must return one array
121 * of {@link restore_log_rule} objects
123 * Note this rules are applied when restoring course logs
124 * by the restore final task, but are defined here at
125 * activity level. All them are rules not linked to any module instance (cmid = 0)
127 * @return array
129 static public function define_restore_log_rules_for_course() {
130 $rules = array();
132 $rules[] = new restore_log_rule('book', 'view all', 'index.php?id={course}', null);
134 return $rules;