diff --git a/backup/util/plan/restore_execution_step.class.php b/backup/util/plan/restore_execution_step.class.php new file mode 100644 index 00000000000..811c07ba08f --- /dev/null +++ b/backup/util/plan/restore_execution_step.class.php @@ -0,0 +1,43 @@ +. + +/** + * @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(); +} diff --git a/backup/util/plan/restore_plan.class.php b/backup/util/plan/restore_plan.class.php new file mode 100644 index 00000000000..3aa35188a69 --- /dev/null +++ b/backup/util/plan/restore_plan.class.php @@ -0,0 +1,95 @@ +. + +/** + * @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); + } +} diff --git a/backup/util/plan/restore_step.class.php b/backup/util/plan/restore_step.class.php new file mode 100644 index 00000000000..29b2734d985 --- /dev/null +++ b/backup/util/plan/restore_step.class.php @@ -0,0 +1,58 @@ +. + +/** + * @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); + } +} diff --git a/backup/util/plan/restore_task.class.php b/backup/util/plan/restore_task.class.php new file mode 100644 index 00000000000..46e40736849 --- /dev/null +++ b/backup/util/plan/restore_task.class.php @@ -0,0 +1,55 @@ +. + +/** + * @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); + } +}