19 declare(strict_types=1);
42 private \ILIAS\DI\RBACServices
$rbac;
54 $this->
lng = $DIC->language();
55 $this->
ctrl = $DIC->ctrl();
57 $this->tpl = $DIC->ui()->mainTemplate();
58 $this->uiFactory = $DIC->ui()->factory();
59 $this->uiRenderer = $DIC->ui()->renderer();
60 $this->uiService = $DIC->uiService();
61 $this->
rbac = $DIC->rbac();
62 $this->error = $DIC[
'ilErr'];
63 $this->httpRequest = $DIC->http()->wrapper();
65 $this->actor = $DIC->user();
66 $this->cronRepository = $DIC->cron()->repository();
67 $this->cronManager = $DIC->cron()->manager();
69 $this->
lng->loadLanguageModule(
'cron');
70 $this->
lng->loadLanguageModule(
'cmps');
83 bool $forceRetrieval =
false,
89 if ($forceRetrieval || $this->httpRequest->query()->has($key)) {
90 return $this->httpRequest->query()->retrieve($key, $trafo);
97 if ($forceRetrieval || $this->httpRequest->post()->has($key)) {
98 return $this->httpRequest->post()->retrieve($key, $trafo);
104 if ($forceRetrieval && $exc) {
108 return $default ?? null;
114 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
117 $class = $this->
ctrl->getNextClass($this);
120 switch (strtolower($class)) {
121 case strtolower(ilPropertyFormGUI::class):
124 $this->
ctrl->forwardCommand($form);
128 $cmd = $this->
ctrl->getCmd(
'render');
134 $tstamp = $this->
lng->txt(
'cronjob_last_start_unknown');
135 if ($this->
settings->get(
'last_cronjob_start_ts')) {
138 $this->
settings->get(
'last_cronjob_start_ts'),
144 $message = $this->uiFactory->messageBox()->info($this->
lng->txt(
'cronjob_last_start') .
': ' . $tstamp);
146 $cronJobs = $this->cronRepository->findAll();
154 $filter = $tableFilterMediator->filter($this->
ctrl->getFormAction(
163 $this->cronRepository,
167 $this->tpl->setContent(implode(
'', [
168 $this->uiRenderer->render([
$message, $filter]),
170 $tableFilterMediator->filteredJobs(
180 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
185 $this->
ctrl->redirect($this,
'render');
188 if ($a_form === null) {
192 $this->tpl->setContent($a_form->getHTML());
197 switch ($scheduleTypeId) {
199 return $this->
lng->txt(
'cron_schedule_daily');
202 return $this->
lng->txt(
'cron_schedule_weekly');
205 return $this->
lng->txt(
'cron_schedule_monthly');
208 return $this->
lng->txt(
'cron_schedule_quarterly');
211 return $this->
lng->txt(
'cron_schedule_yearly');
214 return sprintf($this->
lng->txt(
'cron_schedule_in_minutes'),
'x');
217 return sprintf($this->
lng->txt(
'cron_schedule_in_hours'),
'x');
220 return sprintf($this->
lng->txt(
'cron_schedule_in_days'),
'x');
224 'The passed argument %s is invalid!',
225 var_export($scheduleTypeId,
true)
231 switch ($scheduleTypeId) {
243 'The passed argument %s is invalid!',
244 var_export($scheduleTypeId,
true)
250 return in_array($scheduleTypeId, [
259 $job = $this->cronRepository->getJobInstanceById($a_job_id);
261 $this->
ctrl->redirect($this,
'render');
264 $this->
ctrl->setParameter($this,
'jid', $a_job_id);
266 $jobs_data = $this->cronRepository->getCronJobData($job->getId());
267 $job_data = $jobs_data[0];
270 $form->setFormAction($this->
ctrl->getFormAction($this,
'update'));
271 $form->setTitle($this->
lng->txt(
'cron_action_edit') .
': "' . $job->getTitle() .
'"');
273 if ($job->hasFlexibleSchedule()) {
275 $type->setRequired(
true);
276 $type->setValue((
string) $job_data[
'schedule_type']);
278 foreach ($job->getAllScheduleTypes() as
$typeId) {
279 if (!in_array(
$typeId, $job->getValidScheduleTypes(),
true)) {
287 $type->addOption($option);
289 if (in_array($typeId, $job->getScheduleTypesWithValues(),
true)) {
291 $this->
lng->txt(
'cron_schedule_value'),
295 $scheduleValue->setRequired(
true);
296 $scheduleValue->setSize(5);
297 if ((
int) $job_data[
'schedule_type'] === $typeId) {
298 $scheduleValue->setValue($job_data[
'schedule_value'] === null ? null : (
string) $job_data[
'schedule_value']);
300 $option->addSubItem($scheduleValue);
304 $form->addItem(
$type);
307 if ($job->hasCustomSettings()) {
308 $job->addCustomSettingsToForm($form);
311 $form->addCommandButton(
'update', $this->
lng->txt(
'save'));
312 $form->addCommandButton(
'render', $this->
lng->txt(
'cancel'));
320 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
325 $this->
ctrl->redirect($this,
'render');
329 if ($form->checkInput()) {
330 $job = $this->cronRepository->getJobInstanceById($job_id);
333 if ($job->hasCustomSettings() && !$job->saveCustomSettings($form)) {
337 if (
$valid && $job->hasFlexibleSchedule()) {
338 $type = (
int) $form->getInput(
'type');
341 $value = (
int) $form->getInput($this->getScheduleValueFormElementName(
$type));
349 $this->cronRepository->updateJobSchedule($job,
$type, $value);
353 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_edit_success'),
true);
354 $this->
ctrl->redirect($this,
'render');
359 $form->setValuesByPost();
363 public function run(): void
371 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
376 if ($this->cronManager->runJobManual($job_id, $this->actor)) {
377 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_run_success'),
true);
379 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'cron_action_run_fail'),
true);
383 $this->
ctrl->redirect($this,
'render');
394 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
399 foreach ($jobs as $job) {
400 if ($this->cronManager->isJobInactive($job->getId())) {
401 $this->cronManager->resetJob($job, $this->actor);
405 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_activate_success'),
true);
407 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'no_checkbox'),
true);
410 $this->
ctrl->redirect($this,
'render');
421 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
426 foreach ($jobs as $job) {
427 if ($this->cronManager->isJobActive($job->getId())) {
428 $this->cronManager->deactivateJob($job, $this->actor,
true);
432 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_deactivate_success'),
true);
434 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'no_checkbox'),
true);
437 $this->
ctrl->redirect($this,
'render');
448 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
453 foreach ($jobs as $job) {
454 $this->cronManager->resetJob($job, $this->actor);
456 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_reset_success'),
true);
458 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'no_checkbox'),
true);
461 $this->
ctrl->redirect($this,
'render');
477 $this->
refinery->kindlyTo()->string()
483 foreach ($job_ids as $job_id) {
484 $job = $this->cronRepository->getJobInstanceById($job_id);
486 $res[$job_id] = $job;
493 protected function confirm(
string $a_action): void
496 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
501 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'no_checkbox'),
true);
502 $this->
ctrl->redirect($this,
'render');
505 if (
'run' === $a_action) {
506 $jobs = array_filter($jobs,
static function (
ilCronJob $job):
bool {
511 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'cron_no_executable_job_selected'),
true);
512 $this->
ctrl->redirect($this,
'render');
518 if (1 === count($jobs)) {
519 $jobKeys = array_keys($jobs);
520 $job_id = array_pop($jobKeys);
521 $job = array_pop($jobs);
522 $title = $job->getTitle();
524 $title = preg_replace(
'[^A-Za-z0-9_\-]',
'', $job->getId());
527 $cgui->setHeaderText(sprintf(
528 $this->
lng->txt(
'cron_action_' . $a_action .
'_sure'),
532 $this->
ctrl->setParameter($this,
'jid', $job_id);
534 $cgui->setHeaderText($this->
lng->txt(
'cron_action_' . $a_action .
'_sure_multi'));
536 foreach ($jobs as $job_id => $job) {
537 $cgui->addItem(
'mjid[]', $job_id, $job->getTitle());
541 $cgui->setFormAction($this->
ctrl->getFormAction($this,
'confirmed' . ucfirst($a_action)));
542 $cgui->setCancel($this->
lng->txt(
'cancel'),
'render');
543 $cgui->setConfirm($this->
lng->txt(
'cron_action_' . $a_action),
'confirmed' . ucfirst($a_action));
545 $this->tpl->setContent($cgui->getHTML());
552 $data = $this->cronRepository->getCronJobData();
553 foreach (
$data as $item) {
554 $job = $this->cronRepository->getJobInstance(
559 if (!is_null($job)) {
560 $job->addToExternalSettingsForm($a_form_id, $fields, (
bool) $item[
'job_status']);
564 if ($fields !== []) {
573 return $form_elements;
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An entity that renders components to a string output.
getScheduleValueFormElementName(int $scheduleTypeId)
ILIAS Refinery Factory $refinery
Class ChatMainBarProvider .
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const SCHEDULE_TYPE_IN_MINUTES
This will be replaced with an ENUM in ILIAS 9
initEditForm(string $a_job_id)
ilGlobalTemplateInterface $tpl
const SCHEDULE_TYPE_MONTHLY
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_WEEKLY
This will be replaced with an ENUM in ILIAS 9
confirm(string $a_action)
const SCHEDULE_TYPE_IN_DAYS
This will be replaced with an ENUM in ILIAS 9
addToExternalSettingsForm(int $a_form_id)
hasScheduleValue(int $scheduleTypeId)
const SCHEDULE_TYPE_YEARLY
This will be replaced with an ENUM in ILIAS 9
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Error Handling & global info handling uses PEAR error class.
__construct(Container $dic, ilPlugin $plugin)
ILIAS DI RBACServices $rbac
edit(ilPropertyFormGUI $a_form=null)
const SCHEDULE_TYPE_DAILY
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_QUARTERLY
This will be replaced with an ENUM in ILIAS 9
getScheduleTypeFormElementName(int $scheduleTypeId)
getRequestValue(string $key, \ILIAS\Refinery\Transformation $trafo, bool $forceRetrieval=false, $default=null)
const SCHEDULE_TYPE_IN_HOURS
This will be replaced with an ENUM in ILIAS 9
ilCronManager $cronManager
WrapperFactory $httpRequest
ilCronJobRepository $cronRepository
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...