Adds hruid migration scripts.
Signed-off-by: Vincent Zanotti <vincent.zanotti@polytechnique.org>
--- /dev/null
+# 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:
--- /dev/null
+<?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:
+?>
--- /dev/null
+#!/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";
+ }
+}
+?>
done
###########################################################
+echo "Creating forlife ids for unregistered user (takes a while)."
+
+./hruid.update.php
+
+###########################################################