Permalink
Browse files

MDL-32233 core_course_duplicate_course: Forcing backup and restore in…

… MODE_SAMESITE always as suggested by Eloy.
  • Loading branch information...
jleyva committed May 16, 2012
1 parent 6c7d3e3 commit d7f465d4976cdb6d0d1fd4d57604d766550dc17d
Showing with 16 additions and 30 deletions.
  1. +16 −30 course/externallib.php
View
@@ -729,16 +729,16 @@ public static function duplicate_course($courseid, $fullname, $shortname, $categ
self::validate_context($coursecontext);
$backupdefaults = array(
'activities' => 1,
'blocks' => 1,
'filters' => 1,
'users' => 0,
'role_assignments' => 0,
'user_files' => 0,
'comments' => 0,
'completion_information' => 0,
'logs' => 0,
'histories' => 0
'activities' => 1,
'blocks' => 1,
'filters' => 1,
'users' => 0,
'role_assignments' => 0,
'user_files' => 0,
'comments' => 0,
'completion_information' => 0,
'logs' => 0,
'histories' => 0
);
$backupsettings = array();
@@ -766,10 +766,7 @@ public static function duplicate_course($courseid, $fullname, $shortname, $categ
// The backup controller check for this currently, this may be redundant.
require_capability('moodle/course:create', $categorycontext);
require_capability('moodle/restore:restorecourse', $categorycontext);
require_capability('moodle/restore:restoretargetimport', $categorycontext);
require_capability('moodle/backup:backupcourse', $coursecontext);
require_capability('moodle/backup:backuptargetimport', $coursecontext);
if (!empty($backupsettings['users'])) {
require_capability('moodle/backup:userinfo', $coursecontext);
@@ -787,14 +784,9 @@ public static function duplicate_course($courseid, $fullname, $shortname, $categ
}
// Backup the course.
if (!empty($backupsettings['users'])) {
$mode = backup::MODE_SAMESITE;
} else {
$mode = backup::MODE_IMPORT;
}
$bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE,
backup::INTERACTIVE_NO, $mode, $USER->id);
backup::INTERACTIVE_NO, backup::MODE_SAMESITE, $USER->id);
foreach ($backupsettings as $name => $value) {
$bc->get_plan()->get_setting($name)->set_value($value);
@@ -805,27 +797,22 @@ public static function duplicate_course($courseid, $fullname, $shortname, $categ
$bc->execute_plan();
$results = $bc->get_results();
if (!empty($results['backup_destination'])) {
$file = $results['backup_destination'];
} else {
$file = null;
}
$file = $results['backup_destination'];
$bc->destroy();
// Restore the backup immediately.
// Check if we need to unzip the file because the backup temp dir does not contains backup files.
if ($file and !file_exists($backupbasepath . "/moodle_backup.xml")) {
if (!file_exists($backupbasepath . "/moodle_backup.xml")) {
$file->extract_to_pathname(get_file_packer(), $backupbasepath);
}
// Create new course.
$newcourseid = restore_dbops::create_new_course($params['fullname'], $params['shortname'], $params['categoryid']);
$rc = new restore_controller($backupid, $newcourseid,
backup::INTERACTIVE_NO, $mode, $USER->id, backup::TARGET_NEW_COURSE);
backup::INTERACTIVE_NO, backup::MODE_SAMESITE, $USER->id, backup::TARGET_NEW_COURSE);
foreach ($backupsettings as $name => $value) {
$setting = $rc->get_plan()->get_setting($name);
@@ -872,9 +859,8 @@ public static function duplicate_course($courseid, $fullname, $shortname, $categ
fulldelete($backupbasepath);
}
if ($file) {
$file->delete();
}
// Delete the course backup file created by this WebService. Originally located in the course backups area.
$file->delete();
return array('id' => $course->id, 'shortname' => $course->shortname);
}

0 comments on commit d7f465d

Please sign in to comment.