Moving to GitHub.
[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 = XDB::rawIterator('SELECT uid, full_name, email, type
9 FROM accounts
10 WHERE type NOT IN (\'x\', \'master\', \'phd\')');
11 $total = $it->total();
12 $done = 0;
13
14 while ($item = $it->next()) {
15 if ($item['type'] == 'virtual') {
16 $firstname = '';
17 $lastname = $item['full_name'];
18 } elseif ($item['full_name'] && strpos(' ', $item['full_name'])) {
19 list($firstname, $lastname) = explode(' ', $item['full_name']);
20 } else {
21 list($local_part, ) = explode('@', strtolower($item['email']));
22 $parts = explode('.', $local_part);
23 if (count($parts) == 1) {
24 $lastname = ucfirst($local_part);
25 $firstname = '';
26 } else {
27 $firstname = ucfirst($parts[0]);
28 $lastname = ucwords(implode(' ', array_slice($parts, 1)));
29 }
30 }
31
32 XDB::execute('UPDATE accounts
33 SET firstname = {?}, lastname = {?}
34 WHERE uid = {?}',
35 $firstname, $lastname, $item['uid']);
36 ++$done;
37 printf("\r%u / %u", $done, $total);
38 }
39 print "\n\nDone.\n";
40
41 /* vim:set et sw=4 sts=4 ts=4: */
42 ?>