mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-21432 backup - rest of helper files
This commit is contained in:
parent
c9d8234a9c
commit
fbc2778d1c
4 changed files with 256 additions and 0 deletions
58
backup/util/checks/restore_check.class.php
Normal file
58
backup/util/checks/restore_check.class.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package moodlecore
|
||||||
|
* @subpackage backup-factories
|
||||||
|
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non instantiable helper class providing different restore checks
|
||||||
|
*
|
||||||
|
* This class contains various static methods available in order to easily
|
||||||
|
* perform a bunch of restore architecture tests
|
||||||
|
*
|
||||||
|
* TODO: Finish phpdocs
|
||||||
|
*/
|
||||||
|
abstract class restore_check {
|
||||||
|
|
||||||
|
public static function check_courseid($courseid) {
|
||||||
|
global $DB;
|
||||||
|
// id must exist in course table
|
||||||
|
if (! $DB->record_exists('course', array('id' => $courseid))) {
|
||||||
|
throw new restore_controller_exception('restore_check_course_not_exists', $courseid);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function check_user($userid) {
|
||||||
|
global $DB;
|
||||||
|
// userid must exist in user table
|
||||||
|
if (! $DB->record_exists('user', array('id' => $userid))) {
|
||||||
|
throw new restore_controller_exception('restore_check_user_not_exists', $userid);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function check_security($restore_controller, $apply) {
|
||||||
|
|
||||||
|
debugging('TODO: Not applying security yet!', DEBUG_DEVELOPER); // TODO: Add once plan is complete
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
86
backup/util/dbops/restore_controller_dbops.class.php
Normal file
86
backup/util/dbops/restore_controller_dbops.class.php
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package moodlecore
|
||||||
|
* @subpackage backup-dbops
|
||||||
|
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non instantiable helper class providing DB support to the @restore_controller
|
||||||
|
*
|
||||||
|
* This class contains various static methods available for all the DB operations
|
||||||
|
* performed by the restore_controller class
|
||||||
|
*
|
||||||
|
* TODO: Finish phpdocs
|
||||||
|
*/
|
||||||
|
abstract class restore_controller_dbops extends restore_dbops {
|
||||||
|
|
||||||
|
public static function save_controller($controller, $checksum) {
|
||||||
|
global $DB;
|
||||||
|
// Check we are going to save one backup_controller
|
||||||
|
if (! $controller instanceof restore_controller) {
|
||||||
|
throw new backup_controller_exception('restore_controller_expected');
|
||||||
|
}
|
||||||
|
// Check checksum is ok. Sounds silly but it isn't ;-)
|
||||||
|
if (!$controller->is_checksum_correct($checksum)) {
|
||||||
|
throw new restore_dbops_exception('restore_controller_dbops_saving_checksum_mismatch');
|
||||||
|
}
|
||||||
|
// Get all the columns
|
||||||
|
$rec = new stdclass();
|
||||||
|
$rec->backupid = $controller->get_restoreid();
|
||||||
|
$rec->operation = $controller->get_operation();
|
||||||
|
$rec->type = $controller->get_type();
|
||||||
|
$rec->itemid = $controller->get_courseid();
|
||||||
|
$rec->format = $controller->get_format();
|
||||||
|
$rec->interactive = $controller->get_interactive();
|
||||||
|
$rec->purpose = $controller->get_mode();
|
||||||
|
$rec->userid = $controller->get_userid();
|
||||||
|
$rec->status = $controller->get_status();
|
||||||
|
$rec->execution = $controller->get_execution();
|
||||||
|
$rec->executiontime= $controller->get_executiontime();
|
||||||
|
$rec->checksum = $checksum;
|
||||||
|
// Serialize information
|
||||||
|
$rec->controller = base64_encode(serialize($controller));
|
||||||
|
// Send it to DB
|
||||||
|
if ($recexists = $DB->get_record('backup_controllers', array('backupid' => $rec->backupid))) {
|
||||||
|
$rec->id = $recexists->id;
|
||||||
|
$rec->timemodified = time();
|
||||||
|
$DB->update_record('backup_controllers', $rec);
|
||||||
|
} else {
|
||||||
|
$rec->timecreated = time();
|
||||||
|
$rec->timemodified = 0;
|
||||||
|
$rec->id = $DB->insert_record('backup_controllers', $rec);
|
||||||
|
}
|
||||||
|
return $rec->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function load_controller($restoreid) {
|
||||||
|
global $DB;
|
||||||
|
if (! $controllerrec = $DB->get_record('backup_controllers', array('backupid' => $restoreid))) {
|
||||||
|
throw new backup_dbops_exception('restore_controller_dbops_nonexisting');
|
||||||
|
}
|
||||||
|
$controller = unserialize(base64_decode($controllerrec->controller));
|
||||||
|
// Check checksum is ok. Sounds silly but it isn't ;-)
|
||||||
|
if (!$controller->is_checksum_correct($controllerrec->checksum)) {
|
||||||
|
throw new backup_dbops_exception('restore_controller_dbops_loading_checksum_mismatch');
|
||||||
|
}
|
||||||
|
return $controller;
|
||||||
|
}
|
||||||
|
}
|
40
backup/util/dbops/restore_dbops.class.php
Normal file
40
backup/util/dbops/restore_dbops.class.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package moodlecore
|
||||||
|
* @subpackage backup-dbops
|
||||||
|
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base abstract class for all the helper classes providing DB operations
|
||||||
|
*
|
||||||
|
* TODO: Finish phpdocs
|
||||||
|
*/
|
||||||
|
abstract class restore_dbops { }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Exception class used by all the @dbops stuff
|
||||||
|
*/
|
||||||
|
class restore_dbops_exception extends backup_exception {
|
||||||
|
|
||||||
|
public function __construct($errorcode, $a=NULL, $debuginfo=null) {
|
||||||
|
parent::__construct($errorcode, 'error', '', $a, null, $debuginfo);
|
||||||
|
}
|
||||||
|
}
|
72
backup/util/includes/restore_includes.php
Normal file
72
backup/util/includes/restore_includes.php
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package moodlecore
|
||||||
|
* @subpackage backup-includes
|
||||||
|
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Prevent direct access to this file
|
||||||
|
if (!defined('MOODLE_INTERNAL')) {
|
||||||
|
die('Direct access to this script is forbidden.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include all the backup needed stuff
|
||||||
|
require_once($CFG->dirroot . '/backup/util/interfaces/checksumable.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/interfaces/loggable.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/interfaces/executable.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/helper/restore_moodlexml_parser_processor.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/xml/parser/progressive_parser.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/backup.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/output/output_controller.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/dbops/backup_dbops.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/dbops/restore_dbops.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/dbops/backup_controller_dbops.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/dbops/restore_controller_dbops.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/checks/restore_check.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/loggers/base_logger.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/loggers/error_log_logger.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/loggers/file_logger.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/loggers/database_logger.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/loggers/output_indented_logger.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/factories/backup_factory.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/factories/restore_factory.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/helper/backup_helper.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/helper/backup_general_helper.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/settings/setting_dependency.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/settings/base_setting.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/settings/backup_setting.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/settings/root/root_backup_setting.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/settings/activity/activity_backup_setting.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/settings/section/section_backup_setting.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/settings/course/course_backup_setting.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/plan/base_plan.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/plan/restore_plan.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/plan/base_task.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/plan/restore_task.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/plan/base_step.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/plan/restore_step.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/plan/restore_execution_step.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/moodle2/restore_plan_builder.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/controller/restore_controller.class.php');
|
||||||
|
//require_once($CFG->dirroot . '/backup/util/ui/backup_ui.class.php');
|
||||||
|
//require_once($CFG->dirroot . '/backup/util/ui/backup_ui_stage.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/ui/backup_ui_setting.class.php');
|
||||||
|
|
||||||
|
// And some moodle stuff too
|
Loading…
Add table
Add a link
Reference in a new issue