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'));
}
// 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'));
}
// Main savepoint reached
- upgrade_main_savepoint(true, 2012052900.02);
+ upgrade_main_savepoint(true, 2012052900.05);
}
return true;
*
* @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()) {
$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;
}
}
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();
}