X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=bin%2Fcron%2Fgoogle_apps.php;h=698968e93a0c7b9e65bbf37f987426939a7bfd6b;hb=12a587df92f7bc9efeb91c1a2d27f763070b8609;hp=76cfcc538c2c34f7832a9e7e89e8c5a0d75685f2;hpb=cbfaae155e75c6e93e36a0d6ba68fc73744d3bca;p=platal.git diff --git a/bin/cron/google_apps.php b/bin/cron/google_apps.php index 76cfcc5..698968e 100755 --- a/bin/cron/google_apps.php +++ b/bin/cron/google_apps.php @@ -19,25 +19,61 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -/* Updates the gapps_accounts table with Plat/al information. */ -require('./connect.db.inc.php'); -if (!$globals->googleapps->domain) { +// Updates the gapps_accounts table with Plat/al information. +// Cleans-up the job queue, and execute post-queue hooks. + +require_once('../connect.db.inc.php'); +require_once('../../classes/plmailer.php'); +require_once('../../include/googleapps.inc.php'); +if (!$globals->mailstorage->googleapps_domain) { exit; } /* Updates the l_userid parameter for newer user accounts. */ -$res = XDB::iterator("SELECT g.g_account_name, a.id - FROM gapps_accounts AS g - LEFT JOIN aliases as a ON (a.alias = g.g_account_name AND a.type = 'a_vie') - WHERE (g.l_userid IS NULL OR g.l_userid <= 0) AND - a.id IS NOT NULL"); +$res = XDB::iterator( + "SELECT g.g_account_name, a.id + FROM gapps_accounts AS g + LEFT JOIN aliases as a ON (a.alias = g.g_account_name AND a.type = 'a_vie') + WHERE (g.l_userid IS NULL OR g.l_userid <= 0) AND a.id IS NOT NULL"); +while ($account = $res->next()) { + XDB::execute( + "UPDATE gapps_accounts + SET l_userid = {?} + WHERE g_account_name = {?}", + $account['id'], $account['g_account_name']); +} + +/* Emits a warning for GApps accounts without local user_id. */ +$res = XDB::iterator( + "SELECT g.g_account_name + FROM gapps_accounts AS g + LEFT JOIN aliases as a ON (a.alias = g.g_account_name AND a.type = 'a_vie') + WHERE (g.l_userid IS NULL OR g.l_userid <= 0) AND a.id IS NULL"); while ($account = $res->next()) { - XDB::execute("UPDATE gapps_accounts - SET l_userid = {?} - WHERE g_account_name = {?}", - $account['id'], $account['g_account_name']); + if (!preg_match("/^admin-/", $account['g_account_name'])) { + printf("Warning: GApps account '%s' has no local user_id.\n", $account['g_account_name']); + } } +/* Retrieves successful job queues for post-queue processing. */ +$res = XDB::iterator( + "SELECT q_id, q_recipient_id, j_type, j_parameters + FROM gapps_queue + WHERE p_status = 'success' AND q_recipient_id IS NOT NULL"); +while ($job = $res->next()) { + if ($job['j_type'] == 'u_create') { + post_queue_u_create($job); + } else if ($job['j_type'] == 'u_update') { + post_queue_u_update($job); + } +} + +/* Removes successful jobs, and old failed jobs. */ +XDB::execute( + "DELETE FROM gapps_queue + 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: ?>