MDL-21432 backup - plan/task/step basis
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?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-plan
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class defining the needed stuff to execute code on restore
|
||||
*
|
||||
* TODO: Finish phpdocs
|
||||
*/
|
||||
abstract class restore_execution_step extends restore_step {
|
||||
|
||||
public function execute() {
|
||||
// Simple, for now
|
||||
return $this->define_execution();
|
||||
}
|
||||
|
||||
// Protected API starts here
|
||||
|
||||
/**
|
||||
* Function that will contain all the code to be executed
|
||||
*/
|
||||
abstract protected function define_execution();
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?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-plan
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementable class defining the needed stuf for one restore plan
|
||||
*
|
||||
* TODO: Finish phpdocs
|
||||
*/
|
||||
class restore_plan extends base_plan implements loggable {
|
||||
|
||||
protected $controller; // The restore controller building/executing this plan
|
||||
protected $basepath; // Fullpath to dir where backup is available
|
||||
|
||||
/**
|
||||
* Constructor - instantiates one object of this class
|
||||
*/
|
||||
public function __construct($controller) {
|
||||
global $CFG;
|
||||
|
||||
if (! $controller instanceof restore_controller) {
|
||||
throw new restore_plan_exception('wrong_restore_controller_specified');
|
||||
}
|
||||
$this->controller = $controller;
|
||||
$this->basepath = $CFG->dataroot . '/temp/backup/' . $controller->get_restoreid();
|
||||
parent::__construct('restore_plan');
|
||||
}
|
||||
|
||||
public function build() {
|
||||
restore_plan_builder::build_plan($this->controller); // We are moodle2 always, go straight to builder
|
||||
$this->built = true;
|
||||
}
|
||||
|
||||
public function get_restoreid() {
|
||||
return $this->controller->get_restoreid();
|
||||
}
|
||||
|
||||
public function get_courseid() {
|
||||
return $this->controller->get_courseid();
|
||||
}
|
||||
|
||||
public function get_basepath() {
|
||||
return $this->basepath;
|
||||
}
|
||||
|
||||
public function get_logger() {
|
||||
return $this->controller->get_logger();
|
||||
}
|
||||
|
||||
public function log($message, $level, $a = null, $depth = null, $display = false) {
|
||||
backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
|
||||
}
|
||||
|
||||
/**
|
||||
* Function responsible for executing the tasks of any plan
|
||||
*/
|
||||
public function execute() {
|
||||
if ($this->controller->get_status() != backup::STATUS_AWAITING) {
|
||||
throw new restore_controller_exception('restore_not_executable_awaiting_required', $this->controller->get_status());
|
||||
}
|
||||
$this->controller->set_status(backup::STATUS_EXECUTING);
|
||||
parent::execute();
|
||||
$this->controller->set_status(backup::STATUS_FINISHED_OK);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Exception class used by all the @restore_plan stuff
|
||||
*/
|
||||
class restore_plan_exception extends base_plan_exception {
|
||||
|
||||
public function __construct($errorcode, $a=NULL, $debuginfo=null) {
|
||||
parent::__construct($errorcode, $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
@@ -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-plan
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class defining the needed stuf for one restore step
|
||||
*
|
||||
* TODO: Finish phpdocs
|
||||
*/
|
||||
abstract class restore_step extends base_step {
|
||||
|
||||
/**
|
||||
* Constructor - instantiates one object of this class
|
||||
*/
|
||||
public function __construct($name, $task = null) {
|
||||
if (!is_null($task) && !($task instanceof restore_task)) {
|
||||
throw new restore_step_exception('wrong_restore_task_specified');
|
||||
}
|
||||
parent::__construct($name, $task);
|
||||
}
|
||||
|
||||
protected function get_restoreid() {
|
||||
if (is_null($this->task)) {
|
||||
throw new restore_step_exception('not_specified_restore_task');
|
||||
}
|
||||
return $this->task->get_restoreid();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Exception class used by all the @restore_step stuff
|
||||
*/
|
||||
class restore_step_exception extends base_step_exception {
|
||||
|
||||
public function __construct($errorcode, $a=NULL, $debuginfo=null) {
|
||||
parent::__construct($errorcode, $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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-plan
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class defining the needed stuf for one restore task (a collection of steps)
|
||||
*
|
||||
* TODO: Finish phpdocs
|
||||
*/
|
||||
abstract class restore_task extends base_task {
|
||||
|
||||
/**
|
||||
* Constructor - instantiates one object of this class
|
||||
*/
|
||||
public function __construct($name, $plan = null) {
|
||||
if (!is_null($plan) && !($plan instanceof restore_plan)) {
|
||||
throw new restore_task_exception('wrong_restore_plan_specified');
|
||||
}
|
||||
parent::__construct($name, $plan);
|
||||
}
|
||||
|
||||
public function get_restoreid() {
|
||||
return $this->plan->get_restoreid();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Exception class used by all the @restore_task stuff
|
||||
*/
|
||||
class restore_task_exception extends base_task_exception {
|
||||
|
||||
public function __construct($errorcode, $a=NULL, $debuginfo=null) {
|
||||
parent::__construct($errorcode, $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user