From e40488f80c5abcc91d950708c07c0c0b615dde66 Mon Sep 17 00:00:00 2001 From: paca70 Date: Thu, 24 Apr 2003 18:48:09 +0000 Subject: [PATCH] routines to convert postgeruser to lowercase. --- lib/db/postgres7.php | 49 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index d3dfb26957..fd8a28aedc 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -18,8 +18,8 @@ // This file is tailored to PostgreSQL 7 function main_upgrade($oldversion=0) { - global $CFG; - + global $CFG; + $result = true; if ($oldversion < 2003010101) { delete_records("log_display", "module", "user"); $new->module = "user"; @@ -75,8 +75,45 @@ function main_upgrade($oldversion=0) { } } } - - return true; -} -?> + if ($oldversion < 2003042401) { + // Convert usernames to lowercase + $users = get_records_sql("SELECT id, username FROM {$CFG->prefix}user"); + $cerrors = ""; + $rarray = array(); + foreach ($users as $user) { + $lcname = trim(moodle_strtolower($user->username)); + if (in_array($lcname, $rarray)) { + $cerrors .= $user->id."->".$lcname.'
' ; + }else { + array_push($rarray,$lcname); + } + } + /// Do convert or give error message + if ($cerrors != '') { + print "Error: Cannot convert usernames to lowercase. Following usernames would overlap (id->username):
$cerrors . Please resolve overlapping errors."; + $result = false; + }else { + $cerrors = ''; + print "Checking userdatabase:
"; + foreach ($users as $user) { + $lcname = trim(moodle_strtolower($user->username)); + $convert = set_field("user" , "username" , $lcname, "id", $user->id); + if (!$convert) { + if ($cerrors){ + $cerrors .= ", "; + } + $cerrors .= $item; + } else { + print "."; + } + } + if ($cerrors != '') { + print "There was errors when converting following usernames to lowercase. '$cerrors' . Please maintain your database by hand."; + $result=false; + } + } + } + return $result; +} +?> -- 2.39.5