I am trying to migrate users from kirby2 to kirby3 using the script from the cookbook.
The script works for everything except a page/pages field.
at the moment I have this code:
$profile = @$data['profile'];
$profile = $profile?Data::encode([$profile], 'yaml'):'';
The data this produces looks good but the $kirby->users()->create function then apparently empties the data for the profile field.
This is the whole script:
<?php
//set_time_limit(360);
require __DIR__ . '/kirby/bootstrap.php';
$kirby = new Kirby;
$dir = $kirby->root('accounts');
// authenticate as almighty
$kirby->impersonate('kirby');
// loop through each K2 account file
foreach (Dir::files($dir) as $account) {
// read K2 account file
$data = Data::read($dir . '/' . $account, 'yaml');
if (isset($data['username'])){
// prepare data to be processed
$name = $data['username'];
$email = $data['email'];
$password = $data['password'];
$role = $data['role'];
$language = $data['language'];
$sitelanguage = @$data['sitelanguage'];
$profile = @$data['profile'];
dump($profile);
$profile = $profile?Data::encode([$profile], 'yaml'):'';
dump($profile);
$conditionsagreedon = @$data['conditionsagreedon'];
$date = $conditionsagreedon;
$newDate = DateTime::createFromFormat('d/m/Y H:i:s', $date);
$conditionsagreedon = $newDate?$newDate->format('Y-m-d H:i:s'):'';
unset(
$data[0],
$data['username'],
$data['email'],
$data['password'],
$data['role'],
$data['language'],
$data['history'],
$data['sitelanguage'],
$data['profile'],
$data['conditionsagreedon']
);
// create new K3 user account
$user = $kirby->users()->create([
'email' => $email,
'name' => $name,
'role' => $role,
'language' => $language,
'content' => $data,
'password' => $password,
'sitelanguage' => $sitelanguage,
'profile' => $profile,
'conditionsagreedon' => $conditionsagreedon
]);
// write K2 password hash to .htpasswd
F::write($dir . '/' . $user->id() . '/.htpasswd', $password);
// delete K2 account file
F::remove($dir . '/' . $account);
echo 'User migrated: ' . $user->email() . '<br>';
}
}