mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 15:32:13 +00:00
109 lines
2.7 KiB
PHP
109 lines
2.7 KiB
PHP
|
<?php
|
|||
|
if(isset($_SERVER['SEEDDMS_HOME'])) {
|
|||
|
ini_set('include_path', $_SERVER['SEEDDMS_HOME'].'/utils'. PATH_SEPARATOR .ini_get('include_path'));
|
|||
|
$myincpath = $_SERVER['SEEDDMS_HOME'];
|
|||
|
} else {
|
|||
|
ini_set('include_path', dirname($argv[0]). PATH_SEPARATOR .ini_get('include_path'));
|
|||
|
$myincpath = dirname($argv[0]);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function usage() { /* {{{ */
|
|||
|
echo "Usage:\n";
|
|||
|
echo " seeddms-schedulercli [-h] [-v] [--config <file>]\n";
|
|||
|
echo "\n";
|
|||
|
echo "Description:\n";
|
|||
|
echo " Check for scheduled tasks.\n";
|
|||
|
echo "\n";
|
|||
|
echo "Options:\n";
|
|||
|
echo " -h, --help: print usage information and exit.\n";
|
|||
|
echo " -v, --version: print version and exit.\n";
|
|||
|
echo " --config: set alternative config file.\n";
|
|||
|
echo " --mode: set mode of operation (run, check, list).\n";
|
|||
|
} /* }}} */
|
|||
|
|
|||
|
$version = "0.0.1";
|
|||
|
$shortoptions = "hvc";
|
|||
|
$longoptions = array('help', 'version', 'config:', 'mode:');
|
|||
|
if(false === ($options = getopt($shortoptions, $longoptions))) {
|
|||
|
usage();
|
|||
|
exit(0);
|
|||
|
}
|
|||
|
|
|||
|
/* Print help and exit */
|
|||
|
if(isset($options['h']) || isset($options['help'])) {
|
|||
|
usage();
|
|||
|
exit(0);
|
|||
|
}
|
|||
|
|
|||
|
/* Print version and exit */
|
|||
|
if(isset($options['v']) || isset($options['verѕion'])) {
|
|||
|
echo $version."\n";
|
|||
|
exit(0);
|
|||
|
}
|
|||
|
|
|||
|
/* Set alternative config file */
|
|||
|
if(isset($options['config'])) {
|
|||
|
define('SEEDDMS_CONFIG_FILE', $options['config']);
|
|||
|
}
|
|||
|
|
|||
|
$mode = 'list';
|
|||
|
if(isset($options['mode'])) {
|
|||
|
if(!in_array($options['mode'], array('run', 'check', 'list'))) {
|
|||
|
usage();
|
|||
|
exit(1);
|
|||
|
}
|
|||
|
$mode = $options['mode'];
|
|||
|
}
|
|||
|
|
|||
|
include($myincpath."/inc/inc.Settings.php");
|
|||
|
include($myincpath."/inc/inc.Init.php");
|
|||
|
include($myincpath."/inc/inc.Extension.php");
|
|||
|
include($myincpath."/inc/inc.DBInit.php");
|
|||
|
include($myincpath."/inc/inc.Scheduler.php");
|
|||
|
|
|||
|
$scheduler = new SeedDMS_Scheduler($db);
|
|||
|
$tasks = $scheduler->getTasks();
|
|||
|
|
|||
|
foreach($tasks as $task) {
|
|||
|
if(is_object($taskobj = $GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()][$task->getTask()])) {
|
|||
|
switch($mode) {
|
|||
|
case "run":
|
|||
|
if(method_exists($taskobj, 'execute')) {
|
|||
|
if(!$task->getDisabled()) {
|
|||
|
if($taskobj->execute($task, $dms)) {
|
|||
|
$task->updateLastNextRun();
|
|||
|
} else {
|
|||
|
echo "Execution of task failed, task has been disabled\n";
|
|||
|
$task->setDisabled(1);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case "check":
|
|||
|
echo "Checking ".$task->getExtension()."::".$task->getTask().":\n";
|
|||
|
if(!method_exists($taskobj, 'execute')) {
|
|||
|
echo " Missing method execute()\n";
|
|||
|
}
|
|||
|
if(get_parent_class($taskobj) != 'SeedDMS_SchedulerTaskBase') {
|
|||
|
echo " wrong parent class\n";
|
|||
|
}
|
|||
|
break;
|
|||
|
case "list":
|
|||
|
if(!$task->getDisabled()) {
|
|||
|
if($task->isDue())
|
|||
|
echo "*";
|
|||
|
else
|
|||
|
echo " ";
|
|||
|
} else {
|
|||
|
echo "-";
|
|||
|
}
|
|||
|
echo " ".$task->getExtension()."::".$task->getTask()."";
|
|||
|
echo " ".$task->getNextRun();
|
|||
|
echo "\n";
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|