1.1 --- a/egroupware_update_mailinglists.php Mon Jun 21 00:23:18 2010 +0200
1.2 +++ b/egroupware_update_mailinglists.php Mon Nov 29 21:05:58 2010 +0100
1.3 @@ -72,8 +72,21 @@
1.4 exit(1);
1.5 }
1.6
1.7 -$lists = $config->getValue(('egroupware-lists'));
1.8 -foreach ($lists as $listName => $groupId) {
1.9 +$lists = $config->getValue('egroupware-lists');
1.10 +
1.11 +if ($argc != 1) {
1.12 + $singleListName = $argv[1];
1.13 + if (!isset($lists[$singleListName])) {
1.14 + echo "Invalid list name: '$singleListName'\n";
1.15 + exit(1);
1.16 + }
1.17 +
1.18 + $data = $lists[$singleListName];
1.19 + $lists = array();
1.20 + $lists[$singleListName] = $data;
1.21 +}
1.22 +
1.23 +/* foreach_lists: */ foreach ($lists as $listName => $groupId) {
1.24 echo "(I) Processing list $listName\n";
1.25 $q = "SELECT account_lid, n_family, n_given, contact_email
1.26 FROM `egw_acl`
1.27 @@ -88,55 +101,66 @@
1.28 $users[] = $user['contact_email'];
1.29 }
1.30
1.31 - // get existing users on list (3 tries)
1.32 - $success = true;
1.33 - $cnt = 1;
1.34 + $unsubscribeSuccessful = false;
1.35 + $unsubscribeSuccessfulCnt = 1;
1.36 do {
1.37 - echo "(I) Getting existing users on the list (try $cnt)\n";
1.38 - $wj = new WhoJob;
1.39 - $uuid = $wj->go(array('list' => $listName));
1.40 - echo "(I) Executing job with ID $uuid.\n";
1.41 - $res = wait_for_results($wj);
1.42 - if ($res['status'] !== Job::STATUS_SUCCESS) {
1.43 - $success = false;
1.44 - echo "(E) Getting all users from list $listName failed.\n";
1.45 - } else {
1.46 - $existingUsers = $res['result'];
1.47 - }
1.48 - } while ($cnt++ < 4 && !$success);
1.49 -
1.50 - if (!$success) {
1.51 - echo "(E) Unable to get existing users from list in 3 tries, giving up.\n";
1.52 - continue;
1.53 - }
1.54 -
1.55 - // unsubscribe existing users
1.56 - if (empty($existingUsers)) {
1.57 - echo "(I) No existing users to unsubscribe.\n";
1.58 - } else {
1.59 + // get existing users on list (3 tries)
1.60 $success = true;
1.61 $cnt = 1;
1.62 do {
1.63 - echo "(I) Unsubscribing existing users (try $cnt)\n";
1.64 - $uj = new UnsubscribeJob;
1.65 - $params = array(
1.66 - 'list' => $listName,
1.67 - 'users' => $existingUsers
1.68 - );
1.69 - $uuid = $uj->go($params);
1.70 + echo "(I) Getting existing users on the list (try $cnt)\n";
1.71 + $wj = new WhoJob;
1.72 + $uuid = $wj->go(array('list' => $listName));
1.73 echo "(I) Executing job with ID $uuid.\n";
1.74 - $res = wait_for_results($uj);
1.75 + $res = wait_for_results($wj);
1.76 if ($res['status'] !== Job::STATUS_SUCCESS) {
1.77 $success = false;
1.78 - echo "(E) Unsubscribing all users from $listName failed.\n";
1.79 - var_dump($res);
1.80 + echo "(E) Getting all users from list $listName failed.\n";
1.81 + } else {
1.82 + $existingUsers = $res['result'];
1.83 }
1.84 } while ($cnt++ < 4 && !$success);
1.85 -
1.86 +
1.87 if (!$success) {
1.88 - echo "(E) Unable to unsubscribe users from list in 3 tries, giving up.\n";
1.89 - continue;
1.90 + echo "(E) Unable to get existing users from list in 3 tries, giving up.\n";
1.91 + continue 2; // continue with foreach_lists
1.92 }
1.93 +
1.94 + // unsubscribe existing users
1.95 + if (empty($existingUsers)) {
1.96 + echo "(I) No existing users to unsubscribe.\n";
1.97 + $unsubscribeSuccessful = true;
1.98 + } else {
1.99 + $success = true;
1.100 + $cnt = 1;
1.101 + do {
1.102 + echo "(I) Unsubscribing existing users (try $cnt)\n";
1.103 + $uj = new UnsubscribeJob;
1.104 + $params = array(
1.105 + 'list' => $listName,
1.106 + 'users' => $existingUsers
1.107 + );
1.108 + $uuid = $uj->go($params);
1.109 + echo "(I) Executing job with ID $uuid.\n";
1.110 + $res = wait_for_results($uj);
1.111 + if ($res['status'] !== Job::STATUS_SUCCESS) {
1.112 + $success = false;
1.113 + echo "(E) Unsubscribing all users from $listName failed.\n";
1.114 + var_dump($res);
1.115 + }
1.116 + } while ($cnt++ < 4 && !$success);
1.117 +
1.118 + if (!$success) {
1.119 + echo "(E) Unable to unsubscribe users from list in 3 tries, giving up.\n";
1.120 + } else {
1.121 + $unsubscribeSuccessful = true;
1.122 + }
1.123 + }
1.124 + } while ($unsubscribeSuccessfulCnt++ < 3 && !$unsubscribeSuccessful);
1.125 +
1.126 + // The sequence get users, unsubscribe was not 2x unsuccessful => give up
1.127 + if (!$unsubscribeSuccessful) {
1.128 + continue; // continue with foreach_lists
1.129 }
1.130
1.131 // subscribe new users