| 1 | #!/usr/bin/php5 -q |
| 2 | <?php |
| 3 | /*************************************************************************** |
| 4 | * Copyright (C) 2003-2008 Polytechnique.org * |
| 5 | * http://opensource.polytechnique.org/ * |
| 6 | * * |
| 7 | * This program is free software; you can redistribute it and/or modify * |
| 8 | * it under the terms of the GNU General Public License as published by * |
| 9 | * the Free Software Foundation; either version 2 of the License, or * |
| 10 | * (at your option) any later version. * |
| 11 | * * |
| 12 | * This program is distributed in the hope that it will be useful, * |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 | * GNU General Public License for more details. * |
| 16 | * * |
| 17 | * You should have received a copy of the GNU General Public License * |
| 18 | * along with this program; if not, write to the Free Software * |
| 19 | * Foundation, Inc., * |
| 20 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 21 | ***************************************************************************/ |
| 22 | |
| 23 | // Updates the gapps_accounts table with Plat/al information. |
| 24 | // Cleans-up the job queue, and execute post-queue hooks. |
| 25 | |
| 26 | require_once('../connect.db.inc.php'); |
| 27 | require_once('../../classes/plmailer.php'); |
| 28 | require_once('../../include/googleapps.inc.php'); |
| 29 | if (!$globals->mailstorage->googleapps_domain) { |
| 30 | exit; |
| 31 | } |
| 32 | |
| 33 | /* Updates the l_userid parameter for newer user accounts. */ |
| 34 | $res = XDB::iterator( |
| 35 | "SELECT g.g_account_name, a.id |
| 36 | FROM gapps_accounts AS g |
| 37 | LEFT JOIN aliases as a ON (a.alias = g.g_account_name AND a.type = 'a_vie') |
| 38 | WHERE (g.l_userid IS NULL OR g.l_userid <= 0) AND a.id IS NOT NULL"); |
| 39 | while ($account = $res->next()) { |
| 40 | XDB::execute( |
| 41 | "UPDATE gapps_accounts |
| 42 | SET l_userid = {?} |
| 43 | WHERE g_account_name = {?}", |
| 44 | $account['id'], $account['g_account_name']); |
| 45 | } |
| 46 | |
| 47 | /* Emits a warning for GApps accounts without local user_id. */ |
| 48 | $res = XDB::iterator( |
| 49 | "SELECT g.g_account_name |
| 50 | FROM gapps_accounts AS g |
| 51 | LEFT JOIN aliases as a ON (a.alias = g.g_account_name AND a.type = 'a_vie') |
| 52 | WHERE (g.l_userid IS NULL OR g.l_userid <= 0) AND a.id IS NULL"); |
| 53 | while ($account = $res->next()) { |
| 54 | if (!preg_match("/^admin-/", $account['g_account_name'])) { |
| 55 | printf("Warning: GApps account '%s' has no local user_id.\n", $account['g_account_name']); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /* Retrieves successful job queues for post-queue processing. */ |
| 60 | $res = XDB::iterator( |
| 61 | "SELECT q_id, q_recipient_id, j_type, j_parameters |
| 62 | FROM gapps_queue |
| 63 | WHERE p_status = 'success' AND q_recipient_id IS NOT NULL"); |
| 64 | while ($job = $res->next()) { |
| 65 | if ($job['j_type'] == 'u_create') { |
| 66 | post_queue_u_create($job); |
| 67 | } else if ($job['j_type'] == 'u_update') { |
| 68 | post_queue_u_update($job); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /* Removes successful jobs, and old failed jobs. */ |
| 73 | XDB::execute( |
| 74 | "DELETE FROM gapps_queue |
| 75 | WHERE p_status = 'success' OR |
| 76 | (p_status = 'hardfail' AND p_end_date < DATE_SUB(NOW(), INTERVAL 15 DAY))"); |
| 77 | |
| 78 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 79 | ?> |