Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-29350 Prevent duplication of groupings when copying activities

This patch also includes a database upgrade to correct data produced as a
result of this bug.
  • Loading branch information...
commit 3815ecf471f92059db29e21809a3c8c918c25c9b 1 parent e25ecdf
@bostelm bostelm authored andrewnicols committed
View
9 backup/moodle2/restore_stepslib.php
@@ -802,7 +802,14 @@ public function process_grouping_group($data) {
$data->groupingid = $this->get_new_parentid('grouping'); // Use new parentid
$data->groupid = $this->get_mappingid('group', $data->groupid); // Get from mappings
- $DB->insert_record('groupings_groups', $data); // No need to set this mapping (no child info nor files)
+
+ $params = array();
+ $params['groupingid'] = $data->groupingid;
+ $params['groupid'] = $data->groupid;
+
+ if (!$DB->record_exists('groupings_groups', $params)) {
+ $DB->insert_record('groupings_groups', $data); // No need to set this mapping (no child info nor files)
+ }
}
protected function after_execute() {
View
15 lib/db/upgrade.php
@@ -6679,6 +6679,21 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011070101.10);
}
+ if ($oldversion < 2011070102.08) {
+ // Remove duplicate entries from groupings_groups table
+ $sql = 'SELECT MIN(id) AS firstid, groupingid, groupid FROM {groupings_groups} '.
+ 'GROUP BY groupingid, groupid HAVING COUNT(id)>1';
+ $badrecs = $DB->get_records_sql($sql);
+ foreach ($badrecs as $badrec) {
+ $where = 'groupingid = ? and groupid = ? and id > ?';
+ $params = array($badrec->groupingid, $badrec->groupid, $badrec->firstid);
+ $DB->delete_records_select('groupings_groups', $where, $params);
+ }
+
+ // Main savepoint reached
+ upgrade_main_savepoint(true, 2011070102.08);
+ }
+
return true;
}
View
3  version.php
@@ -30,8 +30,7 @@
defined('MOODLE_INTERNAL') || die();
-
-$version = 2011070102.07; // 20110701 = branching date YYYYMMDD - do not modify!
+$version = 2011070102.08; // 20110701 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches
// .XX = incremental changes
Please sign in to comment.
Something went wrong with that request. Please try again.