Adds a new 'hruid' column (Human Readable UID) to the auth_user_md5 table.
authorVincent Zanotti <vincent.zanotti@polytechnique.org>
Fri, 13 Jun 2008 00:44:15 +0000 (02:44 +0200)
committerVincent Zanotti <vincent.zanotti@polytechnique.org>
Fri, 13 Jun 2008 00:44:15 +0000 (02:44 +0200)
Adds hruid migration scripts.

Signed-off-by: Vincent Zanotti <vincent.zanotti@polytechnique.org>
upgrade/0.9.17/03_hruid.sql [new file with mode: 0644]
upgrade/0.9.17/connect.db.inc.php [new file with mode: 0644]
upgrade/0.9.17/hruid.update.php [new file with mode: 0755]
upgrade/0.9.17/update.sh

diff --git a/upgrade/0.9.17/03_hruid.sql b/upgrade/0.9.17/03_hruid.sql
new file mode 100644 (file)
index 0000000..49b0f78
--- /dev/null
@@ -0,0 +1,13 @@
+# Creates a new column for the hruid field, and adds an index on it.
+ALTER TABLE auth_user_md5
+    ADD COLUMN hruid VARCHAR(255) DEFAULT NULL AFTER user_id,
+    ADD UNIQUE INDEX hruid(hruid);
+
+
+# Pre-fills the hruid field with the current forlife.
+   UPDATE  auth_user_md5 AS u
+LEFT JOIN  aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
+      SET  u.hruid = a.alias
+    WHERE  a.alias IS NOT NULL AND u.hruid IS NULL;
+
+# vim:set syntax=mysql:
diff --git a/upgrade/0.9.17/connect.db.inc.php b/upgrade/0.9.17/connect.db.inc.php
new file mode 100644 (file)
index 0000000..2e66895
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+ini_set('include_path', dirname(__FILE__).'/../../include:' . dirname(__FILE__).'/../../classes:/usr/share/php');
+
+require_once 'xorg.inc.php';
+require_once 'xdb.php';
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
diff --git a/upgrade/0.9.17/hruid.update.php b/upgrade/0.9.17/hruid.update.php
new file mode 100755 (executable)
index 0000000..8edb887
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/php5
+<?php
+
+require_once 'connect.db.inc.php';
+require_once 'xorg.misc.inc.php';
+
+// Fetches the list of unregistered users.
+$users = XDB::iterRow(
+    "SELECT  user_id, prenom, nom, promo
+       FROM  auth_user_md5
+      WHERE  hruid IS NULL");
+
+// Creates missing human readable uids.
+while (list($user_id, $prenom, $nom, $promo) = $users->next()) {
+    $forlife = make_forlife($prenom, $nom, $promo);
+    if (!XDB::execute("UPDATE auth_user_md5 SET hruid = {?} WHERE user_id = {?}", $forlife, $user_id)) {
+        echo "WARNING: Duplicate forlife for user $user_id and forlife '$forlife'. Please check manually the entry.\n";
+    }
+}
+?>
index f351939..0e99620 100755 (executable)
@@ -16,4 +16,9 @@ do
 done
 
 ###########################################################
+echo "Creating forlife ids for unregistered user (takes a while)."
+
+./hruid.update.php
+
+###########################################################