From e6f55285852d7dd7dd669578934c5d5b0f7e6557 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Tue, 29 May 2012 08:50:45 +1200 Subject: [PATCH] MDL-28949 upgrade: Split course completion upgrade into smaller chunks --- lib/db/upgrade.php | 42 ++++++++++++++++++++++++++++-------------- lib/upgradelib.php | 6 +++--- version.php | 2 +- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index f50502386b5..ba53f99374e 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; diff --git a/lib/upgradelib.php b/lib/upgradelib.php index ff87f9a2cf0..aa6ee8f6c3f 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -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(); } diff --git a/version.php b/version.php index c7e462d74fe..dd7484cfbb0 100644 --- a/version.php +++ b/version.php @@ -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 -- 2.43.0