MDL-28949 upgrade: Split course completion upgrade into smaller chunks

This commit is contained in:
Sam Hemelryk 2012-05-29 08:50:45 +12:00
parent bd633dda9a
commit e6f5528585
3 changed files with 32 additions and 18 deletions

View File

@ -686,42 +686,49 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2012052500.03);
}
/**
* Major clean up of course completion tables
*/
if ($oldversion < 2012052900.00) {
// Clean up all instances of duplicate records
// Add indexes to prevent new duplicates
// Clean up all duplicate records in the course_completions table in preparation
// for adding a new index there.
upgrade_course_completion_remove_duplicates(
'course_completions',
array('userid', 'course'),
array('timecompleted', 'timestarted', 'timeenrolled')
);
// Main savepoint reached
upgrade_main_savepoint(true, 2012052900.00);
}
if ($oldversion < 2012052900.01) {
// Add indexes to prevent new duplicates in the course_completions table.
// Define index useridcourse (unique) to be added to course_completions
$table = new xmldb_table('course_completions');
$index = new xmldb_index('useridcourse', XMLDB_INDEX_UNIQUE, array('userid', 'course'));
// Conditionally launch add index useridcourse
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012052900.00);
upgrade_main_savepoint(true, 2012052900.01);
}
if ($oldversion < 2012052900.01) {
if ($oldversion < 2012052900.02) {
// Clean up all duplicate records in the course_completion_crit_compl table in preparation
// for adding a new index there.
upgrade_course_completion_remove_duplicates(
'course_completion_crit_compl',
array('userid', 'course', 'criteriaid'),
array('timecompleted')
);
// Main savepoint reached
upgrade_main_savepoint(true, 2012052900.02);
}
if ($oldversion < 2012052900.03) {
// Add indexes to prevent new duplicates in the course_completion_crit_compl table.
// Define index useridcoursecriteraid (unique) to be added to course_completion_crit_compl
$table = new xmldb_table('course_completion_crit_compl');
$index = new xmldb_index('useridcoursecriteraid', XMLDB_INDEX_UNIQUE, array('userid', 'course', 'criteriaid'));
@ -732,16 +739,23 @@ function xmldb_main_upgrade($oldversion) {
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012052900.01);
upgrade_main_savepoint(true, 2012052900.03);
}
if ($oldversion < 2012052900.02) {
if ($oldversion < 2012052900.04) {
// Clean up all duplicate records in the course_completion_aggr_methd table in preparation
// for adding a new index there.
upgrade_course_completion_remove_duplicates(
'course_completion_aggr_methd',
array('course', 'criteriatype')
);
// Main savepoint reached
upgrade_main_savepoint(true, 2012052900.04);
}
if ($oldversion < 2012052900.05) {
// Add indexes to prevent new duplicates in the course_completion_aggr_methd table.
// Define index coursecriteratype (unique) to be added to course_completion_aggr_methd
$table = new xmldb_table('course_completion_aggr_methd');
$index = new xmldb_index('coursecriteriatype', XMLDB_INDEX_UNIQUE, array('course', 'criteriatype'));
@ -752,7 +766,7 @@ function xmldb_main_upgrade($oldversion) {
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012052900.02);
upgrade_main_savepoint(true, 2012052900.05);
}
return true;

View File

@ -1775,7 +1775,7 @@ function admin_mnet_method_profile(Zend_Server_Reflection_Function_Abstract $fun
*
* @param string $table Table name
* @param array $uniques Array of field names that should be unique
* @param array $feildstocheck Array of fields to generate "correct" data from (optional)
* @param array $fieldstocheck Array of fields to generate "correct" data from (optional)
* @return void
*/
function upgrade_course_completion_remove_duplicates($table, $uniques, $fieldstocheck = array()) {
@ -1792,7 +1792,7 @@ function upgrade_course_completion_remove_duplicates($table, $uniques, $fieldsto
$pointer = 0;
// Generate SQL for finding records with these duplicate uniques
$sql_select = implode(' = ? AND ', $uniques).' = ?'; /// builds "fieldname = ? AND fieldname = ?"
$sql_select = implode(' = ? AND ', $uniques).' = ?'; // builds "fieldname = ? AND fieldname = ?"
$uniq_values = array();
foreach ($uniques as $u) {
$uniq_values[] = $duplicate->$u;
@ -1831,7 +1831,7 @@ function upgrade_course_completion_remove_duplicates($table, $uniques, $fieldsto
}
}
if ($needsupdate || isset($origrecord->reaggregate)) {
// If this table has a reaggregate field, update to force recheck on next cron cron
// If this table has a reaggregate field, update to force recheck on next cron run
if (isset($origrecord->reaggregate)) {
$origrecord->reaggregate = time();
}

View File

@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2012052900.02; // YYYYMMDD = weekly release date of this DEV branch
$version = 2012052900.05; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes