Commit 711f4f0e authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1600126: Using shortname as identifier of group



Rather than shortname/institution pair

Need to fix up how mysqli checks for index when table name
is reserved word

behatnotneeded - existing test should be ok

Change-Id: I62e776a5497671f9455929a21d279f76cf3f4345
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 19cbae54
......@@ -174,7 +174,7 @@ function uploadcsv_validate(Pieform $form, $values) {
}
else if ($values['updategroups']) {
// The groupname needs to exist
if (!record_exists('group', 'shortname', $shortname, 'institution', $institution)) {
if (!record_exists('group', 'shortname', $shortname)) {
$csverrors->add($i, get_string('uploadgroupcsverrorshortnamemissing', 'admin', $i, $shortname));
}
}
......@@ -197,15 +197,14 @@ function uploadcsv_validate(Pieform $form, $values) {
}
}
else {
// This displayname must be new if not our shortname/institution
// This displayname must be new if not tied to our shortname
if (get_records_sql_array('
SELECT id FROM {group}
WHERE LOWER(TRIM(name)) = ?
AND NOT (shortname = ? AND institution = ?)',
AND NOT (shortname = ?)',
array(
strtolower(trim($displayname)),
$shortname,
$institution
$shortname
))) {
$csverrors->add($i, get_string('uploadgroupcsverrordisplaynamealreadyexists', 'admin', $i, $displayname));
}
......
......@@ -345,7 +345,7 @@ class ADODB_mysqli extends ADOConnection {
}
// get index details
$rs = $this->Execute(sprintf('SHOW INDEXES FROM %s',$table));
$rs = $this->Execute(sprintf('SHOW INDEXES FROM `%s`',$table));
// restore fetchmode
if (isset($savem)) {
......
......@@ -4790,5 +4790,34 @@ function xmldb_core_upgrade($oldversion=0) {
delete_records('usr_watchlist_view', 'usr', 0);
}
if ($oldversion < 2016112301) {
require_once(get_config('docroot') . 'lib/group.php');
log_debug('Make sure all existing groups have a unique shortname.');
$groups = get_records_sql_array("
SELECT id, name, shortname FROM {group} WHERE shortname IN (
SELECT shortname FROM {group} GROUP BY shortname HAVING COUNT(shortname) > 1
)", array());
if (!empty($groups)) {
foreach ($groups as $group) {
$shortname = group_generate_shortname($group->shortname);
if ($shortname != $group->shortname) {
log_warn('Duplicate group shortname "' . $group->shortname . '" for group "' . $group->name . '" changed to "' . $shortname . '"', true, false);
update_record('group', array('shortname' => $shortname), array('id' => $group->id));
}
}
}
log_debug('Changing group uniqueness constraint from (institution,shortname) to just (shortname)');
// All shortnames should be unique now so we need to alter the unique key
$table = new XMLDBTable('group');
$index = new XMLDBIndex('shortnameuk');
$index->setAttributes(XMLDB_KEY_UNIQUE, array('institution', 'shortname'));
drop_index($table, $index);
$index = new XMLDBIndex('shortnameuk');
$index->setAttributes(XMLDB_KEY_UNIQUE, array('shortname'));
add_index($table, $index);
}
return $status;
}
......@@ -558,11 +558,11 @@ function group_update($new, $create=false) {
if (!empty($new->id)) {
$old = get_record_select('group', 'id = ? AND deleted = 0', array($new->id));
}
else if (!empty($new->institution) && isset($new->shortname) && strlen($new->shortname)) {
else if (!empty($new->shortname)) {
$old = get_record_select(
'group',
'shortname = ? AND institution = ? AND deleted = 0',
array($new->shortname, $new->institution)
'shortname = ? AND deleted = 0',
array($new->shortname)
);
if (!$old && $create) {
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2016112300;
$config->version = 2016112301;
$config->series = '17.04';
$config->release = '17.04dev';
$config->minupgradefrom = 2012080604;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment