Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/dbops/restore_controller_dbops.class.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 
00033 abstract class restore_controller_dbops extends restore_dbops {
00034 
00035     public static function save_controller($controller, $checksum) {
00036         global $DB;
00037         // Check we are going to save one backup_controller
00038         if (! $controller instanceof restore_controller) {
00039             throw new backup_controller_exception('restore_controller_expected');
00040         }
00041         // Check checksum is ok. Sounds silly but it isn't ;-)
00042         if (!$controller->is_checksum_correct($checksum)) {
00043             throw new restore_dbops_exception('restore_controller_dbops_saving_checksum_mismatch');
00044         }
00045         // Get all the columns
00046         $rec = new stdclass();
00047         $rec->backupid     = $controller->get_restoreid();
00048         $rec->operation    = $controller->get_operation();
00049         $rec->type         = $controller->get_type();
00050         $rec->itemid       = $controller->get_courseid();
00051         $rec->format       = $controller->get_format();
00052         $rec->interactive  = $controller->get_interactive();
00053         $rec->purpose      = $controller->get_mode();
00054         $rec->userid       = $controller->get_userid();
00055         $rec->status       = $controller->get_status();
00056         $rec->execution    = $controller->get_execution();
00057         $rec->executiontime= $controller->get_executiontime();
00058         $rec->checksum     = $checksum;
00059         // Serialize information
00060         $rec->controller = base64_encode(serialize($controller));
00061         // Send it to DB
00062         if ($recexists = $DB->get_record('backup_controllers', array('backupid' => $rec->backupid))) {
00063             $rec->id = $recexists->id;
00064             $rec->timemodified = time();
00065             $DB->update_record('backup_controllers', $rec);
00066         } else {
00067             $rec->timecreated = time();
00068             $rec->timemodified = 0;
00069             $rec->id = $DB->insert_record('backup_controllers', $rec);
00070         }
00071         return $rec->id;
00072     }
00073 
00074     public static function load_controller($restoreid) {
00075         global $DB;
00076         if (! $controllerrec = $DB->get_record('backup_controllers', array('backupid' => $restoreid))) {
00077             throw new backup_dbops_exception('restore_controller_dbops_nonexisting');
00078         }
00079         $controller = unserialize(base64_decode($controllerrec->controller));
00080         // Check checksum is ok. Sounds silly but it isn't ;-)
00081         if (!$controller->is_checksum_correct($controllerrec->checksum)) {
00082             throw new backup_dbops_exception('restore_controller_dbops_loading_checksum_mismatch');
00083         }
00084         return $controller;
00085     }
00086 
00087     public static function create_restore_temp_tables($restoreid) {
00088         global $CFG, $DB;
00089         $dbman = $DB->get_manager(); // We are going to use database_manager services
00090 
00091         if ($dbman->table_exists('backup_ids_temp')) { // Table exists, from restore prechecks
00092             // TODO: Improve this by inserting/selecting some record to see there is restoreid match
00093             // TODO: If not match, exception, table corresponds to another backup/restore operation
00094             return true;
00095         }
00096         backup_controller_dbops::create_temptable_from_real_table($restoreid, 'backup_ids_template', 'backup_ids_temp');
00097         backup_controller_dbops::create_temptable_from_real_table($restoreid, 'backup_files_template', 'backup_files_temp');
00098         return false;
00099     }
00100 
00101     public static function drop_restore_temp_tables($backupid) {
00102         global $DB;
00103         $dbman = $DB->get_manager(); // We are going to use database_manager services
00104 
00105         $targettablenames = array('backup_ids_temp', 'backup_files_temp');
00106         foreach ($targettablenames as $targettablename) {
00107             $table = new xmldb_table($targettablename);
00108             $dbman->drop_temp_table($table); // And drop it
00109         }
00110     }
00111 }
 All Data Structures Namespaces Files Functions Variables Enumerations