Beispiel #1
0
$argv = $_SERVER['argv'];
$opts = getopt('hl', array('help', 'list'));
if (isset($opts['l']) || isset($opts['list'])) {
    $tasks = CronjobTask::findBySql('1');
    foreach ($tasks as $task) {
        $description = call_user_func(array($task->class, 'getDescription'));
        fwrite(STDOUT, sprintf('%s %s' . PHP_EOL, $task->id, studip_utf8encode($description)));
    }
    exit(0);
}
if ($argc < 2 || isset($opts['h']) || isset($opts['help'])) {
    fwrite(STDOUT, 'Usage: ' . basename(__FILE__) . ' [--help] [--list] <task_id> [last_result]' . PHP_EOL);
    exit(0);
}
$id = $_SERVER['argv'][1];
$last_result = $argc > 2 ? $_SERVER['argv'][2] : null;
$task = CronjobTask::find($id);
if (!$task) {
    fwrite(STDOUT, 'Unknown task id' . PHP_EOL);
    exit(0);
}
if (!file_exists($GLOBALS['STUDIP_BASE_PATH'] . '/' . $task->filename)) {
    fwrite(STDOUT, 'Invalid task, unknown filename "' . $task->filename . '"' . PHP_EOL);
    exit(0);
}
require_once $task->filename;
if (!class_exists($task->class)) {
    fwrite(STDOUT, 'Invalid task, unknown class "' . $task->class . '"' . PHP_EOL);
    exit(0);
}
$task->engage($last_result);
Beispiel #2
0
    /**
     * Deletes a tasks.
     *
     * @param String $id Id of the task in question
     * @param int    $page Return to this page after deleting (optional)
     */
    public function delete_action($id, $page = 1)
    {
        $task = CronjobTask::find($id);
        $deleted = $task->schedules->count();
        $task->delete();

        $message = sprintf(_('Die Aufgabe und %u Cronjob(s) wurden gelöscht.'), $deleted);
        PageLayout::postMessage(MessageBox::success($message));

        $this->redirect('admin/cronjobs/tasks/index/' . $page);
    }
 /**
  * Unregisters a previously registered task.
  *
  * @param String $task_id Id of the task to be unregistered
  * @return CronjobScheduler to allow chaining
  * @throws InvalidArgumentException when no task with the given id exists
  */
 public function unregisterTask($task_id)
 {
     $task = CronjobTask::find($task_id);
     if ($task === null) {
         $message = sprintf('A task with the id "%s" does not exist.', $task_id);
         throw new InvalidArgumentException($message);
     }
     $task->delete();
     return $this;
 }
Beispiel #4
0
 /**
  * Registers the cronjob and/or returns the corresponding task.
  *
  * @return CronjobTask Task for this cronjob
  */
 public static function register()
 {
     $class_name = get_called_class();
     $reflection = new ReflectionClass($class_name);
     $task_id = CronjobScheduler::getInstance()->registerTask($reflection->newInstance());
     return CronjobTask::find($task_id);
 }