$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() {
upgrade_main_savepoint(true, 2011110200.02);
}
+ if ($oldversion < 2011111500.01) {
+ // 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, 2011111500.01);
+ }
+
return true;
}
defined('MOODLE_INTERNAL') || die();
-$version = 2011111500.00; // YYYYMMDD = weekly release date of this DEV branch
+$version = 2011111500.01; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes