Adds first and last names to accounts.
[platal.git] / upgrade / 1.1.1 / accounts.php
1 #!/usr/bin/php5
2 <?php
3
4 require_once 'connect.db.inc.php';
5
6 $globals->debug = 0; // Do not store backtraces.
7
8 $it = XDN::rawIterator('SELECT uid, full_name, email, type
9 FROM accounts
10 WHERE type NOT IN (\'x\', \'master\', \'phd\')');
11 while ($item = $it->next()) {
12 if ($item['type'] == 'virtual') {
13 $firstname = '';
14 $lastname = $item['full_name'];
15 } elseif (strpos(' ', $item['full_name'])) {
16 list($firstname, $lastname) = explode(' ', $item['full_name']);
17 } else {
18 list($local_part, ) = explode('@', strtolower($item['email']));
19 $parts = explode('.', $local_part);
20 if (count($parts) == 1) {
21 $lastname = ucfirst($local_part);
22 $firstname = '';
23 } else {
24 $firstname = ucfirst($parts[0]);
25 $lastname = ucwords(implode(' ', array_slice($parts, 1)));
26 }
27 }
28 XDB::execute('UPDATE accounts
29 SET firstname = {?}, lastname = {?}',
30 $firstname, $lastname);
31 }
32
33 /* vim:set et sw=4 sts=4 ts=4: */
34 ?>