MDL-83479 backup: Add hooks to restore process.

- Place hooks inside backup/util/ui/classes/hooks, to be consistent with
other autoloaded classes.
This commit is contained in:
Jason Den Dulk
2025-02-13 11:41:45 +11:00
parent a5de02a54c
commit 7eb9cd0e8b
8 changed files with 83 additions and 208 deletions
@@ -1,44 +0,0 @@
<?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/>.
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;
}
}
@@ -1,43 +0,0 @@
<?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/>.
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;
}
}
@@ -1,49 +0,0 @@
<?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/>.
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;
}
}
@@ -1,51 +0,0 @@
<?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/>.
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;
}
}
@@ -14,20 +14,31 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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;
}
}
@@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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;
}
}
@@ -14,6 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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;
}
}
@@ -14,19 +14,38 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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;
}
}