|
7 | 7 | * based on this extra field values and unify them on the most recent account |
8 | 8 | */ |
9 | 9 | exit; |
| 10 | +$now = date('Y-m-d H:i:s'); |
| 11 | +echo $now . " Starting " . __FILE__ . PHP_EOL; |
10 | 12 | require __DIR__.'/../../main/inc/global.inc.php'; |
11 | 13 |
|
12 | | -// Filter to only manage those users based on their user_id : |
13 | | -//$filteredUsers = [11,12,13]; // set the list of user_id |
| 14 | +// Filter to only manage those users based on the duplicate field's value: |
| 15 | +//$filteredUsers = ['XYZ1','XYZ2','XYZ3']; // set the list of values of the duplicated field |
| 16 | +if (!empty($filteredUsers)) { |
| 17 | + echo "Filtered users list is defined: "; |
| 18 | + foreach ($filteredUsers as $u) { |
| 19 | + echo $u . ' '; |
| 20 | + } |
| 21 | + echo PHP_EOL; |
| 22 | +} |
| 23 | +// Filter to only manage users from one sub-URL |
| 24 | +//$filteredUrls = [4]; |
| 25 | +if (!empty($filteredUrls)) { |
| 26 | + echo "Filtered URLs list is defined: "; |
| 27 | + foreach ($filteredUrls as $u) { |
| 28 | + echo $u . ' '; |
| 29 | + } |
| 30 | + echo PHP_EOL; |
| 31 | +} |
14 | 32 |
|
15 | | -// set the extra field variable to use |
| 33 | +// set the extra field variable to use |
16 | 34 | $extraFieldVariable = 'dni'; |
17 | 35 |
|
18 | 36 | // define if the unified accounts should be deleted or deactivated |
19 | 37 | $unifyMode = 'delete'; // 'delete' or 'deactivate' |
20 | 38 |
|
21 | 39 | $fieldInfo = MySpace::duGetUserExtraFieldByVariable($extraFieldVariable); |
22 | 40 | if (empty($fieldInfo)) { |
23 | | - echo 'ExtraField not found : '. $extraFieldVariable . PHP_EOL; |
| 41 | + echo 'ExtraField not found: ' . $extraFieldVariable . PHP_EOL; |
24 | 42 | exit; |
25 | 43 | } |
26 | 44 |
|
27 | 45 | $fieldId = (int) $fieldInfo['id']; |
28 | 46 | $accessURLs = api_get_access_urls(); |
29 | | -foreach($accessURLs as $accessURL) { |
| 47 | +foreach ($accessURLs as $accessURL) { |
30 | 48 | $urlId = $accessURL['id']; |
31 | | - echo 'Searching duplicates on ' . $accessURL['url'] . ' with id = ' . $urlId . PHP_EOL; |
| 49 | + if (!empty($filteredUrls) && !in_array($urlId, $filteredUrls)) { |
| 50 | + echo "URL " . $accessURL['url'] . " not in filtered list, skipping..." . PHP_EOL; |
| 51 | + continue; |
| 52 | + } |
| 53 | + echo 'Searching duplicates on ' . $accessURL['url'] . ' with id = ' . $urlId . PHP_EOL; |
32 | 54 | $dups = MySpace::duGetDuplicateValues($fieldId, $urlId); |
33 | 55 | if (empty($dups)) { |
34 | 56 | echo 'No duplicates found' . PHP_EOL; |
35 | 57 | } else { |
36 | 58 | foreach ($dups as $g) { |
37 | 59 | $value = $g['the_value']; |
38 | | - echo 'Analysing duplicates of ' . $value . PHP_EOL; |
| 60 | + if (!empty($filteredUsers) && !in_array($value, $filteredUsers)) { |
| 61 | + continue; |
| 62 | + } else { |
| 63 | + echo "Value $value is in the filtered list. Proceeding..." . PHP_EOL; |
| 64 | + } |
| 65 | + echo 'Analysing duplicates of ' . $value . ' ...' . PHP_EOL; |
39 | 66 | $users = MySpace::duGetUsersByFieldValue($fieldId, $urlId, $value); |
40 | 67 | $userIdToUnifyOn = 0; |
41 | 68 | $mostRecentRegistrationDate = 0; |
42 | 69 | foreach ($users as $u) { |
43 | 70 | $uid = (int)$u['user_id']; |
44 | | - if (isset($filteredUsers) && !in_array($uid, $filteredUsers) { |
45 | | - continue; |
46 | | - } |
47 | 71 | $userInfo = api_get_user_info($uid); |
48 | | - if ($userInfo['registration_date'] > $mostRecentRegistrationDate) { |
| 72 | + if ($userInfo['registration_date'] > $mostRecentRegistrationDate) { |
49 | 73 | $mostRecentRegistrationDate = $userInfo['registration_date']; |
50 | 74 | $userIdToUnifyOn = $uid; |
51 | 75 | } |
52 | 76 | } |
53 | 77 | foreach ($users as $u) { |
54 | 78 | $uid = (int)$u['user_id']; |
55 | | - if (isset($filteredUsers) && !in_array($uid, $filteredUsers) { |
56 | | - continue; |
57 | | - } |
58 | 79 | if ($uid === $userIdToUnifyOn) { continue; } |
59 | 80 | $now = date('Y-m-d H:i:s'); |
60 | 81 | echo $now . ' Unifying user ' . $uid . ' on user ' . $userIdToUnifyOn . PHP_EOL; |
|
0 commit comments