Skip to content

Commit

Permalink
MDL-74548 backup: Deprecate core_backup\copy\copy
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron1729 committed Jun 29, 2022
1 parent bc9c536 commit 07e5f43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 93 deletions.
5 changes: 5 additions & 0 deletions backup/upgrade.txt
@@ -1,6 +1,11 @@
This files describes API changes in /backup/*,
information provided here is intended especially for developers.

=== 4.1 ===

* The class core_backup\copy\copy in backup/util/ui/classes/copy.php has been deprecated, please use copy_helper
from backup/util/helper/copy_helper.class.php instead.

=== 4.0 ===

* Backup UI labels now accept empty/whitespace-only contents.
Expand Down
110 changes: 17 additions & 93 deletions backup/util/ui/classes/copy/copy.php
Expand Up @@ -24,6 +24,7 @@
* @copyright 2020 onward The Moodle Users Association <https://moodleassociation.org/>
* @author Matt Porritt <mattp@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since Moodle 4.1. Use copy_helper instead
*/

namespace core_backup\copy;
Expand All @@ -44,8 +45,11 @@
* @copyright 2020 onward The Moodle Users Association <https://moodleassociation.org/>
* @author Matt Porritt <mattp@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since Moodle 4.1 MDL-74548 - please use copy_helper instead
* @todo MDL-75022 This class will be deleted in Moodle 4.5
* @see copy_helper
*/
class copy {
class copy {

/**
* The fields required for copy operations.
Expand Down Expand Up @@ -84,6 +88,7 @@ class copy {
* @param \stdClass $formdata Data from the validated course copy form.
*/
public function __construct(\stdClass $formdata) {
debugging('Class \course_backup\copy\copy is deprecated. Please use the copy_helper class instead.');
$this->copydata = $this->get_copy_data($formdata);
$this->roles = $this->get_enrollment_roles($formdata);
}
Expand Down Expand Up @@ -133,6 +138,10 @@ private function get_copy_data(\stdClass $formdata): \stdClass {
* Sets up relevant controllers and adhoc task.
*
* @return array $copyids THe backup and restore controller ids.
* @deprecated since Moodle 4.1 MDL-74548 - please use copy_helper instead.
* @todo MDL-75023 This method will be deleted in Moodle 4.5
* @see copy_helper::process_formdata()
* @see copy_helper::create_copy()
*/
public function create_copy(): array {
debugging('The method \core_backup\copy\copy::create_copy() is deprecated.
Expand All @@ -148,99 +157,14 @@ public function create_copy(): array {
* @param int $userid User id to get the course copies for.
* @param int $courseid The optional source course id to get copies for.
* @return array $copies Details of the inprogress copies.
* @deprecated since Moodle 4.1 MDL-74548 - please use copy_helper::get_copies() instead.
* @todo MDL-75024 This method will be deleted in Moodle 4.5
* @see copy_helper::get_copies()
*/
static public function get_copies(int $userid, int $courseid=0): array {
global $DB;
$copies = array();
$params = array($userid, \backup::EXECUTION_DELAYED, \backup::MODE_COPY);
$sql = 'SELECT bc.backupid, bc.itemid, bc.operation, bc.status, bc.timecreated
FROM {backup_controllers} bc
INNER JOIN {course} c ON bc.itemid = c.id
WHERE bc.userid = ?
AND bc.execution = ?
AND bc.purpose = ?
ORDER BY bc.timecreated DESC';

$copyrecords = $DB->get_records_sql($sql, $params);

foreach ($copyrecords as $copyrecord) {
$copy = new \stdClass();
$copy->itemid = $copyrecord->itemid;
$copy->time = $copyrecord->timecreated;
$copy->operation = $copyrecord->operation;
$copy->status = $copyrecord->status;
$copy->backupid = null;
$copy->restoreid = null;

if ($copyrecord->operation == \backup::OPERATION_RESTORE) {
$copy->restoreid = $copyrecord->backupid;
// If record is complete or complete with errors, it means the backup also completed.
// It also means there are no controllers. In this case just skip and move on.
if ($copyrecord->status == \backup::STATUS_FINISHED_OK
|| $copyrecord->status == \backup::STATUS_FINISHED_ERR) {
continue;
} else if ($copyrecord->status > \backup::STATUS_REQUIRE_CONV) {
// If record is a restore and it's in progress (>200), it means the backup is finished.
// In this case return the restore.
$rc = \restore_controller::load_controller($copyrecord->backupid);
$course = get_course($rc->get_copy()->courseid);

$copy->source = $course->shortname;
$copy->sourceid = $course->id;
$copy->destination = $rc->get_copy()->shortname;
$copy->backupid = $rc->get_copy()->copyids['backupid'];
$rc->destroy();

} else if ($copyrecord->status == \backup::STATUS_REQUIRE_CONV) {
// If record is a restore and it is waiting (=200), load the controller
// and check the status of the backup.
// If the backup has finished successfully we have and edge case. Process as per in progress restore.
// If the backup has any other code it will be handled by backup processing.
$rc = \restore_controller::load_controller($copyrecord->backupid);
$bcid = $rc->get_copy()->copyids['backupid'];
if (empty($copyrecords[$bcid])) {
continue;
}
$backuprecord = $copyrecords[$bcid];
$backupstatus = $backuprecord->status;
if ($backupstatus == \backup::STATUS_FINISHED_OK) {
$course = get_course($rc->get_copy()->courseid);

$copy->source = $course->shortname;
$copy->sourceid = $course->id;
$copy->destination = $rc->get_copy()->shortname;
$copy->backupid = $rc->get_copy()->copyids['backupid'];
} else {
continue;
}
}
} else { // Record is a backup.
$copy->backupid = $copyrecord->backupid;
if ($copyrecord->status == \backup::STATUS_FINISHED_OK
|| $copyrecord->status == \backup::STATUS_FINISHED_ERR) {
// If successfully finished then skip it. Restore procesing will look after it.
// If it has errored then we can't go any further.
continue;
} else {
// If is in progress then process it.
$bc = \backup_controller::load_controller($copyrecord->backupid);
$course = get_course($bc->get_courseid());

$copy->source = $course->shortname;
$copy->sourceid = $course->id;
$copy->destination = $bc->get_copy()->shortname;
$copy->restoreid = $bc->get_copy()->copyids['restoreid'];
}
}

$copies[] = $copy;
}

// Extra processing to filter records for a given course.
if ($courseid != 0 ) {
$copies = self::filter_copies_course($copies, $courseid);
}
public static function get_copies(int $userid, int $courseid=0): array {
debugging('The method \core_backup\copy\copy::get_copies() is deprecated.
Please use copy_helper::get_copies() instead.', DEBUG_DEVELOPER);

return $copies;
return \copy_helper::get_copies($userid, $coursied);
}
}

0 comments on commit 07e5f43

Please sign in to comment.