From 93759defcff625fb596be339df6f4a312c78788f Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 18 May 2007 09:20:52 +0000 Subject: [PATCH] MDL-9842 Groups from groupings not moved to "Not in a grouping"; merged from MOODLE_18_STABLE --- group/db/upgrade.php | 27 +++++++++++++++++++++++++++ lib/db/upgrade.php | 11 ++++++++++- version.php | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/group/db/upgrade.php b/group/db/upgrade.php index e338c435c7..b071675da6 100644 --- a/group/db/upgrade.php +++ b/group/db/upgrade.php @@ -48,6 +48,33 @@ function install_group_db() { notify(get_string('databaseupgradegroups', '', $group_version), 'green'); } +function undo_groupings() { + global $CFG; + + if (!$rs = get_recordset_sql(" + SELECT gpgs.courseid, ggs.groupid + FROM {$CFG->prefix}groups_courses_groupings gpgs, + {$CFG->prefix}groups_groupings_groups ggs + WHERE gpgs.groupingid = ggs.groupingid")) { + //strange - did we already remove the tables? + return; + } + + $db->debug = false; + if ($rs && $rs->RecordCount() > 0) { + while ($group = rs_fetch_next_record($rs)) { + if (!record_exists('groups_courses_groups', 'courseid', $group->courseid, 'groupid', $group->groupid)) { + insert_record('groups_courses_groups', $group); + } + } + } + $db->debug = true; + + delete_records('groups_courses_groupings'); + delete_records('groups_groupings_groups'); + delete_records('groups_groupings'); +} + function upgrade_group_db($continueto) { /// This function upgrades the group tables, if necessary diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index b25d330e66..f25f5b3509 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1270,7 +1270,16 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch add field signup $result = $result && add_field($table, $field); } - + + if ($result && $oldversion < 2007051101) { + if (empty($CFG->enablegroupings)) { + // delete all groupings - they do not work yet :-( + // while keeping all existing groups + require_once("$CFG->dirroot/group/db/upgrade.php"); + undo_groupings(); + } + } + return $result; } diff --git a/version.php b/version.php index b4532b92ed..ec0eff3525 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2007051100; // YYYYMMDD = date + $version = 2007051101; // YYYYMMDD = date // XY = increments within a single day $release = '1.9 dev'; // Human-friendly version name -- 2.39.5