mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 15:32:13 +00:00
finish running cron jobs via web, result is returned as json
This commit is contained in:
parent
29a6882106
commit
7b87cc355d
|
@ -32,8 +32,16 @@ class SeedDMS_Controller_Cron extends SeedDMS_Controller_Common {
|
|||
$scheduler = new SeedDMS_Scheduler($db);
|
||||
$tasks = $scheduler->getTasks();
|
||||
|
||||
$jsonarr = [];
|
||||
foreach($tasks as $task) {
|
||||
if(isset($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()]) && is_object($taskobj = resolveTask($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()][$task->getTask()]))) {
|
||||
$arr = array(
|
||||
'extension'=>$task->getExtension(),
|
||||
'name'=>$task->getTask(),
|
||||
'mode'=>$mode,
|
||||
'disabled' => (bool) $task->getDisabled(),
|
||||
'isdue' => $task->isDue(),
|
||||
);
|
||||
switch($mode) {
|
||||
case "run":
|
||||
case "dryrun":
|
||||
|
@ -48,19 +56,47 @@ class SeedDMS_Controller_Cron extends SeedDMS_Controller_Common {
|
|||
$task->updateLastNextRun();
|
||||
if($taskobj->execute($task)) {
|
||||
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." successful.");
|
||||
$arr['success'] = true;
|
||||
} else {
|
||||
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed, task has been disabled.", PEAR_LOG_ERR);
|
||||
$arr['success'] = false;
|
||||
$task->setDisabled(1);
|
||||
}
|
||||
} elseif($mode == 'dryrun') {
|
||||
echo "Running ".$task->getExtension()."::".$task->getTask()." in dry mode\n";
|
||||
$arr['success'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "check":
|
||||
$arr['error'] = false;
|
||||
if(!method_exists($taskobj, 'execute')) {
|
||||
$arr['error'] = true;
|
||||
$arr['messages'][] = 'Missing method execute()';
|
||||
}
|
||||
if(get_parent_class($taskobj) != 'SeedDMS_SchedulerTaskBase') {
|
||||
$arr['error'] = true;
|
||||
$arr['error'][] = "Wrong parent class";
|
||||
}
|
||||
break;
|
||||
case "list":
|
||||
default:
|
||||
header("Content-Type: application/json");
|
||||
$arr['nextrun']=$task->getNextRun();
|
||||
$arr['frequency']=$task->getFrequency();
|
||||
$arr['params']=array();
|
||||
if($params = $task->getParameter()) {
|
||||
foreach($params as $key=>$value) {
|
||||
$p = $taskobj->getAdditionalParamByName($key);
|
||||
$arr['params'][$key] = ($p['type'] == 'password') ? '*******' : $value;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
$jsonarr[] = $arr;
|
||||
}
|
||||
}
|
||||
echo json_encode($jsonarr);
|
||||
|
||||
return true;
|
||||
} /* }}} */
|
||||
|
|
|
@ -35,13 +35,18 @@ include("../inc/inc.BasicAuthentication.php");
|
|||
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||
$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user));
|
||||
|
||||
header("Content-Type: text/plain");
|
||||
if($user->getLogin() != 'cli_scheduler') {
|
||||
header('WWW-Authenticate: Basic realm="'.$settings->_siteName.'"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
echo "Wrong user";
|
||||
exit;
|
||||
}
|
||||
$mode = 'list';
|
||||
if(!empty($_GET['mode']) && in_array($_GET['mode'], array('list', 'run', 'dryrun', 'check')))
|
||||
$mode = $_GET['mode'];
|
||||
|
||||
$controller->setParam('settings', $settings);
|
||||
$controller->setParam('mode', 'dryrun');
|
||||
$controller->setParam('mode', $mode);
|
||||
if(!$controller->run()) {
|
||||
echo getMLText("error_occured");
|
||||
exit;
|
||||
|
|
Loading…
Reference in New Issue
Block a user