X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=bin%2Fcron%2Fgoogle_apps.php;h=ee4a1801b4dd3ffde5cf64caf23b763039d6a61a;hb=3424387cde6c635ff16c3b5459c4caa88bb76e2e;hp=9b6f78d2452d8ec038d20b7cf6c9e0b420b0d1c9;hpb=45ea6160465aeba0aa780e49c12272819dedffd1;p=platal.git diff --git a/bin/cron/google_apps.php b/bin/cron/google_apps.php index 9b6f78d..ee4a180 100755 --- a/bin/cron/google_apps.php +++ b/bin/cron/google_apps.php @@ -1,7 +1,7 @@ #!/usr/bin/php5 -q next()) { // we might run in troubler later if we don't keep the two repos. If we need // to add a forlife-looking nickname at some point, we'll do it manually. if (!preg_match('/^[-a-z]+\.[-a-z]+\.\d{4}$/', $nickname['nickname'])) { - XDB::execute( - "INSERT INTO gapps_queue - SET q_recipient_id = {?}, p_entry_date = NOW(), p_notbefore_date = NOW(), - p_priority = 'offline', j_type = 'n_create', j_parameters = {?}", - $nickname['uid'], - json_encode($nickname)); + $pending_tasks = XDB::fetchOneCell( + "SELECT COUNT(*) + FROM gapps_queue + WHERE q_recipient_id = {?} AND p_status = 'idle' AND j_type = 'n_create' AND j_parameters = {?}", + $nickname['id'], json_encode($nickname)); + if ($pending_tasks == 0) { + XDB::execute( + "INSERT INTO gapps_queue + SET q_recipient_id = {?}, p_entry_date = NOW(), p_notbefore_date = NOW(), + p_priority = 'offline', j_type = 'n_create', j_parameters = {?}", + $nickname['id'], json_encode($nickname)); + } } } @@ -111,15 +117,21 @@ while ($nickname = $res->next()) { $res = XDB::iterator( "SELECT g.l_userid AS id, g.g_nickname AS nickname FROM gapps_nicknames AS g - LEFT JOIN email_source_account AS s ON (s.uid = g.l_userid AND s.type = 'forlife' AND s.email = g.g_nickname) + LEFT JOIN email_source_account AS s ON (s.uid = g.l_userid AND s.type = 'alias' AND s.email = g.g_nickname) WHERE g.l_userid IS NOT NULL AND s.email IS NULL"); while ($nickname = $res->next()) { - XDB::execute( - "INSERT INTO gapps_queue - SET q_recipient_id = {?}, p_entry_date = NOW(), p_notbefore_date = NOW(), - p_priority = 'offline', j_type = 'n_delete', j_parameters = {?}", - $nickname['uid'], - json_encode($nickname)); + $pending_tasks = XDB::fetchOneCell( + "SELECT COUNT(*) + FROM gapps_queue + WHERE q_recipient_id = {?} AND p_status = 'idle' AND j_type = 'n_delete' AND j_parameters = {?}", + $nickname['id'], json_encode($nickname)); + if ($pending_tasks == 0) { + XDB::execute( + "INSERT INTO gapps_queue + SET q_recipient_id = {?}, p_entry_date = NOW(), p_notbefore_date = NOW(), + p_priority = 'offline', j_type = 'n_delete', j_parameters = {?}", + $nickname['id'], json_encode($nickname)); + } } /* Retrieves successful job queues for post-queue processing. */ @@ -141,5 +153,5 @@ XDB::execute( WHERE p_status = 'success' OR (p_status = 'hardfail' AND p_end_date < DATE_SUB(NOW(), INTERVAL 15 DAY))"); -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>