Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
run_cron_job.php
1 <?php
26 error_reporting(E_ALL);
27 if (php_sapi_name() != 'cli') trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
28 
29 if (count($_SERVER['argv']) != 3) {
30  echo "Usage:\n\n";
31  echo "\tphp ".basename($_SERVER['argv'][0])." <SYSTEM_ROOT> <cron job assetid>\n\n";
32  exit();
33 }
34 
35 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
36 if (empty($SYSTEM_ROOT)) {
37  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
38  exit();
39 }
40 
41 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
42  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
43  exit();
44 }
45 $ASSETID = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : '';
46 
47 require_once $SYSTEM_ROOT.'/core/include/init.inc';
48 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
49 
50 $root_user = &$GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
51 if (is_null($root_user)) {
52  echo "Unable to get Root User\n";
53  exit();
54 }
55 
56 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
57  echo "Unable to set Root User as current user\n";
58  exit();
59 }
60 
61 $cron_job = &$GLOBALS['SQ_SYSTEM']->am->getAsset($ASSETID);
62 if (is_null($cron_job)) {
63  echo "Asset ID passed (#'.$ASSETID.') does not point to a valid asset\n";
64  exit();
65 }
66 if (!is_a($cron_job, 'cron_job')) {
67  echo "Asset ID passed (#'.$ASSETID.') does not point to a Cron Job asset";
68  exit();
69 }
70 
71 $result = $cron_job->run();
72 
73 pre_echo("Result: ".implode(', ',get_bit_names('SQ_CRON_JOB_', $result, true)));
74 
75 ?>