]> git.mjollnir.org Git - moodle.git/commitdiff
routines to convert postgeruser to lowercase.
authorpaca70 <paca70>
Thu, 24 Apr 2003 18:48:09 +0000 (18:48 +0000)
committerpaca70 <paca70>
Thu, 24 Apr 2003 18:48:09 +0000 (18:48 +0000)
lib/db/postgres7.php

index d3dfb2695795fb82cb95f1b8ed4c2b05513f6ef9..fd8a28aedcd9c2ca21254d325afcd367109902b7 100644 (file)
@@ -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;
+}
+?>