[2] | 1 | #!/usr/bin/php -q |
---|
| 2 | <?php |
---|
| 3 | /**************************************************************************\ |
---|
| 4 | * eGroupWare API - Timed Asynchron Services for eGroupWare * |
---|
| 5 | * Written by Ralf Becker <RalfBecker@outdoor-training.de> * |
---|
| 6 | * Class for creating cron-job like timed calls of eGroupWare methods * |
---|
| 7 | * -------------------------------------------------------------------------* |
---|
| 8 | * This library is part of the eGroupWare API * |
---|
| 9 | * http://www.egroupware.org/ * |
---|
| 10 | * ------------------------------------------------------------------------ * |
---|
| 11 | * This library is free software; you can redistribute it and/or modify it * |
---|
| 12 | * under the terms of the GNU Lesser General Public License as published by * |
---|
| 13 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
| 14 | * or any later version. * |
---|
| 15 | * This library is distributed in the hope that it will be useful, but * |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
| 18 | * See the GNU Lesser General Public License for more details. * |
---|
| 19 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 20 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 21 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
| 22 | \**************************************************************************/ |
---|
| 23 | |
---|
| 24 | $_GET['domain'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'default'; |
---|
| 25 | $path_to_egroupware = realpath(dirname(__FILE__).'/../..'); // need to be adapted if this script is moved somewhere else |
---|
[5141] | 26 | $_SESSION['isCrun'] = true; |
---|
[2] | 27 | // remove the comment from one of the following lines to enable loging |
---|
| 28 | // define('ASYNC_LOG','C:\\async.log'); // Windows |
---|
| 29 | define('ASYNC_LOG','/tmp/async.log'); // Linux, Unix, ... |
---|
| 30 | if (defined('ASYNC_LOG')) |
---|
| 31 | { |
---|
| 32 | $msg = date('Y/m/d H:i:s ').$_GET['domain'].": asyncservice started\n"; |
---|
| 33 | $f = fopen(ASYNC_LOG,'a+'); |
---|
| 34 | fwrite($f,$msg); |
---|
| 35 | fclose($f); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
| 39 | 'currentapp' => 'login', |
---|
| 40 | 'noapi' => True // this stops header.inc.php to include phpgwapi/inc/function.inc.php |
---|
| 41 | ); |
---|
| 42 | if (!is_readable($path_to_egroupware.'/header.inc.php')) |
---|
| 43 | { |
---|
| 44 | echo $msg = "asyncservice.php: Could not find '$path_to_egroupware/header.inc.php', exiting !!!\n"; |
---|
| 45 | if (defined('ASYNC_LOG')) |
---|
| 46 | { |
---|
| 47 | $f = fopen(ASYNC_LOG,'a+'); |
---|
| 48 | fwrite($f,$msg); |
---|
| 49 | fclose($f); |
---|
| 50 | } |
---|
| 51 | exit(1); |
---|
| 52 | } |
---|
| 53 | include($path_to_egroupware.'/header.inc.php'); |
---|
| 54 | unset($GLOBALS['phpgw_info']['flags']['noapi']); |
---|
| 55 | |
---|
| 56 | $db_type = $GLOBALS['phpgw_domain'][$_GET['domain']]['db_type']; |
---|
| 57 | if (!isset($GLOBALS['phpgw_domain'][$_GET['domain']]) || empty($db_type)) |
---|
| 58 | { |
---|
| 59 | echo $msg = "asyncservice.php: Domain '$_GET[domain]' is not configured or renamed, exiting !!!\n"; |
---|
| 60 | if (defined('ASYNC_LOG')) |
---|
| 61 | { |
---|
| 62 | $f = fopen(ASYNC_LOG,'a+'); |
---|
| 63 | fwrite($f,$msg); |
---|
| 64 | fclose($f); |
---|
| 65 | } |
---|
| 66 | exit(1); |
---|
| 67 | } |
---|
| 68 | // some constanst for pre php4.3 |
---|
| 69 | if (!defined('PHP_SHLIB_SUFFIX')) |
---|
| 70 | { |
---|
| 71 | define('PHP_SHLIB_SUFFIX',strtoupper(substr(PHP_OS, 0,3)) == 'WIN' ? 'dll' : 'so'); |
---|
| 72 | } |
---|
| 73 | if (!defined('PHP_SHLIB_PREFIX')) |
---|
| 74 | { |
---|
| 75 | define('PHP_SHLIB_PREFIX',PHP_SHLIB_SUFFIX == 'dll' ? 'php_' : ''); |
---|
| 76 | } |
---|
| 77 | $db_extension = PHP_SHLIB_PREFIX.$db_type.'.'.PHP_SHLIB_SUFFIX; |
---|
| 78 | if (!extension_loaded($db_type) && !dl($db_extension)) |
---|
| 79 | { |
---|
| 80 | echo $msg = "asyncservice.php: Extension '$db_type' is not loaded and can't be loaded via dl('$db_extension') !!!\n"; |
---|
| 81 | if (defined('ASYNC_LOG')) |
---|
| 82 | { |
---|
| 83 | $f = fopen(ASYNC_LOG,'a+'); |
---|
| 84 | fwrite($f,$msg); |
---|
| 85 | fclose($f); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | $GLOBALS['phpgw_info']['server']['sessions_type'] = 'db'; // no php4-sessions availible for cgi |
---|
| 90 | |
---|
| 91 | include(PHPGW_API_INC.'/functions.inc.php'); |
---|
[86] | 92 | $preferences = createobject('phpgwapi.preferences'); |
---|
| 93 | $preferences->read(); |
---|
[2] | 94 | |
---|
| 95 | $num = ExecMethod('phpgwapi.asyncservice.check_run','crontab'); |
---|
| 96 | |
---|
| 97 | $msg = date('Y/m/d H:i:s ').$_GET['domain'].': '.($num ? "$num job(s) executed" : 'Nothing to execute')."\n\n"; |
---|
| 98 | // if the following comment got removed, you will get an email from cron for every check performed (*nix only) |
---|
| 99 | //echo $msg; |
---|
| 100 | |
---|
| 101 | if (defined('ASYNC_LOG')) |
---|
| 102 | { |
---|
| 103 | $f = fopen(ASYNC_LOG,'a+'); |
---|
| 104 | fwrite($f,$msg); |
---|
| 105 | fclose($f); |
---|
| 106 | } |
---|
| 107 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|