diff --git a/backup/controller/backup_controller.class.php b/backup/controller/backup_controller.class.php index 1bab62be627..d6d7bd1d6a1 100644 --- a/backup/controller/backup_controller.class.php +++ b/backup/controller/backup_controller.class.php @@ -293,6 +293,14 @@ class backup_controller extends backup implements loggable { // Basic/initial prevention against time/memory limits set_time_limit(1 * 60 * 60); // 1 hour for 1 course initially granted raise_memory_limit(MEMORY_EXTRA); + // If this is not a course backup, inform the plan we are not + // including all the activities for sure. This will affect any + // task/step executed conditionally to stop including information + // for section and activity backup. MDL-28180. + if ($this->get_type() !== backup::TYPE_1COURSE) { + $this->log('notifying plan about excluded activities by type', backup::LOG_DEBUG); + $this->plan->set_excluding_activities(); + } return $this->plan->execute(); } diff --git a/backup/controller/restore_controller.class.php b/backup/controller/restore_controller.class.php index 50ec1027d02..680e6e9d95f 100644 --- a/backup/controller/restore_controller.class.php +++ b/backup/controller/restore_controller.class.php @@ -299,6 +299,14 @@ class restore_controller extends backup implements loggable { // Basic/initial prevention against time/memory limits set_time_limit(1 * 60 * 60); // 1 hour for 1 course initially granted raise_memory_limit(MEMORY_EXTRA); + // If this is not a course restore, inform the plan we are not + // including all the activities for sure. This will affect any + // task/step executed conditionally to stop processing information + // for section and activity restore. MDL-28180. + if ($this->get_type() !== backup::TYPE_1COURSE) { + $this->log('notifying plan about excluded activities by type', backup::LOG_DEBUG); + $this->plan->set_excluding_activities(); + } return $this->plan->execute(); } diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index f83b7c3752c..14d130afa3b 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -1805,15 +1805,20 @@ class restore_course_completion_structure_step extends restore_structure_step { $data->course = $this->get_courseid(); - $params = array( - 'course' => $data->course, - 'criteriatype' => $data->criteriatype, - 'method' => $data->method, - 'value' => $data->value, - ); - $DB->insert_record('course_completion_aggr_methd', $params); + // Only create the course_completion_aggr_methd records if + // the target course has not them defined. MDL-28180 + if (!$DB->record_exists('course_completion_aggr_methd', array( + 'course' => $data->course, + 'criteriatype' => $data->criteriatype))) { + $params = array( + 'course' => $data->course, + 'criteriatype' => $data->criteriatype, + 'method' => $data->method, + 'value' => $data->value, + ); + $DB->insert_record('course_completion_aggr_methd', $params); + } } - } diff --git a/backup/util/plan/backup_plan.class.php b/backup/util/plan/backup_plan.class.php index f21385cc5f4..bf217fd9c10 100644 --- a/backup/util/plan/backup_plan.class.php +++ b/backup/util/plan/backup_plan.class.php @@ -44,6 +44,7 @@ class backup_plan extends base_plan implements loggable { } $this->controller = $controller; $this->basepath = $CFG->tempdir . '/backup/' . $controller->get_backupid(); + $this->excludingdactivities = false; parent::__construct('backup_plan'); } diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index e540801aa49..a8a8f512f91 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6951,6 +6951,34 @@ FROM // Moodle v2.2.0 release upgrade line // Put any upgrade step following this + if ($oldversion < 2011120500.02) { + + upgrade_set_timeout(60*20); // This may take a while + // MDL-28180. Some missing restrictions in certain backup & restore operations + // were causing incorrect duplicates in the course_completion_aggr_methd table. + // This upgrade step takes rid of them. + $sql = 'SELECT course, criteriatype, MIN(id) AS minid + FROM {course_completion_aggr_methd} + GROUP BY course, criteriatype + HAVING COUNT(*) > 1'; + $duprs = $DB->get_recordset_sql($sql); + foreach ($duprs as $duprec) { + // We need to handle NULLs in criteriatype diferently + if (is_null($duprec->criteriatype)) { + $where = 'course = ? AND criteriatype IS NULL AND id > ?'; + $params = array($duprec->course, $duprec->minid); + } else { + $where = 'course = ? AND criteriatype = ? AND id > ?'; + $params = array($duprec->course, $duprec->criteriatype, $duprec->minid); + } + $DB->delete_records_select('course_completion_aggr_methd', $where, $params); + } + $duprs->close(); + + // Main savepoint reached + upgrade_main_savepoint(true, 2011120500.02); + } + return true; } diff --git a/version.php b/version.php index fcc0f57e4b7..86d0ad6aa9e 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2011120500.01; // 20111205 = branching date YYYYMMDD - do not modify! +$version = 2011120500.02; // 20111205 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches // .XX = incremental changes