Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/data/backup/moodle2/restore_data_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_data_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('data', '/activity/data');
00040         $paths[] = new restore_path_element('data_field', '/activity/data/fields/field');
00041         if ($userinfo) {
00042             $paths[] = new restore_path_element('data_record', '/activity/data/records/record');
00043             $paths[] = new restore_path_element('data_content', '/activity/data/records/record/contents/content');
00044             $paths[] = new restore_path_element('data_rating', '/activity/data/records/record/ratings/rating');
00045         }
00046 
00047         // Return the paths wrapped into standard activity structure
00048         return $this->prepare_activity_structure($paths);
00049     }
00050 
00051     protected function process_data($data) {
00052         global $DB;
00053 
00054         $data = (object)$data;
00055         $oldid = $data->id;
00056         $data->course = $this->get_courseid();
00057 
00058         $data->timeavailablefrom = $this->apply_date_offset($data->timeavailablefrom);
00059         $data->timeavailableto = $this->apply_date_offset($data->timeavailableto);
00060         $data->timeviewfrom = $this->apply_date_offset($data->timeviewfrom);
00061         $data->timeviewto = $this->apply_date_offset($data->timeviewto);
00062         $data->assesstimestart = $this->apply_date_offset($data->assesstimestart);
00063         $data->assesstimefinish = $this->apply_date_offset($data->assesstimefinish);
00064 
00065         if ($data->scale < 0) { // scale found, get mapping
00066             $data->scale = -($this->get_mappingid('scale', abs($data->scale)));
00067         }
00068 
00069         // Some old backups can arrive with data->notification = null (MDL-24470)
00070         // convert them to proper column default (zero)
00071         if (is_null($data->notification)) {
00072             $data->notification = 0;
00073         }
00074 
00075         // insert the data record
00076         $newitemid = $DB->insert_record('data', $data);
00077         $this->apply_activity_instance($newitemid);
00078     }
00079 
00080     protected function process_data_field($data) {
00081         global $DB;
00082 
00083         $data = (object)$data;
00084         $oldid = $data->id;
00085 
00086         $data->dataid = $this->get_new_parentid('data');
00087 
00088         // insert the data_fields record
00089         $newitemid = $DB->insert_record('data_fields', $data);
00090         $this->set_mapping('data_field', $oldid, $newitemid, false); // no files associated
00091     }
00092 
00093     protected function process_data_record($data) {
00094         global $DB;
00095 
00096         $data = (object)$data;
00097         $oldid = $data->id;
00098 
00099         $data->timecreated = $this->apply_date_offset($data->timecreated);
00100         $data->timemodified = $this->apply_date_offset($data->timemodified);
00101 
00102         $data->userid = $this->get_mappingid('user', $data->userid);
00103         $data->groupid = $this->get_mappingid('group', $data->groupid);
00104         $data->dataid = $this->get_new_parentid('data');
00105 
00106         // insert the data_records record
00107         $newitemid = $DB->insert_record('data_records', $data);
00108         $this->set_mapping('data_record', $oldid, $newitemid, false); // no files associated
00109     }
00110 
00111     protected function process_data_content($data) {
00112         global $DB;
00113 
00114         $data = (object)$data;
00115         $oldid = $data->id;
00116 
00117         $data->fieldid = $this->get_mappingid('data_field', $data->fieldid);
00118         $data->recordid = $this->get_new_parentid('data_record');
00119 
00120         // insert the data_content record
00121         $newitemid = $DB->insert_record('data_content', $data);
00122         $this->set_mapping('data_content', $oldid, $newitemid, true); // files by this itemname
00123     }
00124 
00125     protected function process_data_rating($data) {
00126         global $DB;
00127 
00128         $data = (object)$data;
00129 
00130         // Cannot use ratings API, cause, it's missing the ability to specify times (modified/created)
00131         $data->contextid = $this->task->get_contextid();
00132         $data->itemid    = $this->get_new_parentid('data_record');
00133         if ($data->scaleid < 0) { // scale found, get mapping
00134             $data->scaleid = -($this->get_mappingid('scale', abs($data->scaleid)));
00135         }
00136         $data->rating = $data->value;
00137         $data->userid = $this->get_mappingid('user', $data->userid);
00138         $data->timecreated = $this->apply_date_offset($data->timecreated);
00139         $data->timemodified = $this->apply_date_offset($data->timemodified);
00140 
00141         // We need to check that component and ratingarea are both set here.
00142         if (empty($data->component)) {
00143             $data->component = 'mod_data';
00144         }
00145         if (empty($data->ratingarea)) {
00146             $data->ratingarea = 'entry';
00147         }
00148 
00149         $newitemid = $DB->insert_record('rating', $data);
00150     }
00151 
00152     protected function after_execute() {
00153         global $DB;
00154         // Add data related files, no need to match by itemname (just internally handled context)
00155         $this->add_related_files('mod_data', 'intro', null);
00156         // Add content related files, matching by itemname (data_content)
00157         $this->add_related_files('mod_data', 'content', 'data_content');
00158         // Adjust the data->defaultsort field
00159         if ($defaultsort = $DB->get_field('data', 'defaultsort', array('id' => $this->get_new_parentid('data')))) {
00160             if ($defaultsort = $this->get_mappingid('data_field', $defaultsort)) {
00161                 $DB->set_field('data', 'defaultsort', $defaultsort, array('id' => $this->get_new_parentid('data')));
00162             }
00163         }
00164     }
00165 }
 All Data Structures Namespaces Files Functions Variables Enumerations