Skip to content
Browse files

routines to convert postgeruser to lowercase.

  • Loading branch information...
1 parent c37053e commit e40488f80c5abcc91d950708c07c0c0b615dde66 paca70 committed Apr 24, 2003
Showing with 43 additions and 6 deletions.
  1. +43 −6 lib/db/postgres7.php
View
49 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.'<br/>' ;
+ }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):<br/> $cerrors . Please resolve overlapping errors.";
+ $result = false;
+ }else {
+ $cerrors = '';
+ print "Checking userdatabase:<br>";
+ 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;
+}
+?>

0 comments on commit e40488f

Please sign in to comment.
Something went wrong with that request. Please try again.