PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/backup/util/plan/restore_task.class.php

http://github.com/moodle/moodle
PHP | 124 lines | 68 code | 21 blank | 35 comment | 6 complexity | 95d2a1c1be7094c949f7c66849d9d53a MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * @package moodlecore
  18. * @subpackage backup-plan
  19. * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. /**
  23. * Abstract class defining the needed stuf for one restore task (a collection of steps)
  24. *
  25. * TODO: Finish phpdocs
  26. */
  27. abstract class restore_task extends base_task {
  28. /**
  29. * Constructor - instantiates one object of this class
  30. */
  31. public function __construct($name, $plan = null) {
  32. if (!is_null($plan) && !($plan instanceof restore_plan)) {
  33. throw new restore_task_exception('wrong_restore_plan_specified');
  34. }
  35. parent::__construct($name, $plan);
  36. }
  37. public function get_restoreid() {
  38. return $this->plan->get_restoreid();
  39. }
  40. public function get_info() {
  41. return $this->plan->get_info();
  42. }
  43. public function get_target() {
  44. return $this->plan->get_target();
  45. }
  46. public function get_userid() {
  47. return $this->plan->get_userid();
  48. }
  49. public function get_decoder() {
  50. return $this->plan->get_decoder();
  51. }
  52. public function is_samesite() {
  53. return $this->plan->is_samesite();
  54. }
  55. public function is_missing_modules() {
  56. return $this->plan->is_missing_modules();
  57. }
  58. public function is_excluding_activities() {
  59. return $this->plan->is_excluding_activities();
  60. }
  61. public function set_preloaded_information() {
  62. $this->plan->set_preloaded_information();
  63. }
  64. public function get_preloaded_information() {
  65. return $this->plan->get_preloaded_information();
  66. }
  67. public function get_tempdir() {
  68. return $this->plan->get_tempdir();
  69. }
  70. public function get_old_courseid() {
  71. return $this->plan->get_info()->original_course_id;
  72. }
  73. public function get_old_contextid() {
  74. return $this->plan->get_info()->original_course_contextid;
  75. }
  76. public function get_old_system_contextid() {
  77. return $this->plan->get_info()->original_system_contextid;
  78. }
  79. /**
  80. * If the task has been executed, launch its after_restore()
  81. * method if available
  82. */
  83. public function execute_after_restore() {
  84. if ($this->executed) {
  85. foreach ($this->steps as $step) {
  86. if (method_exists($step, 'launch_after_restore_methods')) {
  87. $step->launch_after_restore_methods();
  88. }
  89. }
  90. }
  91. if ($this->executed && method_exists($this, 'after_restore')) {
  92. $this->after_restore();
  93. }
  94. }
  95. }
  96. /*
  97. * Exception class used by all the @restore_task stuff
  98. */
  99. class restore_task_exception extends base_task_exception {
  100. public function __construct($errorcode, $a=NULL, $debuginfo=null) {
  101. parent::__construct($errorcode, $a, $debuginfo);
  102. }
  103. }