From 7eb9cd0e8b2fae9d1d1947ad4c1d5f41878d24fe Mon Sep 17 00:00:00 2001 From: Jason Den Dulk Date: Mon, 16 Dec 2024 09:38:39 +1100 Subject: [PATCH] MDL-83479 backup: Add hooks to restore process. - Place hooks inside backup/util/ui/classes/hooks, to be consistent with other autoloaded classes. --- .../hook/after_copy_form_definition.php | 44 ---------------- .../after_restore_root_define_settings.php | 43 ---------------- .../hook/before_copy_course_execute.php | 49 ------------------ .../hook/copy_helper_process_formdata.php | 51 ------------------- .../hook/after_copy_form_definition.php | 25 ++++++--- .../after_restore_root_define_settings.php | 23 +++++++-- .../hook/before_copy_course_execute.php | 27 ++++++++-- .../hook/copy_helper_process_formdata.php | 29 +++++++++-- 8 files changed, 83 insertions(+), 208 deletions(-) delete mode 100644 backup/classes/hook/after_copy_form_definition.php delete mode 100644 backup/classes/hook/after_restore_root_define_settings.php delete mode 100644 backup/classes/hook/before_copy_course_execute.php delete mode 100644 backup/classes/hook/copy_helper_process_formdata.php diff --git a/backup/classes/hook/after_copy_form_definition.php b/backup/classes/hook/after_copy_form_definition.php deleted file mode 100644 index e2b57768acc..00000000000 --- a/backup/classes/hook/after_copy_form_definition.php +++ /dev/null @@ -1,44 +0,0 @@ -. - -namespace core_backup\hook; - -use MoodleQuickForm; - -/** - * Hook to allow adding extra fields to the copy course form. - * This should be used together with core_backup\hook\copy_helper_process_formdata - * - * @package core_backup - * @copyright 2024 Monash University (https://www.monash.edu) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -#[\core\attribute\label('Use to add extra elements to the copy course form.')] -#[\core\attribute\tags('backup')] -final class after_copy_form_definition { - - /** @var MoodleQuickForm */ - public readonly MoodleQuickForm $mform; - - /** - * Constructor. - * - * @param MoodleQuickForm $mform - */ - public function __construct(MoodleQuickForm $mform) { - $this->mform = $mform; - } -} diff --git a/backup/classes/hook/after_restore_root_define_settings.php b/backup/classes/hook/after_restore_root_define_settings.php deleted file mode 100644 index 04b7c9ba522..00000000000 --- a/backup/classes/hook/after_restore_root_define_settings.php +++ /dev/null @@ -1,43 +0,0 @@ -. - -namespace core_backup\hook; - -use restore_root_task; - -/** - * Hook to allow extra settings to be defined for the course restore process. - * - * @package core_backup - * @copyright 2024 Monash University (https://www.monash.edu) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -#[\core\attribute\label('Use to add extra elements to the settings tab of the restore process.')] -#[\core\attribute\tags('backup')] -final class after_restore_root_define_settings { - - /** @var restore_root_task */ - public readonly restore_root_task $task; - - /** - * Constructor. - * - * @param restore_root_task $task - */ - public function __construct(restore_root_task $task) { - $this->task = $task; - } -} diff --git a/backup/classes/hook/before_copy_course_execute.php b/backup/classes/hook/before_copy_course_execute.php deleted file mode 100644 index 9930351b4e6..00000000000 --- a/backup/classes/hook/before_copy_course_execute.php +++ /dev/null @@ -1,49 +0,0 @@ -. - -namespace core_backup\hook; - -use stdClass; -use restore_plan; - -/** - * Hook used to allow interaction with the copy task, before the actual task execution takes place. - * - * @package core_backup - * @copyright 2024 Monash University (https://www.monash.edu) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -#[\core\attribute\label('Use to interact with the copy course task before the actual execution takes place.')] -#[\core\attribute\tags('backup')] -final class before_copy_course_execute { - - /** @var restore_plan */ - public readonly restore_plan $plan; - - /** @var stdClass */ - public readonly stdClass $copyinfo; - - /** - * Hook constructor. - * - * @param restore_plan $plan - * @param stdClass $copyinfo - */ - public function __construct(restore_plan $plan, stdClass $copyinfo) { - $this->plan = $plan; - $this->copyinfo = $copyinfo; - } -} diff --git a/backup/classes/hook/copy_helper_process_formdata.php b/backup/classes/hook/copy_helper_process_formdata.php deleted file mode 100644 index 84cec9f7ea0..00000000000 --- a/backup/classes/hook/copy_helper_process_formdata.php +++ /dev/null @@ -1,51 +0,0 @@ -. - -namespace core_backup\hook; - -/** - * Hook used by copy_helper::process_formdata() to expand the list of required fields. - * This should be used together with core_backup\hook\after_copy_form_definition. - * - * @package core_backup - * @copyright 2024 Monash University (https://www.monash.edu) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -#[\core\attribute\label('Able to add extra fields to the copy course.')] -#[\core\attribute\tags('backup')] -final class copy_helper_process_formdata { - - /** @var array List of extra fields to be added. */ - protected $extrafields = []; - - /** - * Add an extra field. - * - * @param string $extrafield - */ - public function add_extra_field(string $extrafield) { - $this->extrafields[] = $extrafield; - } - - /** - * Get the extra fields. - * - * @return array - */ - public function get_extrafields(): array { - return $this->extrafields; - } -} diff --git a/backup/util/ui/classes/hook/after_copy_form_definition.php b/backup/util/ui/classes/hook/after_copy_form_definition.php index d7a2bf6be49..e2b57768acc 100644 --- a/backup/util/ui/classes/hook/after_copy_form_definition.php +++ b/backup/util/ui/classes/hook/after_copy_form_definition.php @@ -14,20 +14,31 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core_backup\hook; + +use MoodleQuickForm; + /** * Hook to allow adding extra fields to the copy course form. - * * This should be used together with core_backup\hook\copy_helper_process_formdata * * @package core_backup * @copyright 2024 Monash University (https://www.monash.edu) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +#[\core\attribute\label('Use to add extra elements to the copy course form.')] +#[\core\attribute\tags('backup')] +final class after_copy_form_definition { -namespace core_backup\hook; - -defined('MOODLE_INTERNAL') || die(); - -// This file is a placeholder. Remove when MDL-83618 is available. -require_once(__DIR__.'/../../../../classes/hook/after_copy_form_definition.php'); + /** @var MoodleQuickForm */ + public readonly MoodleQuickForm $mform; + /** + * Constructor. + * + * @param MoodleQuickForm $mform + */ + public function __construct(MoodleQuickForm $mform) { + $this->mform = $mform; + } +} diff --git a/backup/util/ui/classes/hook/after_restore_root_define_settings.php b/backup/util/ui/classes/hook/after_restore_root_define_settings.php index 382b33495aa..04b7c9ba522 100644 --- a/backup/util/ui/classes/hook/after_restore_root_define_settings.php +++ b/backup/util/ui/classes/hook/after_restore_root_define_settings.php @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core_backup\hook; + +use restore_root_task; + /** * Hook to allow extra settings to be defined for the course restore process. * @@ -21,10 +25,19 @@ * @copyright 2024 Monash University (https://www.monash.edu) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +#[\core\attribute\label('Use to add extra elements to the settings tab of the restore process.')] +#[\core\attribute\tags('backup')] +final class after_restore_root_define_settings { -namespace core_backup\hook; + /** @var restore_root_task */ + public readonly restore_root_task $task; -defined('MOODLE_INTERNAL') || die(); - -// This file is a placeholder. Remove when MDL-83618 is available. -require_once(__DIR__.'/../../../../classes/hook/after_restore_root_define_settings.php'); + /** + * Constructor. + * + * @param restore_root_task $task + */ + public function __construct(restore_root_task $task) { + $this->task = $task; + } +} diff --git a/backup/util/ui/classes/hook/before_copy_course_execute.php b/backup/util/ui/classes/hook/before_copy_course_execute.php index 5f90bc0e1c1..9930351b4e6 100644 --- a/backup/util/ui/classes/hook/before_copy_course_execute.php +++ b/backup/util/ui/classes/hook/before_copy_course_execute.php @@ -14,6 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core_backup\hook; + +use stdClass; +use restore_plan; + /** * Hook used to allow interaction with the copy task, before the actual task execution takes place. * @@ -21,10 +26,24 @@ * @copyright 2024 Monash University (https://www.monash.edu) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +#[\core\attribute\label('Use to interact with the copy course task before the actual execution takes place.')] +#[\core\attribute\tags('backup')] +final class before_copy_course_execute { -namespace core_backup\hook; + /** @var restore_plan */ + public readonly restore_plan $plan; -defined('MOODLE_INTERNAL') || die(); + /** @var stdClass */ + public readonly stdClass $copyinfo; -// This file is a placeholder. Remove when MDL-83618 is available. -require_once(__DIR__.'/../../../../classes/hook/before_copy_course_execute.php'); + /** + * Hook constructor. + * + * @param restore_plan $plan + * @param stdClass $copyinfo + */ + public function __construct(restore_plan $plan, stdClass $copyinfo) { + $this->plan = $plan; + $this->copyinfo = $copyinfo; + } +} diff --git a/backup/util/ui/classes/hook/copy_helper_process_formdata.php b/backup/util/ui/classes/hook/copy_helper_process_formdata.php index fea46a992c5..84cec9f7ea0 100644 --- a/backup/util/ui/classes/hook/copy_helper_process_formdata.php +++ b/backup/util/ui/classes/hook/copy_helper_process_formdata.php @@ -14,19 +14,38 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core_backup\hook; + /** * Hook used by copy_helper::process_formdata() to expand the list of required fields. - * * This should be used together with core_backup\hook\after_copy_form_definition. * * @package core_backup * @copyright 2024 Monash University (https://www.monash.edu) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +#[\core\attribute\label('Able to add extra fields to the copy course.')] +#[\core\attribute\tags('backup')] +final class copy_helper_process_formdata { -namespace core_backup\hook; + /** @var array List of extra fields to be added. */ + protected $extrafields = []; -defined('MOODLE_INTERNAL') || die(); + /** + * Add an extra field. + * + * @param string $extrafield + */ + public function add_extra_field(string $extrafield) { + $this->extrafields[] = $extrafield; + } -// This file is a placeholder. Remove when MDL-83618 is available. -require_once(__DIR__.'/../../../../classes/hook/copy_helper_process_formdata.php'); + /** + * Get the extra fields. + * + * @return array + */ + public function get_extrafields(): array { + return $this->extrafields; + } +}