MDL-35305 wiki: backup and restore files
[moodle.git] / mod / wiki / backup / moodle2 / backup_wiki_stepslib.php
CommitLineData
ebe93f74
JP
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/**
593b8385 19 * @package mod_wiki
ebe93f74
JP
20 * @subpackage backup-moodle2
21 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25/**
26 * Define all the backup steps that will be used by the backup_wiki_activity_task
27 */
ab6df974 28
ebe93f74
JP
29/**
30 * Define the complete wiki structure for backup, with file and id annotations
31 */
32class backup_wiki_activity_structure_step extends backup_activity_structure_step {
33
34 protected function define_structure() {
35
36 // To know if we are including userinfo
37 $userinfo = $this->get_setting_value('userinfo');
38
39 // Define each element separated
ab6df974 40 $wiki = new backup_nested_element('wiki', array('id'), array('name', 'intro', 'introformat', 'timecreated', 'timemodified', 'firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend'));
ebe93f74
JP
41
42 $subwikis = new backup_nested_element('subwikis');
43
ab6df974 44 $subwiki = new backup_nested_element('subwiki', array('id'), array('groupid', 'userid'));
ebe93f74
JP
45
46 $pages = new backup_nested_element('pages');
47
1ecc51c4 48 $page = new backup_nested_element('page', array('id'), array('title', 'cachedcontent', 'timecreated', 'timemodified', 'timerendered', 'userid', 'pageviews', 'readonly'));
ebe93f74
JP
49
50 $synonyms = new backup_nested_element('synonyms');
51
ab6df974 52 $synonym = new backup_nested_element('synonym', array('id'), array('pageid', 'pagesynonym'));
ebe93f74
JP
53
54 $links = new backup_nested_element('links');
55
ab6df974 56 $link = new backup_nested_element('link', array('id'), array('frompageid', 'topageid', 'tomissingpage'));
ebe93f74
JP
57
58 $versions = new backup_nested_element('versions');
59
ab6df974
JP
60 $version = new backup_nested_element('version', array('id'), array('content', 'contentformat', 'version', 'timecreated', 'userid'));
61
07f7954d 62 $tags = new backup_nested_element('tags');
ab6df974 63
07f7954d 64 $tag = new backup_nested_element('tag', array('id'), array('name', 'rawname'));
ab6df974 65
ebe93f74 66 // Build the tree
ab6df974 67 $wiki->add_child($subwikis);
ebe93f74
JP
68 $subwikis->add_child($subwiki);
69
70 $subwiki->add_child($pages);
71 $pages->add_child($page);
72
73 $subwiki->add_child($synonyms);
74 $synonyms->add_child($synonym);
75
76 $subwiki->add_child($links);
77 $links->add_child($link);
78
79 $page->add_child($versions);
80 $versions->add_child($version);
ab6df974 81
07f7954d
EL
82 $page->add_child($tags);
83 $tags->add_child($tag);
ebe93f74
JP
84
85 // Define sources
ab6df974 86 $wiki->set_source_table('wiki', array('id' => backup::VAR_ACTIVITYID));
ebe93f74
JP
87
88 // All these source definitions only happen if we are including user info
ab6df974
JP
89 if ($userinfo) {
90 $subwiki->set_source_sql('
ebe93f74
JP
91 SELECT *
92 FROM {wiki_subwikis}
ab6df974
JP
93 WHERE wikiid = ?', array(backup::VAR_PARENTID));
94
95 $page->set_source_table('wiki_pages', array('subwikiid' => backup::VAR_PARENTID));
ebe93f74 96
ab6df974 97 $synonym->set_source_table('wiki_synonyms', array('subwikiid' => backup::VAR_PARENTID));
ebe93f74 98
ab6df974 99 $link->set_source_table('wiki_links', array('subwikiid' => backup::VAR_PARENTID));
ebe93f74 100
ab6df974 101 $version->set_source_table('wiki_versions', array('pageid' => backup::VAR_PARENTID));
ebe93f74 102
07f7954d
EL
103 $tag->set_source_sql('SELECT t.id, t.name, t.rawname
104 FROM {tag} t
105 JOIN {tag_instance} ti ON ti.tagid = t.id
106 WHERE ti.itemtype = ?
107 AND ti.itemid = ?', array(
f0f77dfa 108 backup_helper::is_sqlparam('wiki_pages'),
07f7954d 109 backup::VAR_PARENTID));
ebe93f74
JP
110 }
111
112 // Define id annotations
ab6df974 113 $subwiki->annotate_ids('group', 'groupid');
ebe93f74 114
ab6df974 115 $subwiki->annotate_ids('user', 'userid');
ebe93f74 116
ab6df974 117 $page->annotate_ids('user', 'userid');
ebe93f74 118
ab6df974 119 $version->annotate_ids('user', 'userid');
ebe93f74 120
ebe93f74 121 // Define file annotations
64f93798 122 $wiki->annotate_files('mod_wiki', 'intro', null); // This file area hasn't itemid
e9e9b197 123 $subwiki->annotate_files('mod_wiki', 'attachments', 'id'); // This file area hasn't itemid
ebe93f74
JP
124
125 // Return the root element (wiki), wrapped into standard activity structure
126 return $this->prepare_activity_structure($wiki);
127 }
128
129}