Skip to content
Snippets Groups Projects
Commit 8c029c06 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #67233 : another user datas migrations case

parent 245fd433
Branches
Tags
2 merge requests!2409Master,!2403hotline #67233 : another user datas migrations case
Pipeline #2892 passed with stage
in 22 minutes and 49 seconds
......@@ -12,9 +12,9 @@ echo 'User Data Migration by Stl And Pat since 1854
| T -\ \ / /-
/ \[_]..........................\ \ / /
This will detect user marked for deletion and
try to give their datas to another user
based on a rule before deleting them.
This will detect user with login starting with CHAM
try to rename them without CHAM or give their datas
to another user if a double exists.
';
......@@ -22,9 +22,10 @@ readline('press enter to continue...');
$valid_count = Class_Users::countBy(['statut' => 0, 'role_level' => 2]);
$invalid_count = Class_Users::countBy(['statut' => 1, 'role_level' => 2]);
$to_migrate = Class_Users::countBy(['where' => 'login like \'CHAM%\' AND SUBSTR(login,5) < 51001']);
echo $valid_count . ' valid users in database
' . $invalid_count . ' users marked for deletion
' . $to_migrate . ' users starting with CHAM[id < 51001]
';
if (0 == $valid_count) {
......@@ -80,10 +81,14 @@ echo '
';
$rename = 0;
$without_datas = 0;
$without_target = 0;
$success = 0;
$rename_log = (new UserDataMigrationLog('renamed.txt'))
->write(['id_bokeh', 'old_carte', 'new_carte', 'nom', 'prenom', 'naissance']);
$no_datas_log = (new UserDataMigrationLog('deleted_without_datas.txt'))
->write(['id_bokeh', 'carte', 'nom', 'prenom', 'naissance']);
......@@ -97,7 +102,48 @@ $success_log = (new UserDataMigrationLog('deleted_with_datas.txt'))
echo 'Started at ' . date('c') . "\n";
foreach(Class_Users::findAllBy(['statut' => 1, 'role_level' => 2]) as $user) {
/**
* migrate users from CHAMXXXXX login to XXXXX without CHAM, dedup if needed
*/
foreach(Class_Users::findAllBy(['where' => 'login like "CHAM%" and role_level=2']) as $user) {
// My login starts with cham (lowercase), I should not migrate
if ('CHAM' !== substr($user->getLogin(), 0, 4))
continue;
// My login is not strictly CHAM[0-9]+, I should not migrate
$id = substr($user->getLogin(), 4);
if (!is_numeric($id)) {
echo 'S';
continue;
}
// My login contains id above 51000, I should not migrate
if (51000 <= (int)$id) {
echo 'S';
continue;
}
// no user with my future id, simply rename me
if (!$double = Class_Users::findFirstBy(['login' => $id])) {
$rename_log->write([$user->getId(),
$user->getLogin(),
$id,
$user->getNom(),
$user->getPrenom(),
$user->getNaissance()]);
$user
->setLogin($id)
->setIdabon($id);
if ($for_real)
$user->save();
echo '.';
$rename++;
continue;
}
// another user has my target but I have no datas, simply delete me
$datas = new Class_User_Datas($user);
if (!$datas->hasDatas()) {
$no_datas_log->write([$user->getId(),
......@@ -108,25 +154,13 @@ foreach(Class_Users::findAllBy(['statut' => 1, 'role_level' => 2]) as $user) {
if ($for_real)
$user->delete();
$without_datas++;
continue;
}
if ('CHAM' != substr(strtoupper($user->getLogin()), 0, 4)) {
$no_target_log->write([$user->getId(),
$user->getLogin(),
$user->getNom(),
$user->getPrenom(),
$user->getNaissance(),
'Card does not starts with CHAM']);
$without_target++;
echo 'F';
echo '.';
$without_datas++;
continue;
}
if (!$target = $datas->giveTo(['login' => substr($user->getLogin(), 4),
'statut' => 0,
'role_level' => 2],
if (!$target = $datas->giveTo(['login' => $id, 'role_level' => 2],
$for_real)) {
$no_target_log->write([$user->getId(),
$user->getLogin(),
......@@ -160,8 +194,9 @@ foreach(Class_Users::findAllBy(['statut' => 1, 'role_level' => 2]) as $user) {
echo "\nEnded at " . date('c') . "\n";
printf('
%s renamed, log in renamed.txt
%s without datas, log in deleted_without_datas.txt
%s without target, log in not_deleted_target_problem.txt
%s success, log in deleted_with_datas.txt
%s given to another user, log in deleted_with_datas.txt
', $without_datas, $without_target, $success);
\ No newline at end of file
', $rename, $without_datas, $without_target, $success);
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment