MDL-64843 Backup: Course copy user interface

This patch adds better core support for copying courses.
There is now a simplified and dedicated UI for copying
courses. This can be accessed from the course context
menu or course management screens.

All backups are done asynchronously and there can be multiple
copies of a course in flight at once.
This commit is contained in:
Matt Porritt
2020-05-15 06:02:02 +00:00
parent 206e179df5
commit 01436f7539
40 changed files with 2868 additions and 73 deletions
+30 -2
View File
@@ -70,6 +70,12 @@ class backup_controller extends base_controller {
protected $checksum; // Cache @checksumable results for lighter @is_checksum_correct() uses
/**
* The role ids to keep in a copy operation.
* @var array
*/
protected $keptroles = array();
/**
* Constructor for the backup controller class.
*
@@ -97,7 +103,7 @@ class backup_controller extends base_controller {
$this->checksum = '';
// Set execution based on backup mode.
if ($mode == backup::MODE_ASYNC) {
if ($mode == backup::MODE_ASYNC || $mode == backup::MODE_COPY) {
$this->execution = backup::EXECUTION_DELAYED;
} else {
$this->execution = backup::EXECUTION_INMEDIATE;
@@ -291,7 +297,7 @@ class backup_controller extends base_controller {
// When a backup is intended for the same site, we don't need to include the files.
// Note, this setting is only used for duplication of an entire course.
if ($this->get_mode() === backup::MODE_SAMESITE) {
if ($this->get_mode() === backup::MODE_SAMESITE || $this->get_mode() === backup::MODE_COPY) {
$includefiles = false;
}
@@ -352,6 +358,22 @@ class backup_controller extends base_controller {
return $this->plan;
}
/**
* Sets the user roles that should be kept in the destination course
* for a course copy operation.
*
* @param array $roleids
* @throws backup_controller_exception
*/
public function set_kept_roles(array $roleids): void {
// Only allow of keeping user roles when controller is in copy mode.
if ($this->mode != backup::MODE_COPY) {
throw new backup_controller_exception('cannot_set_keep_roles_wrong_mode');
}
$this->keptroles = $roleids;
}
/**
* Executes the backup
* @return void Throws and exception of completes
@@ -379,6 +401,12 @@ class backup_controller extends base_controller {
$this->log('notifying plan about excluded activities by type', backup::LOG_DEBUG);
$this->plan->set_excluding_activities();
}
// Handle copy operation specific settings.
if ($this->mode == backup::MODE_COPY) {
$this->plan->set_kept_roles($this->keptroles);
}
return $this->plan->execute();
}