|
| 1 | +<?php |
| 2 | + |
| 3 | +/* For licensing terms, see /license.txt */ |
| 4 | + |
| 5 | +/** |
| 6 | + * This script takes a user extra field variabler and looks for users duplicated |
| 7 | + * based on this extra field values and unify them on the most recent account |
| 8 | + */ |
| 9 | +exit; |
| 10 | +require __DIR__.'/../../main/inc/global.inc.php'; |
| 11 | + |
| 12 | +// set the extra field variable to use |
| 13 | +$extraFieldVariable = 'dni'; |
| 14 | + |
| 15 | +// define if the unified accounts should be deleted or deactivated |
| 16 | +$unifyMode = 'delete'; // 'delete' or 'deactivate' |
| 17 | + |
| 18 | +$fieldInfo = MySpace::duGetUserExtraFieldByVariable($extraFieldVariable); |
| 19 | +if (empty($fieldInfo)) { |
| 20 | + echo 'ExtraField not found : '. $extraFieldVariable . PHP_EOL; |
| 21 | + exit; |
| 22 | +} |
| 23 | + |
| 24 | +$fieldId = (int) $fieldInfo['id']; |
| 25 | +$accessURLs = api_get_access_urls(); |
| 26 | +foreach($accessURLs as $accessURL) { |
| 27 | + $urlId = $accessURL['id']; |
| 28 | + echo 'Searching duplicates on ' . $accessURL['url'] . ' with id = ' . $urlId . PHP_EOL; |
| 29 | + $dups = MySpace::duGetDuplicateValues($fieldId, $urlId); |
| 30 | + if (empty($dups)) { |
| 31 | + echo 'No duplicates found' . PHP_EOL; |
| 32 | + } else { |
| 33 | + foreach ($dups as $g) { |
| 34 | + $value = $g['the_value']; |
| 35 | + echo 'Analysing duplicates of ' . $value . PHP_EOL; |
| 36 | + $users = MySpace::duGetUsersByFieldValue($fieldId, $urlId, $value); |
| 37 | + $userIdToUnifyOn = 0; |
| 38 | + $mostRecentRegistrationDate = 0; |
| 39 | + foreach ($users as $u) { |
| 40 | + $uid = (int)$u['user_id']; |
| 41 | + $userInfo = api_get_user_info($uid); |
| 42 | + if ($userInfo['registration_date'] > $mostRecentRegistrationDate) { |
| 43 | + $mostRecentRegistrationDate = $userInfo['registration_date']; |
| 44 | + $userIdToUnifyOn = $uid; |
| 45 | + } |
| 46 | + } |
| 47 | + foreach ($users as $u) { |
| 48 | + $uid = (int)$u['user_id']; |
| 49 | + if ($uid === $userIdToUnifyOn) { continue; } |
| 50 | + |
| 51 | + echo 'Unifying user ' . $uid . ' on user ' . $userIdToUnifyOn . PHP_EOL; |
| 52 | + MySpace::duUpdateAllUserRefsList($uid, $userIdToUnifyOn); |
| 53 | + MySpace::duDisableOrDeleteUser($uid, $unifyMode); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments