Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/wiki/backup/moodle2/restore_wiki_stepslib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00032 class restore_wiki_activity_structure_step extends restore_activity_structure_step {
00033 
00034     protected function define_structure() {
00035 
00036         $paths = array();
00037         $userinfo = $this->get_setting_value('userinfo');
00038 
00039         $paths[] = new restore_path_element('wiki', '/activity/wiki');
00040         if ($userinfo) {
00041             $paths[] = new restore_path_element('wiki_subwiki', '/activity/wiki/subwikis/subwiki');
00042             $paths[] = new restore_path_element('wiki_page', '/activity/wiki/subwikis/subwiki/pages/page');
00043             $paths[] = new restore_path_element('wiki_version', '/activity/wiki/subwikis/subwiki/pages/page/versions/version');
00044             $paths[] = new restore_path_element('wiki_tag', '/activity/wiki/subwikis/subwiki/pages/page/tags/tag');
00045             $paths[] = new restore_path_element('wiki_synonym', '/activity/wiki/subwikis/subwiki/synonyms/synonym');
00046             $paths[] = new restore_path_element('wiki_link', '/activity/wiki/subwikis/subwiki/links/link');
00047         }
00048 
00049         // Return the paths wrapped into standard activity structure
00050         return $this->prepare_activity_structure($paths);
00051     }
00052 
00053     protected function process_wiki($data) {
00054         global $DB;
00055 
00056         $data = (object)$data;
00057         $oldid = $data->id;
00058         $data->course = $this->get_courseid();
00059 
00060         $data->editbegin = $this->apply_date_offset($data->editbegin);
00061         $data->editend = $this->apply_date_offset($data->editend);
00062         $data->timemodified = $this->apply_date_offset($data->timemodified);
00063 
00064         // insert the wiki record
00065         $newitemid = $DB->insert_record('wiki', $data);
00066         // immediately after inserting "activity" record, call this
00067         $this->apply_activity_instance($newitemid);
00068     }
00069 
00070     protected function process_wiki_subwiki($data) {
00071         global $DB;
00072 
00073 
00074         $data = (object)$data;
00075         $oldid = $data->id;
00076         $data->wikiid = $this->get_new_parentid('wiki');
00077         $data->groupid = $this->get_mappingid('group', $data->groupid);
00078         $data->userid = $this->get_mappingid('user', $data->userid);
00079 
00080         $newitemid = $DB->insert_record('wiki_subwikis', $data);
00081         $this->set_mapping('wiki_subwiki', $oldid, $newitemid);
00082     }
00083     protected function process_wiki_page($data) {
00084         global $DB;
00085 
00086         $data = (object)$data;
00087         $oldid = $data->id;
00088         $data->subwikiid = $this->get_new_parentid('wiki_subwiki');
00089         $data->userid = $this->get_mappingid('user', $data->userid);
00090         $data->timemodified = $this->apply_date_offset($data->timemodified);
00091         $data->timecreated = $this->apply_date_offset($data->timecreated);
00092         $data->timerendered = $this->apply_date_offset($data->timerendered);
00093 
00094         $newitemid = $DB->insert_record('wiki_pages', $data);
00095         $this->set_mapping('wiki_page', $oldid, $newitemid, true); // There are files related to this
00096     }
00097     protected function process_wiki_version($data) {
00098         global $DB;
00099 
00100         $data = (object)$data;
00101         $oldid = $data->id;
00102         $data->pageid = $this->get_new_parentid('wiki_page');
00103         $data->userid = $this->get_mappingid('user', $data->userid);
00104         $data->timecreated = $this->apply_date_offset($data->timecreated);
00105 
00106         $newitemid = $DB->insert_record('wiki_versions', $data);
00107         $this->set_mapping('wiki_version', $oldid, $newitemid);
00108     }
00109     protected function process_wiki_synonym($data) {
00110         global $DB;
00111 
00112         $data = (object)$data;
00113         $oldid = $data->id;
00114         $data->subwikiid = $this->get_new_parentid('wiki_subwiki');
00115         $data->pageid = $this->get_mappingid('wiki_page', $data->pageid);
00116 
00117         $newitemid = $DB->insert_record('wiki_synonyms', $data);
00118         // No need to save this mapping as far as nothing depend on it
00119         // (child paths, file areas nor links decoder)
00120     }
00121     protected function process_wiki_link($data) {
00122         global $DB;
00123 
00124         $data = (object)$data;
00125         $oldid = $data->id;
00126         $data->subwikiid = $this->get_new_parentid('wiki_subwiki');
00127         $data->frompageid = $this->get_mappingid('wiki_page', $data->frompageid);
00128         $data->topageid = $this->get_mappingid('wiki_page', $data->topageid);
00129 
00130         $newitemid = $DB->insert_record('wiki_links', $data);
00131         // No need to save this mapping as far as nothing depend on it
00132         // (child paths, file areas nor links decoder)
00133     }
00134 
00135     protected function process_wiki_tag($data) {
00136         global $CFG, $DB;
00137 
00138         $data = (object)$data;
00139         $oldid = $data->id;
00140 
00141         if (empty($CFG->usetags)) { // tags disabled in server, nothing to process
00142             return;
00143         }
00144 
00145         $tag = $data->rawname;
00146         $itemid = $this->get_new_parentid('wiki_page');
00147         tag_set_add('wiki_pages', $itemid, $tag);
00148     }
00149 
00150     protected function after_execute() {
00151         // Add wiki related files, no need to match by itemname (just internally handled context)
00152         $this->add_related_files('mod_wiki', 'intro', null);
00153         $this->add_related_files('mod_wiki', 'attachments', 'wiki_page');
00154     }
00155 }
 All Data Structures Namespaces Files Functions Variables Enumerations