mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-07-15 08:58:10 +00:00
require basic auth and login as user cli_scheduler
This commit is contained in:
parent
31fda7e60e
commit
542a6cb045
|
@ -24,8 +24,9 @@ class SeedDMS_Controller_Cron extends SeedDMS_Controller_Common {
|
||||||
|
|
||||||
public function run() { /* {{{ */
|
public function run() { /* {{{ */
|
||||||
$dms = $this->params['dms'];
|
$dms = $this->params['dms'];
|
||||||
|
$user = $this->params['user'];
|
||||||
$settings = $this->params['settings'];
|
$settings = $this->params['settings'];
|
||||||
$mode = 'run'; //$this->params['mode'];
|
$mode = $this->params['mode'];
|
||||||
$db = $dms->getDb();
|
$db = $dms->getDb();
|
||||||
|
|
||||||
$scheduler = new SeedDMS_Scheduler($db);
|
$scheduler = new SeedDMS_Scheduler($db);
|
||||||
|
@ -35,19 +36,24 @@ class SeedDMS_Controller_Cron extends SeedDMS_Controller_Common {
|
||||||
if(isset($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()]) && is_object($taskobj = resolveTask($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()][$task->getTask()]))) {
|
if(isset($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()]) && is_object($taskobj = resolveTask($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()][$task->getTask()]))) {
|
||||||
switch($mode) {
|
switch($mode) {
|
||||||
case "run":
|
case "run":
|
||||||
|
case "dryrun":
|
||||||
if(method_exists($taskobj, 'execute')) {
|
if(method_exists($taskobj, 'execute')) {
|
||||||
if(!$task->getDisabled() && $task->isDue()) {
|
if(!$task->getDisabled() && $task->isDue()) {
|
||||||
if($user = $dms->getUserByLogin('cli_scheduler')) {
|
if($mode == 'run') {
|
||||||
|
/* Schedule the next run right away to prevent a second execution
|
||||||
|
* of the task when the cron job of the scheduler is called before
|
||||||
|
* the last run was finished. The task itself can still be scheduled
|
||||||
|
* to fast, but this is up to the admin of seeddms.
|
||||||
|
*/
|
||||||
|
$task->updateLastNextRun();
|
||||||
if($taskobj->execute($task)) {
|
if($taskobj->execute($task)) {
|
||||||
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." successful.");
|
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." successful.");
|
||||||
$task->updateLastNextRun();
|
|
||||||
} else {
|
} else {
|
||||||
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed, task has been disabled.", PEAR_LOG_ERR);
|
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed, task has been disabled.", PEAR_LOG_ERR);
|
||||||
$task->setDisabled(1);
|
$task->setDisabled(1);
|
||||||
}
|
}
|
||||||
} else {
|
} elseif($mode == 'dryrun') {
|
||||||
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed because of missing user 'cli_scheduler'. Task has been disabled.", PEAR_LOG_ERR);
|
echo "Running ".$task->getExtension()."::".$task->getTask()." in dry mode\n";
|
||||||
$task->setDisabled(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +62,7 @@ class SeedDMS_Controller_Cron extends SeedDMS_Controller_Common {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,18 @@ include("../inc/inc.ClassNotificationService.php");
|
||||||
include("../inc/inc.ClassEmailNotify.php");
|
include("../inc/inc.ClassEmailNotify.php");
|
||||||
include("../inc/inc.ClassController.php");
|
include("../inc/inc.ClassController.php");
|
||||||
include("../inc/inc.Scheduler.php");
|
include("../inc/inc.Scheduler.php");
|
||||||
|
include("../inc/inc.BasicAuthentication.php");
|
||||||
|
|
||||||
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||||
$controller = Controller::factory($tmp[1], array('dms'=>$dms));
|
$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user));
|
||||||
|
|
||||||
$controller->setParam('settings', $settings);
|
|
||||||
header("Content-Type: text/plain");
|
header("Content-Type: text/plain");
|
||||||
|
if($user->getLogin() != 'cli_scheduler') {
|
||||||
|
echo "Wrong user";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$controller->setParam('settings', $settings);
|
||||||
|
$controller->setParam('mode', 'dryrun');
|
||||||
if(!$controller->run()) {
|
if(!$controller->run()) {
|
||||||
echo getMLText("error_occured");
|
echo getMLText("error_occured");
|
||||||
exit;
|
exit;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user