From 2f86231e61e81cf13194c6dbb354cfa80b8c3a9c Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 2 Sep 2016 21:30:51 +0200 Subject: [PATCH] Import users, too. --- TODO.md | 1 - import_albums.php | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 8911bdb..eea3696 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,6 @@ TODO: * Draaiing van foto's bij importeren goedzetten -* Import users * Import asset ownership * Pagina om één foto te bekijken * Taggen door gebruikers diff --git a/import_albums.php b/import_albums.php index 770d9cb..c19bc6b 100644 --- a/import_albums.php +++ b/import_albums.php @@ -25,6 +25,62 @@ Registry::set('user', Authentication::isLoggedIn() ? Member::fromId($_SESSION['u //set_error_handler('ErrorHandler::handleError'); ini_set("display_errors", DEBUG ? "On" : "Off"); +/******************************* + * STEP 0: USERS + *******************************/ + +$num_users = $pdb->queryValue(' + SELECT COUNT(*) + FROM users'); + +echo $num_users, ' users to import.', "\n"; + +$rs_users = $pdb->query(' + SELECT id, name, full_name, password, last_login, email, admin + FROM users + WHERE id > 1 + ORDER BY id ASC'); + +$old_user_id_to_new_user_id = []; + +while ($user = $pdb->fetch_assoc($rs_users)) +{ + // Check whether a user already exists for this e-mail address. + if (!($id_user = Authentication::getUserId($user['email']))) + { + $bool = $db->insert('insert', 'users', [ + 'first_name' => 'string-30', + 'surname' => 'string-60', + 'slug' => 'string-90', + 'emailaddress' => 'string-255', + 'password_hash' => 'string-255', + 'creation_time' => 'int', + 'last_action_time' => 'int', + 'ip_address' => 'string-15', + 'is_admin' => 'int', + ], [ + 'first_name' => substr($user['full_name'], 0, strpos($user['full_name'], ' ')), + 'surname' => substr($user['full_name'], strpos($user['full_name'], ' ') + 1), + 'slug' => $user['name'], + 'emailaddress' => $user['email'], + 'password_hash' => $user['password'], + 'creation_time' => 0, + 'last_action_time' => $user['last_login'], + 'ip_address' => '0.0.0.0', + 'is_admin' => $user['admin'], + ], ['id_user']); + + if ($bool) + $id_user = $db->insert_id(); + else + die("User creation failed!"); + } + + $old_user_id_to_new_user_id[$user['id']] = $id_user; +} + +$pdb->free_result($rs_users); + /******************************* * STEP 1: ALBUMS *******************************/