Commit 9433a5f8 authored by Robert Lyon's avatar Robert Lyon Committed by Aaron Wells
Browse files

Bugs 1630753, 1630764 Updating db to fix missing user data



In case we have any missing studentid/preferredname artefacts if a
user was created with webservices before it was fixed

behatnotneeded

Change-Id: I520d580b5af496260d524ea9434aace41a22bcc1
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent c1cfa39a
......@@ -4708,5 +4708,44 @@ function xmldb_core_upgrade($oldversion=0) {
update_safe_iframe_regex();
}
if ($oldversion < 2016100600) {
log_debug('Fix broken user data for existing users created via webservices');
if ($studentids = get_records_sql_array("
SELECT u.id, u.studentid, 1 AS makenew FROM {usr} u
WHERE (u.studentid IS NOT NULL AND u.studentid != '')
AND NOT EXISTS (
SELECT id FROM {artefact}
WHERE artefacttype = 'studentid'
AND owner = u.id
)
UNION
SELECT u.id, u.studentid, 0 AS makenew FROM {usr} u
JOIN {artefact} a ON (a.owner = u.id AND a.artefacttype='studentid')
WHERE (u.studentid IS NOT NULL AND u.studentid != '')
AND u.studentid != a.title", array())) {
foreach ($studentids as $info) {
set_profile_field($info->id, 'studentid', $info->studentid, (bool) $info->makenew);
}
}
if ($preferrednames = get_records_sql_array("
SELECT u.id, u.preferredname, 1 AS makenew FROM {usr} u
WHERE (u.preferredname IS NOT NULL AND u.preferredname != '')
AND NOT EXISTS (
SELECT id FROM {artefact}
WHERE artefacttype = 'preferredname'
AND owner = u.id
)
UNION
SELECT u.id, u.preferredname, 0 AS makenew FROM {usr} u
JOIN {artefact} a ON (a.owner = u.id AND a.artefacttype='preferredname')
WHERE (u.preferredname IS NOT NULL AND u.preferredname != '')
AND u.preferredname != a.title", array())) {
foreach ($preferrednames as $info) {
set_profile_field($info->id, 'preferredname', $info->preferredname, (bool) $info->makenew);
}
}
}
return $status;
}
......@@ -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 = 2016090500;
$config->version = 2016100600;
$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