Created
April 18, 2012 18:04
-
-
Save litzinger/2415470 to your computer and use it in GitHub Desktop.
Call EE actions via cron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Cheap way to fire off EE's ACT events in a crontab, and without having | |
to make any other changes to bootstrap EE to work in CLI. | |
*/ | |
if (isset($_SERVER['SERVER_NAME']) || PHP_SAPI !== "cli") die(); | |
$args = $argv; | |
//remove first element from the argument array (script name) | |
array_shift($args); | |
/** | |
* convert arguments in the format --key1=value1 --key2=value2 to | |
* ?key1=value1&key2=value2 | |
* | |
* Example call: cron.php --var=foo | |
* | |
* Examples | |
* | |
* Run every Friday at noon | |
* 0 12 * * 5 php /path/to/site/cmd/cron.php --ACT=65 | |
* | |
* Run every day at 6 am | |
* 0 6 * * * * php /path/to/site/cmd/cron.php | |
* | |
*/ | |
if ( ! empty($args)) | |
{ | |
foreach($args as $param) | |
{ | |
if (strpos($param, '--') === 0) | |
{ | |
$param_string = substr($param, 2); | |
if ( ! empty($param_string)) | |
{ | |
if (strpos($param_string, '=') !== false) | |
{ | |
list($key, $value) = explode('=', $param_string); | |
$_GET[$key] = $value; | |
} | |
else | |
{ | |
$_GET[$param_string] = null; | |
} | |
} | |
} | |
} | |
} | |
if(isset($_GET['site_url']) AND isset($_GET['key']) AND isset($_GET['action'])) | |
{ | |
if($_GET['action'] == 'export') | |
{ | |
exec("wget --quiet --output-document=cmd/cron_output.html '". rtrim($_GET['site_url'], '/') ."/?ACT=65&key=". $_GET['key'] ."'"); | |
} | |
if($_GET['action'] == 'import') | |
{ | |
exec("wget --quiet --output-document=cmd/cron_output.html '". rtrim($_GET['site_url'], '/') ."/?ACT=73&key=". $_GET['key'] ."'"); | |
} | |
if($_GET['action'] == 'update_literature_dates') | |
{ | |
exec("wget --quiet --output-document=cmd/cron_output.html '". rtrim($_GET['site_url'], '/') ."/?ACT=105&key=". $_GET['key'] ."'"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment