19 declare(strict_types=1);
43 private readonly \ILIAS\DI\RBACServices
$rbac;
55 $this->
lng = $DIC->language();
56 $this->
ctrl = $DIC->ctrl();
58 $this->tpl = $DIC->ui()->mainTemplate();
59 $this->uiFactory = $DIC->ui()->factory();
60 $this->uiRenderer = $DIC->ui()->renderer();
61 $this->uiService = $DIC->uiService();
62 $this->
rbac = $DIC->rbac();
63 $this->error = $DIC[
'ilErr'];
64 $this->httpRequest = $DIC->http()->wrapper();
66 $this->actor = $DIC->user();
67 $this->cronRepository = $DIC->cron()->repository();
68 $this->cronManager = $DIC->cron()->manager();
70 $this->
lng->loadLanguageModule(
'cron');
71 $this->
lng->loadLanguageModule(
'cmps');
81 bool $forceRetrieval =
false,
87 if ($forceRetrieval || $this->httpRequest->query()->has($key)) {
88 return $this->httpRequest->query()->retrieve($key, $trafo);
95 if ($forceRetrieval || $this->httpRequest->post()->has($key)) {
96 return $this->httpRequest->post()->retrieve($key, $trafo);
102 if ($forceRetrieval && $exc) {
106 return $default ?? null;
112 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
115 $class = $this->
ctrl->getNextClass($this);
118 switch (strtolower($class)) {
119 case strtolower(ilPropertyFormGUI::class):
122 $this->
ctrl->forwardCommand($form);
126 $cmd = $this->
ctrl->getCmd(
'render');
132 $tstamp = $this->
lng->txt(
'cronjob_last_start_unknown');
133 if ($this->
settings->get(
'last_cronjob_start_ts')) {
136 $this->
settings->get(
'last_cronjob_start_ts'),
142 $message = $this->uiFactory->messageBox()->info($this->
lng->txt(
'cronjob_last_start') .
': ' . $tstamp);
144 $cronJobs = $this->cronRepository->findAll();
152 $filter = $tableFilterMediator->filter($this->
ctrl->getFormAction(
161 $this->cronRepository,
165 $this->tpl->setContent(implode(
'', [
166 $this->uiRenderer->render([
$message, $filter]),
168 $tableFilterMediator->filteredJobs(
178 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
183 $this->
ctrl->redirect($this,
'render');
186 if ($a_form === null) {
190 $this->tpl->setContent($a_form->getHTML());
195 return match ($schedule_type) {
196 CronJobScheduleType::SCHEDULE_TYPE_DAILY => $this->
lng->txt(
'cron_schedule_daily'),
197 CronJobScheduleType::SCHEDULE_TYPE_WEEKLY => $this->
lng->txt(
'cron_schedule_weekly'),
198 CronJobScheduleType::SCHEDULE_TYPE_MONTHLY => $this->
lng->txt(
'cron_schedule_monthly'),
199 CronJobScheduleType::SCHEDULE_TYPE_QUARTERLY => $this->
lng->txt(
'cron_schedule_quarterly'),
201 CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES => sprintf($this->
lng->txt(
'cron_schedule_in_minutes'),
'x'),
202 CronJobScheduleType::SCHEDULE_TYPE_IN_HOURS => sprintf($this->
lng->txt(
'cron_schedule_in_hours'),
'x'),
203 CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS => sprintf($this->
lng->txt(
'cron_schedule_in_days'),
'x'),
209 return match ($schedule_type) {
210 CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES =>
'smini',
211 CronJobScheduleType::SCHEDULE_TYPE_IN_HOURS =>
'shri',
212 CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS =>
'sdyi',
214 'The passed argument %s is invalid!',
215 var_export($schedule_type,
true)
222 return in_array($schedule_type, [
223 CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES,
224 CronJobScheduleType::SCHEDULE_TYPE_IN_HOURS,
225 CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS
231 $job = $this->cronRepository->getJobInstanceById($a_job_id);
233 $this->
ctrl->redirect($this,
'render');
236 $this->
ctrl->setParameter($this,
'jid', $a_job_id);
238 $jobs_data = $this->cronRepository->getCronJobData($job->getId());
239 $job_data = $jobs_data[0];
242 $form->setFormAction($this->
ctrl->getFormAction($this,
'update'));
243 $form->setTitle($this->
lng->txt(
'cron_action_edit') .
': "' . $job->getTitle() .
'"');
245 if ($job->hasFlexibleSchedule()) {
248 $type->setValue($job_data[
'schedule_type'] === null ? null : (
string) $job_data[
'schedule_type']);
250 foreach ($job->getAllScheduleTypes() as $schedule_type) {
251 if (!in_array($schedule_type, $job->getValidScheduleTypes(),
true)) {
257 (
string) $schedule_type->value
259 $type->addOption($option);
261 if (in_array($schedule_type, $job->getScheduleTypesWithValues(),
true)) {
263 $this->
lng->txt(
'cron_schedule_value'),
266 $scheduleValue->allowDecimals(
false);
267 $scheduleValue->setRequired(
true);
268 $scheduleValue->setSize(5);
269 if (is_numeric($job_data[
'schedule_type']) &&
270 CronJobScheduleType::tryFrom((
int) $job_data[
'schedule_type']) === $schedule_type) {
271 $scheduleValue->setValue($job_data[
'schedule_value'] === null ? null : (
string) $job_data[
'schedule_value']);
273 $option->addSubItem($scheduleValue);
277 $form->addItem($type);
280 if ($job->hasCustomSettings()) {
281 $job->addCustomSettingsToForm($form);
284 $form->addCommandButton(
'update', $this->
lng->txt(
'save'));
285 $form->addCommandButton(
'render', $this->
lng->txt(
'cancel'));
293 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
298 $this->
ctrl->redirect($this,
'render');
302 if ($form->checkInput()) {
303 $job = $this->cronRepository->getJobInstanceById($job_id);
306 if ($job->hasCustomSettings() && !$job->saveCustomSettings($form)) {
310 if (
$valid && $job->hasFlexibleSchedule()) {
312 $value = match (
true) {
313 $this->
hasScheduleValue($type) => (
int) $form->getInput($this->getScheduleValueFormElementName($type)),
317 $this->cronRepository->updateJobSchedule($job, $type, $value);
321 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_edit_success'),
true);
322 $this->
ctrl->redirect($this,
'render');
327 $form->setValuesByPost();
331 public function run(): void
339 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
344 if ($this->cronManager->runJobManual($job_id, $this->actor)) {
345 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_run_success'),
true);
347 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'cron_action_run_fail'),
true);
351 $this->
ctrl->redirect($this,
'render');
362 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
367 foreach ($jobs as $job) {
368 if ($this->cronManager->isJobInactive($job->getId())) {
369 $this->cronManager->resetJob($job, $this->actor);
373 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_activate_success'),
true);
375 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'no_checkbox'),
true);
378 $this->
ctrl->redirect($this,
'render');
389 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
394 foreach ($jobs as $job) {
395 if ($this->cronManager->isJobActive($job->getId())) {
396 $this->cronManager->deactivateJob($job, $this->actor,
true);
400 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_deactivate_success'),
true);
402 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'no_checkbox'),
true);
405 $this->
ctrl->redirect($this,
'render');
416 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
421 foreach ($jobs as $job) {
422 $this->cronManager->resetJob($job, $this->actor);
424 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'cron_action_reset_success'),
true);
426 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'no_checkbox'),
true);
429 $this->
ctrl->redirect($this,
'render');
445 $this->
refinery->kindlyTo()->string()
451 foreach ($job_ids as $job_id) {
452 $job = $this->cronRepository->getJobInstanceById($job_id);
454 $res[$job_id] = $job;
461 protected function confirm(
string $a_action): void
464 $this->error->raiseError($this->
lng->txt(
'no_permission'), $this->error->WARNING);
469 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'no_checkbox'),
true);
470 $this->
ctrl->redirect($this,
'render');
473 if (
'run' === $a_action) {
474 $jobs = array_filter($jobs,
static function (
ilCronJob $job):
bool {
479 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'cron_no_executable_job_selected'),
true);
480 $this->
ctrl->redirect($this,
'render');
486 if (1 === count($jobs)) {
487 $jobKeys = array_keys($jobs);
488 $job_id = array_pop($jobKeys);
489 $job = array_pop($jobs);
490 $title = $job->getTitle();
492 $title = preg_replace(
'[^A-Za-z0-9_\-]',
'', $job->getId());
495 $cgui->setHeaderText(sprintf(
496 $this->
lng->txt(
'cron_action_' . $a_action .
'_sure'),
500 $this->
ctrl->setParameter($this,
'jid', $job_id);
502 $cgui->setHeaderText($this->
lng->txt(
'cron_action_' . $a_action .
'_sure_multi'));
504 foreach ($jobs as $job_id => $job) {
505 $cgui->addItem(
'mjid[]', $job_id, $job->getTitle());
509 $cgui->setFormAction($this->
ctrl->getFormAction($this,
'confirmed' . ucfirst($a_action)));
510 $cgui->setCancel($this->
lng->txt(
'cancel'),
'render');
511 $cgui->setConfirm($this->
lng->txt(
'cron_action_' . $a_action),
'confirmed' . ucfirst($a_action));
513 $this->tpl->setContent($cgui->getHTML());
520 $data = $this->cronRepository->getCronJobData();
521 foreach (
$data as $item) {
522 $job = $this->cronRepository->getJobInstance(
527 if (!is_null($job)) {
528 $job->addToExternalSettingsForm($a_form_id, $fields, (
bool) $item[
'job_status']);
532 if ($fields !== []) {
541 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.
readonly ilCronJobRepository $cronRepository
readonly ilCtrlInterface $ctrl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readonly ILIAS Refinery Factory $refinery
Class ChatMainBarProvider .
readonly Factory $uiFactory
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)
initEditForm(string $a_job_id)
readonly ilCronManager $cronManager
readonly ilGlobalTemplateInterface $tpl
readonly ilSetting $settings
readonly ilErrorHandling $error
readonly Renderer $uiRenderer
confirm(string $a_action)
readonly ilObjUser $actor
readonly ILIAS DI RBACServices $rbac
getScheduleTypeFormElementName(CronJobScheduleType $schedule_type)
readonly ilUIService $uiService
getScheduleValueFormElementName(CronJobScheduleType $schedule_type)
hasScheduleValue(CronJobScheduleType $schedule_type)
addToExternalSettingsForm(int $a_form_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Error Handling & global info handling.
readonly WrapperFactory $httpRequest
edit(ilPropertyFormGUI $a_form=null)
getRequestValue(string $key, \ILIAS\Refinery\Transformation $trafo, bool $forceRetrieval=false, $default=null)