Import users, too.

This commit is contained in:
Aaron van Geffen 2016-09-02 21:30:51 +02:00
parent 7240201a3e
commit 2f86231e61
2 changed files with 56 additions and 1 deletions

View File

@ -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

View File

@ -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
*******************************/