ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCronManagerGUI Class Reference

ilCronManagerGUI: ilPropertyFormGUI ilCronManagerGUI: ilAdministrationGUI More...

+ Collaboration diagram for ilCronManagerGUI:

Public Member Functions

 executeCommand ()
 
 edit (?ILIAS\UI\Component\Input\Container\Form\Form $form=null)
 
 editLegacy (?ilPropertyFormGUI $a_form=null)
 
 update ()
 
 updateLegacy ()
 
 run ()
 
 confirmedRun ()
 
 activate ()
 
 confirmedActivate ()
 
 deactivate ()
 
 confirmedDeactivate ()
 
 reset ()
 
 confirmedReset ()
 
 addToExternalSettingsForm (int $a_form_id)
 

Data Fields

const FORM_PARAM_MAIN_SECTION = 'main'
 
const FORM_PARAM_JOB_INPUT = 'additional_job_input'
 
const FORM_PARAM_GROUP_SCHEDULE = 'schedule'
 

Protected Member Functions

 render ()
 
 getScheduleValueFormElementName (JobScheduleType $schedule_type)
 
 hasScheduleValue (JobScheduleType $schedule_type)
 
 initEditForm (?CronJob $job)
 
 initLegacyEditForm (?CronJob $job)
 
 getMultiActionData ()
 
 confirm (string $a_action)
 

Private Member Functions

 retrieveTableActionJobIds ()
 
 getTableActionParameterName ()
 
 addProblematicItemsInfo (\ILIAS\Cron\Job\JobCollection $filtered_jobs, \ILIAS\UI\Component\MessageBox\MessageBox $message, array $components)
 
 getJobIdParameterName ()
 
 getRequestValue (string $key, \ILIAS\Refinery\Transformation $trafo, bool $force_retrieval=false, $default=null)
 
 handleTableActions ()
 
 getScheduleTypeFormElementName (JobScheduleType $schedule_type)
 

Private Attributes

const TABLE_ACTION_NAMESPACE = ['cron', 'jobs']
 
const TABLE_ACTION_PARAM_NAME = 'table_action'
 
const TABLE_ACTION_IDENTIFIER_NAME = 'jid'
 
const FORM_PARAM_SCHEDULE_PREFIX = 'schedule_'
 
readonly ilLanguage $lng
 
readonly ilCtrlInterface $ctrl
 
readonly ilSetting $settings
 
readonly ilGlobalTemplateInterface $tpl
 
readonly Factory $ui_factory
 
readonly Renderer $ui_renderer
 
readonly ilUIService $ui_service
 
readonly JobRepository $cron_repository
 
readonly ILIAS DI RBACServices $rbac
 
readonly ilErrorHandling $error
 
readonly WrapperFactory $http_wrapper
 
readonly ILIAS HTTP GlobalHttpState $http
 
readonly ILIAS Refinery Factory $refinery
 
readonly JobManager $cron_manager
 
readonly ilObjUser $actor
 

Detailed Description

Member Function Documentation

◆ activate()

ilCronManagerGUI::activate ( )

Definition at line 706 of file class.ilCronManagerGUI.php.

References confirm().

Referenced by handleTableActions().

706  : void
707  {
708  $this->confirm('activate');
709  }
confirm(string $a_action)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addProblematicItemsInfo()

ilCronManagerGUI::addProblematicItemsInfo ( \ILIAS\Cron\Job\JobCollection  $filtered_jobs,
\ILIAS\UI\Component\MessageBox\MessageBox  $message,
array  $components 
)
private
Parameters
list<

Definition at line 146 of file class.ilCronManagerGUI.php.

References $components, ILIAS\BackgroundTasks\Task\Job\JobEntity\getEffectiveJobId(), ILIAS\BackgroundTasks\Task\Job\JobEntity\getEffectiveTitle(), ILIAS\BackgroundTasks\Task\Job\JobEntity\getJobResultStatus(), and ILIAS\Repository\lng().

150  : array {
151  $problematic_jobs = $filtered_jobs->filter(static function (JobEntity $entity): bool {
152  return $entity->getJobResultStatus() === JobResult::STATUS_CRASHED;
153  });
154  if (count($problematic_jobs) > 0) {
155  $problematic_jobs_info = $this->ui_factory->messageBox()->info(
156  $this->lng->txt('cron_jobs_with_required_intervention')
157  )->withLinks(
158  array_map(
159  function (JobEntity $entity): \ILIAS\UI\Component\Link\Standard {
160  return $this->ui_factory->link()->standard(
161  $entity->getEffectiveTitle(),
162  '#job-' . $entity->getEffectiveJobId()
163  );
164  },
165  (new OrderedJobEntities(
166  $problematic_jobs,
167  OrderedJobEntities::ORDER_BY_NAME
168  ))->toArray()
169  )
170  );
171 
172  if (in_array($message, $components, true)) {
173  $components = array_merge(
174  array_slice($components, 0, array_search($message, $components, true) + 1),
175  [$problematic_jobs_info],
176  array_slice($components, array_search($message, $components, true) + 1)
177  );
178  } else {
179  array_unshift($components, $problematic_jobs_info);
180  }
181  }
182 
183  return $components;
184  }
Interface Observer Contains several chained tasks and infos about them.
$components
$message
Definition: xapiexit.php:31
+ Here is the call graph for this function:

◆ addToExternalSettingsForm()

ilCronManagerGUI::addToExternalSettingsForm ( int  $a_form_id)
Returns
array<string, mixed>

Definition at line 867 of file class.ilCronManagerGUI.php.

References $data, and null.

867  : array
868  {
869  $form_elements = [];
870  $fields = [];
871  $data = $this->cron_repository->getCronJobData();
872  foreach ($data as $item) {
873  $job = $this->cron_repository->getJobInstance(
874  $item['job_id'],
875  $item['component'],
876  $item['class']
877  );
878  if ($job !== null) {
879  $job->addToExternalSettingsForm($a_form_id, $fields, (bool) $item['job_status']);
880  }
881  }
882 
883  if ($fields !== []) {
884  $form_elements = [
885  'cron_jobs' => [
886  'jumpToCronJobs',
887  $fields
888  ]
889  ];
890  }
891 
892  return $form_elements;
893  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ confirm()

ilCronManagerGUI::confirm ( string  $a_action)
protected

Definition at line 807 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\ctrl(), getJobIdParameterName(), getMultiActionData(), ILIAS\Cron\CronJob\isManuallyExecutable(), ILIAS\Repository\lng(), ILIAS\Repository\rbac(), and SYSTEM_FOLDER_ID.

Referenced by activate(), deactivate(), reset(), and run().

807  : void
808  {
809  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
810  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
811  }
812 
813  $jobs = $this->getMultiActionData();
814  if ($jobs === []) {
815  $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_checkbox'), true);
816  $this->ctrl->redirect($this, 'render');
817  }
818 
819  if ($a_action === 'run') {
820  $jobs = array_filter($jobs, static function (CronJob $job): bool {
821  return $job->isManuallyExecutable();
822  });
823 
824  if ($jobs === []) {
825  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('cron_no_executable_job_selected'), true);
826  $this->ctrl->redirect($this, 'render');
827  }
828  }
829 
830  $cgui = new ilConfirmationGUI();
831 
832  if (count($jobs) === 1) {
833  $jobKeys = array_keys($jobs);
834  $job_id = array_pop($jobKeys);
835  $job = array_pop($jobs);
836  $title = $job->getTitle();
837  if (!$title) {
838  $title = preg_replace('[^A-Za-z0-9_\-]', '', $job->getId());
839  }
840 
841  $cgui->setHeaderText(
842  sprintf(
843  $this->lng->txt('cron_action_' . $a_action . '_sure'),
844  $title
845  )
846  );
847 
848  $cgui->addHiddenItem($this->getJobIdParameterName() . '[]', $job_id);
849  } else {
850  $cgui->setHeaderText($this->lng->txt('cron_action_' . $a_action . '_sure_multi'));
851 
852  foreach ($jobs as $job_id => $job) {
853  $cgui->addItem($this->getJobIdParameterName() . '[]', $job_id, $job->getTitle());
854  }
855  }
856 
857  $cgui->setFormAction($this->ctrl->getFormAction($this, 'confirmed' . ucfirst($a_action)));
858  $cgui->setCancel($this->lng->txt('cancel'), 'render');
859  $cgui->setConfirm($this->lng->txt('cron_action_' . $a_action), 'confirmed' . ucfirst($a_action));
860 
861  $this->tpl->setContent($cgui->getHTML());
862  }
const SYSTEM_FOLDER_ID
Definition: constants.php:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ confirmedActivate()

ilCronManagerGUI::confirmedActivate ( )

Definition at line 711 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\ctrl(), getMultiActionData(), ILIAS\Repository\lng(), ILIAS\Repository\rbac(), and SYSTEM_FOLDER_ID.

711  : void
712  {
713  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
714  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
715  }
716 
717  $jobs = $this->getMultiActionData();
718  if ($jobs !== []) {
719  foreach ($jobs as $job) {
720  if ($this->cron_manager->isJobInactive($job->getId())) {
721  $this->cron_manager->resetJob($job, $this->actor);
722  }
723  }
724 
725  $this->tpl->setOnScreenMessage('success', $this->lng->txt('cron_action_activate_success'), true);
726  } else {
727  $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_checkbox'), true);
728  }
729 
730  $this->ctrl->redirect($this, 'render');
731  }
const SYSTEM_FOLDER_ID
Definition: constants.php:35
+ Here is the call graph for this function:

◆ confirmedDeactivate()

ilCronManagerGUI::confirmedDeactivate ( )

Definition at line 738 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\ctrl(), getMultiActionData(), ILIAS\Repository\lng(), ILIAS\Repository\rbac(), and SYSTEM_FOLDER_ID.

738  : void
739  {
740  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
741  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
742  }
743 
744  $jobs = $this->getMultiActionData();
745  if ($jobs !== []) {
746  foreach ($jobs as $job) {
747  if ($this->cron_manager->isJobActive($job->getId())) {
748  $this->cron_manager->deactivateJob($job, $this->actor, true);
749  }
750  }
751 
752  $this->tpl->setOnScreenMessage('success', $this->lng->txt('cron_action_deactivate_success'), true);
753  } else {
754  $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_checkbox'), true);
755  }
756 
757  $this->ctrl->redirect($this, 'render');
758  }
const SYSTEM_FOLDER_ID
Definition: constants.php:35
+ Here is the call graph for this function:

◆ confirmedReset()

ilCronManagerGUI::confirmedReset ( )

Definition at line 765 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\ctrl(), getMultiActionData(), ILIAS\Repository\lng(), ILIAS\Repository\rbac(), and SYSTEM_FOLDER_ID.

765  : void
766  {
767  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
768  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
769  }
770 
771  $jobs = $this->getMultiActionData();
772  if ($jobs !== []) {
773  foreach ($jobs as $job) {
774  $this->cron_manager->resetJob($job, $this->actor);
775  }
776  $this->tpl->setOnScreenMessage('success', $this->lng->txt('cron_action_reset_success'), true);
777  } else {
778  $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_checkbox'), true);
779  }
780 
781  $this->ctrl->redirect($this, 'render');
782  }
const SYSTEM_FOLDER_ID
Definition: constants.php:35
+ Here is the call graph for this function:

◆ confirmedRun()

ilCronManagerGUI::confirmedRun ( )

Definition at line 685 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), ILIAS\Repository\rbac(), retrieveTableActionJobIds(), and SYSTEM_FOLDER_ID.

685  : void
686  {
687  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
688  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
689  }
690 
691  $job_ids = $this->retrieveTableActionJobIds();
692  if (count($job_ids) !== 1) {
693  $this->ctrl->redirect($this, 'render');
694  }
695 
696  $job_id = current($job_ids);
697  if ($this->cron_manager->runJobManual($job_id, $this->actor)) {
698  $this->tpl->setOnScreenMessage('success', $this->lng->txt('cron_action_run_success'), true);
699  } else {
700  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('cron_action_run_fail'), true);
701  }
702 
703  $this->ctrl->redirect($this, 'render');
704  }
const SYSTEM_FOLDER_ID
Definition: constants.php:35
+ Here is the call graph for this function:

◆ deactivate()

ilCronManagerGUI::deactivate ( )

Definition at line 733 of file class.ilCronManagerGUI.php.

References confirm().

Referenced by handleTableActions().

733  : void
734  {
735  $this->confirm('deactivate');
736  }
confirm(string $a_action)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ edit()

ilCronManagerGUI::edit ( ?ILIAS\UI\Component\Input\Container\Form\Form  $form = null)

Definition at line 327 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\ctrl(), getJobIdParameterName(), initEditForm(), ILIAS\Repository\lng(), null, ILIAS\Repository\rbac(), retrieveTableActionJobIds(), and SYSTEM_FOLDER_ID.

Referenced by handleTableActions(), and update().

327  : void
328  {
329  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
330  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
331  }
332 
333  if ($form === null) {
334  $job_ids = $this->retrieveTableActionJobIds();
335  if (count($job_ids) !== 1) {
336  $this->ctrl->redirect($this, 'render');
337  }
338 
339  $job_id = current($job_ids);
340  $job = $this->cron_repository->getJobInstanceById($job_id);
341  if ($job && $job->usesLegacyForms()) {
342  $this->ctrl->setParameter($this, $this->getJobIdParameterName(), $job->getId());
343  $this->ctrl->redirect($this, 'editLegacy');
344  }
345 
346  $form = $this->initEditForm($job);
347  }
348 
349  $this->tpl->setContent($this->ui_renderer->render($form));
350  }
const SYSTEM_FOLDER_ID
Definition: constants.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ editLegacy()

ilCronManagerGUI::editLegacy ( ?ilPropertyFormGUI  $a_form = null)

Definition at line 352 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\ctrl(), initLegacyEditForm(), ILIAS\Repository\lng(), null, ILIAS\Repository\rbac(), retrieveTableActionJobIds(), and SYSTEM_FOLDER_ID.

Referenced by updateLegacy().

352  : void
353  {
354  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
355  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
356  }
357 
358  if ($a_form === null) {
359  $job_ids = $this->retrieveTableActionJobIds();
360  if (count($job_ids) !== 1) {
361  $this->ctrl->redirect($this, 'render');
362  }
363 
364  $job_id = current($job_ids);
365  $job = $this->cron_repository->getJobInstanceById($job_id);
366  $a_form = $this->initLegacyEditForm($job);
367  }
368 
369  $this->tpl->setContent($a_form->getHTML());
370  }
const SYSTEM_FOLDER_ID
Definition: constants.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
initLegacyEditForm(?CronJob $job)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilCronManagerGUI::executeCommand ( )

Definition at line 226 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\ctrl(), getJobIdParameterName(), getRequestValue(), initLegacyEditForm(), ILIAS\Repository\lng(), ILIAS\Repository\rbac(), ILIAS\Repository\refinery(), ilUtil\stripSlashes(), and SYSTEM_FOLDER_ID.

226  : void
227  {
228  if (!$this->rbac->system()->checkAccess('visible,read', SYSTEM_FOLDER_ID)) {
229  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
230  }
231 
232  $class = $this->ctrl->getNextClass($this);
233 
234  switch (strtolower($class)) {
235  case strtolower(ilPropertyFormGUI::class):
236  $job_id = $this->getRequestValue($this->getJobIdParameterName(), $this->refinery->kindlyTo()->string());
237  $job = $this->cron_repository->getJobInstanceById(ilUtil::stripSlashes($job_id));
238  $form = $this->initLegacyEditForm($job);
239  $this->ctrl->forwardCommand($form);
240  break;
241  }
242 
243  $cmd = $this->ctrl->getCmd('render');
244  $this->$cmd();
245  }
getRequestValue(string $key, \ILIAS\Refinery\Transformation $trafo, bool $force_retrieval=false, $default=null)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
const SYSTEM_FOLDER_ID
Definition: constants.php:35
initLegacyEditForm(?CronJob $job)
+ Here is the call graph for this function:

◆ getJobIdParameterName()

ilCronManagerGUI::getJobIdParameterName ( )
private

Definition at line 186 of file class.ilCronManagerGUI.php.

Referenced by confirm(), edit(), executeCommand(), initEditForm(), initLegacyEditForm(), retrieveTableActionJobIds(), update(), and updateLegacy().

186  : string
187  {
188  return implode('_', array_merge(self::TABLE_ACTION_NAMESPACE, [self::TABLE_ACTION_IDENTIFIER_NAME]));
189  }
+ Here is the caller graph for this function:

◆ getMultiActionData()

ilCronManagerGUI::getMultiActionData ( )
protected
Returns
array<string, CronJob>

Definition at line 787 of file class.ilCronManagerGUI.php.

References $res, and retrieveTableActionJobIds().

Referenced by confirm(), confirmedActivate(), confirmedDeactivate(), and confirmedReset().

787  : array
788  {
789  $res = [];
790 
791  $job_ids = [];
792  try {
793  $job_ids = $this->retrieveTableActionJobIds();
794  } catch (\ILIAS\Refinery\ConstraintViolationException|OutOfBoundsException) {
795  }
796 
797  foreach ($job_ids as $job_id) {
798  $job = $this->cron_repository->getJobInstanceById($job_id);
799  if ($job instanceof CronJob) {
800  $res[$job_id] = $job;
801  }
802  }
803 
804  return $res;
805  }
$res
Definition: ltiservices.php:66
Interface Observer Contains several chained tasks and infos about them.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRequestValue()

ilCronManagerGUI::getRequestValue ( string  $key,
\ILIAS\Refinery\Transformation  $trafo,
bool  $force_retrieval = false,
  $default = null 
)
private
Parameters
mixed$default
Returns
mixed|null

Definition at line 195 of file class.ilCronManagerGUI.php.

References Vendor\Package\$e, and null.

Referenced by executeCommand(), update(), and updateLegacy().

200  {
201  $exc = null;
202 
203  try {
204  if ($force_retrieval || $this->http_wrapper->query()->has($key)) {
205  return $this->http_wrapper->query()->retrieve($key, $trafo);
206  }
207  } catch (OutOfBoundsException $e) {
208  $exc = $e;
209  }
210 
211  try {
212  if ($force_retrieval || $this->http_wrapper->post()->has($key)) {
213  return $this->http_wrapper->post()->retrieve($key, $trafo);
214  }
215  } catch (OutOfBoundsException $e) {
216  $exc = $e;
217  }
218 
219  if ($force_retrieval && $exc) {
220  throw $exc;
221  }
222 
223  return $default ?? null;
224  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ getScheduleTypeFormElementName()

ilCronManagerGUI::getScheduleTypeFormElementName ( JobScheduleType  $schedule_type)
private

Definition at line 372 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\lng(), and ILIAS\Cron\Job\Schedule\YEARLY.

Referenced by initEditForm(), and initLegacyEditForm().

372  : string
373  {
374  return match ($schedule_type) {
375  JobScheduleType::DAILY => $this->lng->txt('cron_schedule_daily'),
376  JobScheduleType::WEEKLY => $this->lng->txt('cron_schedule_weekly'),
377  JobScheduleType::MONTHLY => $this->lng->txt('cron_schedule_monthly'),
378  JobScheduleType::QUARTERLY => $this->lng->txt('cron_schedule_quarterly'),
379  JobScheduleType::YEARLY => $this->lng->txt('cron_schedule_yearly'),
380  JobScheduleType::IN_MINUTES => sprintf($this->lng->txt('cron_schedule_in_minutes'), 'x'),
381  JobScheduleType::IN_HOURS => sprintf($this->lng->txt('cron_schedule_in_hours'), 'x'),
382  JobScheduleType::IN_DAYS => sprintf($this->lng->txt('cron_schedule_in_days'), 'x'),
383  };
384  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getScheduleValueFormElementName()

ilCronManagerGUI::getScheduleValueFormElementName ( JobScheduleType  $schedule_type)
protected

Definition at line 386 of file class.ilCronManagerGUI.php.

Referenced by initEditForm(), initLegacyEditForm(), and update().

386  : string
387  {
388  return match ($schedule_type) {
389  JobScheduleType::IN_MINUTES => 'smini',
390  JobScheduleType::IN_HOURS => 'shri',
391  JobScheduleType::IN_DAYS => 'sdyi',
392  default => throw new InvalidArgumentException(
393  sprintf(
394  'The passed argument %s is invalid!',
395  var_export($schedule_type, true)
396  )
397  ),
398  };
399  }
+ Here is the caller graph for this function:

◆ getTableActionParameterName()

ilCronManagerGUI::getTableActionParameterName ( )
private

Definition at line 137 of file class.ilCronManagerGUI.php.

Referenced by handleTableActions().

137  : string
138  {
139  return implode('_', array_merge(self::TABLE_ACTION_NAMESPACE, [self::TABLE_ACTION_PARAM_NAME]));
140  }
+ Here is the caller graph for this function:

◆ handleTableActions()

ilCronManagerGUI::handleTableActions ( )
private

Definition at line 247 of file class.ilCronManagerGUI.php.

References activate(), deactivate(), edit(), getTableActionParameterName(), ILIAS\Repository\refinery(), render(), reset(), and run().

247  : void
248  {
249  $action = $this->http_wrapper->query()->retrieve(
251  $this->refinery->byTrying([
252  $this->refinery->kindlyTo()->string(),
253  $this->refinery->always('')
254  ])
255  );
256  match ($action) {
257  'run' => $this->run(),
258  'activate' => $this->activate(),
259  'deactivate' => $this->deactivate(),
260  'reset' => $this->reset(),
261  'edit' => $this->edit(),
262  default => $this->render()
263  };
264  }
edit(?ILIAS\UI\Component\Input\Container\Form\Form $form=null)
+ Here is the call graph for this function:

◆ hasScheduleValue()

ilCronManagerGUI::hasScheduleValue ( JobScheduleType  $schedule_type)
protected

Definition at line 401 of file class.ilCronManagerGUI.php.

Referenced by update(), and updateLegacy().

401  : bool
402  {
403  return in_array($schedule_type, [
404  JobScheduleType::IN_MINUTES,
405  JobScheduleType::IN_HOURS,
406  JobScheduleType::IN_DAYS
407  ], true);
408  }
+ Here is the caller graph for this function:

◆ initEditForm()

ilCronManagerGUI::initEditForm ( ?CronJob  $job)
protected

Definition at line 410 of file class.ilCronManagerGUI.php.

References ILIAS\UI\Implementation\Component\Input\$inputs, ILIAS\Repository\ctrl(), ILIAS\Cron\CronJob\getAllScheduleTypes(), ILIAS\Cron\CronJob\getCustomConfigurationInput(), ILIAS\Cron\CronJob\getId(), getJobIdParameterName(), getScheduleTypeFormElementName(), ILIAS\Cron\CronJob\getScheduleTypesWithValues(), getScheduleValueFormElementName(), ILIAS\Cron\CronJob\getTitle(), ILIAS\Cron\CronJob\getValidScheduleTypes(), ILIAS\Cron\CronJob\hasCustomSettings(), ILIAS\Cron\CronJob\hasFlexibleSchedule(), ILIAS\Repository\lng(), null, ILIAS\Repository\refinery(), and ILIAS\UI\Implementation\Component\Input\ViewControl\withAdditionalTransformation().

Referenced by edit(), and update().

411  {
412  if (!($job instanceof CronJob)) {
413  $this->ctrl->redirect($this, 'render');
414  }
415 
416  $this->ctrl->setParameter($this, $this->getJobIdParameterName(), $job->getId());
417 
418  $jobs_data = $this->cron_repository->getCronJobData($job->getId());
419  $job_data = $jobs_data[0];
420 
421  $section_inputs = [];
422  if ($job->hasFlexibleSchedule()) {
423  $schedule_type_groups = [];
424  foreach ($job->getAllScheduleTypes() as $schedule_type) {
425  if (!in_array($schedule_type, $job->getValidScheduleTypes(), true)) {
426  continue;
427  }
428 
429  $schedule_type_inputs = [];
430  if (in_array($schedule_type, $job->getScheduleTypesWithValues(), true)) {
431  $schedule_value_input = $this->ui_factory
432  ->input()
433  ->field()
434  ->numeric(
435  $this->lng->txt('cron_schedule_value')
437  $this->refinery->in()->series([
438  $this->refinery->int()->isGreaterThanOrEqual(1)
439  ])
440  )->withRequired(true);
441 
442  if (is_numeric($job_data['schedule_type']) &&
443  JobScheduleType::tryFrom((int) $job_data['schedule_type']) === $schedule_type) {
444  $schedule_value_input = $schedule_value_input->withValue(
445  $job_data['schedule_value'] === null ? null : (int) $job_data['schedule_value']
446  );
447  }
448 
449  $schedule_type_inputs = [
450  $this->getScheduleValueFormElementName($schedule_type) => $schedule_value_input
451  ];
452  }
453 
454  $schedule_type_groups[self::FORM_PARAM_SCHEDULE_PREFIX . $schedule_type->value] = $this->ui_factory
455  ->input()
456  ->field()
457  ->group(
458  $schedule_type_inputs,
459  $this->getScheduleTypeFormElementName($schedule_type)
460  )
461  ->withDedicatedName(self::FORM_PARAM_SCHEDULE_PREFIX . $schedule_type->value);
462  }
463 
464  $default_schedule_type = current($job->getValidScheduleTypes())->value;
465 
466  $section_inputs['schedule'] = $this->ui_factory
467  ->input()
468  ->field()
469  ->switchableGroup(
470  $schedule_type_groups,
471  $this->lng->txt('cron_schedule_type')
472  )
473  ->withRequired(true)
474  ->withValue(
475  $job_data['schedule_type'] === null ?
476  self::FORM_PARAM_SCHEDULE_PREFIX . $default_schedule_type :
477  self::FORM_PARAM_SCHEDULE_PREFIX . $job_data['schedule_type']
478  );
479  }
480 
481  $main_section = $this->ui_factory->input()->field()->section(
482  $section_inputs,
483  $this->lng->txt('cron_action_edit') . ': "' . $job->getTitle() . '"'
484  );
485 
486  $inputs = [
487  self::FORM_PARAM_MAIN_SECTION => $main_section
488  ];
489 
490  if ($job->hasCustomSettings()) {
491  $inputs = array_merge(
492  $inputs,
493  [
494  self::FORM_PARAM_JOB_INPUT =>
495  $job->getCustomConfigurationInput(
496  $this->ui_factory,
497  $this->refinery,
498  $this->lng
499  )
500  ]
501  );
502  }
503 
504  return $this->ui_factory
505  ->input()
506  ->container()
507  ->form()
508  ->standard($this->ctrl->getFormAction($this, 'update'), $inputs)
509  ->withDedicatedName('cron_form');
510  }
getScheduleTypeFormElementName(JobScheduleType $schedule_type)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getScheduleValueFormElementName(JobScheduleType $schedule_type)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initLegacyEditForm()

ilCronManagerGUI::initLegacyEditForm ( ?CronJob  $job)
protected
Deprecated:

Definition at line 516 of file class.ilCronManagerGUI.php.

References ILIAS\Cron\CronJob\addCustomSettingsToForm(), ilNumberInputGUI\allowDecimals(), ILIAS\Repository\ctrl(), ILIAS\Cron\CronJob\getAllScheduleTypes(), ILIAS\Cron\CronJob\getId(), getJobIdParameterName(), getScheduleTypeFormElementName(), ILIAS\Cron\CronJob\getScheduleTypesWithValues(), getScheduleValueFormElementName(), ILIAS\Cron\CronJob\getTitle(), ILIAS\Cron\CronJob\getValidScheduleTypes(), ILIAS\Cron\CronJob\hasCustomSettings(), ILIAS\Cron\CronJob\hasFlexibleSchedule(), ILIAS\Repository\lng(), null, and ilFormPropertyGUI\setRequired().

Referenced by editLegacy(), executeCommand(), and updateLegacy().

517  {
518  if (!($job instanceof CronJob)) {
519  $this->ctrl->redirect($this, 'render');
520  }
521 
522  $this->ctrl->setParameter($this, $this->getJobIdParameterName(), $job->getId());
523 
524  $jobs_data = $this->cron_repository->getCronJobData($job->getId());
525  $job_data = $jobs_data[0];
526 
527  $form = new ilPropertyFormGUI();
528  $form->setFormAction($this->ctrl->getFormAction($this, 'updateLegacy'));
529  $form->setTitle($this->lng->txt('cron_action_edit') . ': "' . $job->getTitle() . '"');
530 
531  if ($job->hasFlexibleSchedule()) {
532  $type = new ilRadioGroupInputGUI($this->lng->txt('cron_schedule_type'), 'type');
533  $type->setRequired(true);
534  $type->setValue($job_data['schedule_type'] === null ? null : (string) $job_data['schedule_type']);
535 
536  foreach ($job->getAllScheduleTypes() as $schedule_type) {
537  if (!in_array($schedule_type, $job->getValidScheduleTypes(), true)) {
538  continue;
539  }
540 
541  $option = new ilRadioOption(
542  $this->getScheduleTypeFormElementName($schedule_type),
543  (string) $schedule_type->value
544  );
545  $type->addOption($option);
546 
547  if (in_array($schedule_type, $job->getScheduleTypesWithValues(), true)) {
548  $scheduleValue = new ilNumberInputGUI(
549  $this->lng->txt('cron_schedule_value'),
550  $this->getScheduleValueFormElementName($schedule_type)
551  );
552  $scheduleValue->allowDecimals(false);
553  $scheduleValue->setRequired(true);
554  $scheduleValue->setSize(5);
555  if (is_numeric($job_data['schedule_type']) &&
556  JobScheduleType::tryFrom((int) $job_data['schedule_type']) === $schedule_type) {
557  $scheduleValue->setValue(
558  $job_data['schedule_value'] === null ? null : (string) $job_data['schedule_value']
559  );
560  }
561  $option->addSubItem($scheduleValue);
562  }
563  }
564 
565  $form->addItem($type);
566  }
567 
568  if ($job->hasCustomSettings()) {
569  $job->addCustomSettingsToForm($form);
570  }
571 
572  $form->addCommandButton('updateLegacy', $this->lng->txt('save'));
573  $form->addCommandButton('render', $this->lng->txt('cancel'));
574 
575  return $form;
576  }
This class represents an option in a radio group.
getScheduleTypeFormElementName(JobScheduleType $schedule_type)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
allowDecimals(bool $a_value)
This class represents a property in a property form.
getScheduleValueFormElementName(JobScheduleType $schedule_type)
This class represents a number property in a property form.
setRequired(bool $a_required)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ilCronManagerGUI::render ( )
protected

Definition at line 266 of file class.ilCronManagerGUI.php.

References $cron_repository, $ctrl, $lng, $message, ILIAS\Repository\ctrl(), ilDatePresentation\formatDate(), ILIAS\FileDelivery\http(), IL_CAL_UNIX, ILIAS\Repository\lng(), ILIAS\Repository\rbac(), ILIAS\Repository\settings(), and SYSTEM_FOLDER_ID.

Referenced by handleTableActions().

266  : void
267  {
268  $tstamp = $this->lng->txt('cronjob_last_start_unknown');
269  if ($this->settings->get('last_cronjob_start_ts')) {
271  new ilDateTime(
272  $this->settings->get('last_cronjob_start_ts'),
274  )
275  );
276  }
277 
278  $message = $this->ui_factory->messageBox()->info($this->lng->txt('cronjob_last_start') . ': ' . $tstamp);
279 
280  $cronJobs = $this->cron_repository->findAll();
281 
282  $tableFilterMediator = new JobTableFilterMediator(
283  $cronJobs,
284  $this->ui_factory,
285  $this->ui_service,
286  $this->lng
287  );
288  $filter = $tableFilterMediator->filter(
289  $this->ctrl->getFormAction(
290  $this,
291  'render',
292  '',
293  true
294  )
295  );
296 
297  $filtered_jobs = $tableFilterMediator->filteredJobs(
298  $filter
299  );
300 
301  $tbl = new JobTable(
302  $this,
303  'handleTableActions',
304  self::TABLE_ACTION_NAMESPACE,
305  self::TABLE_ACTION_PARAM_NAME,
306  self::TABLE_ACTION_IDENTIFIER_NAME,
307  $this->ui_factory,
308  $this->http->request(),
309  $this->ctrl,
310  $this->lng,
311  $filtered_jobs,
313  $this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)
314  );
315 
316  $this->tpl->setContent(
317  $this->ui_renderer->render(
318  $this->addProblematicItemsInfo(
319  $filtered_jobs,
320  $message,
321  [$message, $filter, $tbl->getComponent()]
322  )
323  )
324  );
325  }
readonly ilCtrlInterface $ctrl
const IL_CAL_UNIX
const SYSTEM_FOLDER_ID
Definition: constants.php:35
static http()
Fetches the global http state from ILIAS.
readonly JobRepository $cron_repository
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
$message
Definition: xapiexit.php:31
readonly ilLanguage $lng
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

ilCronManagerGUI::reset ( )

Definition at line 760 of file class.ilCronManagerGUI.php.

References confirm().

Referenced by handleTableActions().

760  : void
761  {
762  $this->confirm('reset');
763  }
confirm(string $a_action)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieveTableActionJobIds()

ilCronManagerGUI::retrieveTableActionJobIds ( )
private
Returns
list<string>

Definition at line 92 of file class.ilCronManagerGUI.php.

References $lng, $ui_factory, $ui_service, ILIAS\Repository\ctrl(), ILIAS\BackgroundTasks\Task\Job\Manager\UI\JobTableFilterMediator\filter(), ILIAS\BackgroundTasks\Task\Job\JobEntity\getEffectiveJobId(), getJobIdParameterName(), ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by confirmedRun(), edit(), editLegacy(), and getMultiActionData().

92  : array
93  {
94  $retrieval = $this->http_wrapper->query();
95  if (strtoupper($this->http->request()->getMethod()) === 'POST') {
96  $retrieval = $this->http_wrapper->post();
97  }
98 
99  $trafo = $this->refinery->byTrying([
100  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
101  $this->refinery->always([])
102  ]);
103 
104  $ids = $retrieval->retrieve(
105  $this->getJobIdParameterName(),
106  $trafo
107  );
108 
109  if (count($ids) === 1 && $ids[0] === 'ALL_OBJECTS') {
110  $tableFilterMediator = new JobTableFilterMediator(
111  $this->cron_repository->findAll(),
114  $this->lng
115  );
116  $filter = $tableFilterMediator->filter(
117  $this->ctrl->getFormAction(
118  $this,
119  'render',
120  '',
121  true
122  )
123  );
124  $ids = array_map(
125  static function (JobEntity $entity): string {
126  return $entity->getEffectiveJobId();
127  },
128  $tableFilterMediator->filteredJobs(
129  $filter
130  )->toArray()
131  );
132  }
133 
134  return $ids;
135  }
readonly ilUIService $ui_service
static http()
Fetches the global http state from ILIAS.
readonly Factory $ui_factory
readonly ilLanguage $lng
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

ilCronManagerGUI::run ( )

Definition at line 680 of file class.ilCronManagerGUI.php.

References confirm().

Referenced by handleTableActions().

680  : void
681  {
682  $this->confirm('run');
683  }
confirm(string $a_action)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilCronManagerGUI::update ( )

Definition at line 578 of file class.ilCronManagerGUI.php.

References ILIAS\Repository\ctrl(), edit(), ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from(), getJobIdParameterName(), getRequestValue(), getScheduleValueFormElementName(), hasScheduleValue(), ILIAS\FileDelivery\http(), initEditForm(), ILIAS\Repository\int(), ILIAS\Repository\lng(), null, ILIAS\Repository\rbac(), ILIAS\Repository\refinery(), and SYSTEM_FOLDER_ID.

578  : void
579  {
580  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
581  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
582  }
583 
584  $job_id = $this->getRequestValue($this->getJobIdParameterName(), $this->refinery->kindlyTo()->string());
585  if (!$job_id) {
586  $this->ctrl->redirect($this, 'render');
587  }
588 
589  $job = $this->cron_repository->getJobInstanceById($job_id);
590  $form = $this->initEditForm($job);
591 
592  $form_valid = false;
593  $form_data = null;
594  if ($this->http->request()->getMethod() === 'POST') {
595  $form = $form->withRequest($this->http->request());
596  $form_data = $form->getData();
597  $form_valid = $form_data !== null;
598  }
599 
600  if (!$form_valid) {
601  $this->edit($form);
602  return;
603  }
604 
605  if ($job instanceof CronJob) {
606  if ($job->hasFlexibleSchedule()) {
607  $schedule_group = $form_data[self::FORM_PARAM_MAIN_SECTION][self::FORM_PARAM_GROUP_SCHEDULE];
608 
609  $type = JobScheduleType::from(
610  (int) ltrim($schedule_group[0], self::FORM_PARAM_SCHEDULE_PREFIX)
611  );
612 
613  $value = match (true) {
614  $this->hasScheduleValue($type) => (int) $schedule_group[1][$this->getScheduleValueFormElementName(
615  $type
616  )],
617  default => null,
618  };
619 
620  $this->cron_repository->updateJobSchedule($job, $type, $value);
621  }
622 
623  if ($job->hasCustomSettings()) {
624  $job->saveCustomConfiguration($form_data[self::FORM_PARAM_JOB_INPUT]);
625  }
626 
627  $this->tpl->setOnScreenMessage('success', $this->lng->txt('cron_action_edit_success'), true);
628  $this->ctrl->redirect($this, 'render');
629  }
630 
631  $this->edit($form);
632  }
hasScheduleValue(JobScheduleType $schedule_type)
getRequestValue(string $key, \ILIAS\Refinery\Transformation $trafo, bool $force_retrieval=false, $default=null)
const SYSTEM_FOLDER_ID
Definition: constants.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
getScheduleValueFormElementName(JobScheduleType $schedule_type)
edit(?ILIAS\UI\Component\Input\Container\Form\Form $form=null)
+ Here is the call graph for this function:

◆ updateLegacy()

ilCronManagerGUI::updateLegacy ( )
Deprecated:

Definition at line 638 of file class.ilCronManagerGUI.php.

References $valid, ILIAS\Repository\ctrl(), editLegacy(), ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from(), getJobIdParameterName(), getRequestValue(), hasScheduleValue(), initLegacyEditForm(), ILIAS\Repository\int(), ILIAS\Repository\lng(), null, ILIAS\Repository\rbac(), ILIAS\Repository\refinery(), and SYSTEM_FOLDER_ID.

638  : void
639  {
640  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
641  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
642  }
643 
644  $job_id = $this->getRequestValue($this->getJobIdParameterName(), $this->refinery->kindlyTo()->string());
645  if (!$job_id) {
646  $this->ctrl->redirect($this, 'render');
647  }
648 
649  $job = $this->cron_repository->getJobInstanceById($job_id);
650 
651  $form = $this->initLegacyEditForm($job);
652  if ($job instanceof CronJob && $form->checkInput()) {
653  $valid = true;
654  if ($job->hasCustomSettings() && !$job->saveCustomSettings($form)) {
655  $valid = false;
656  }
657 
658  if ($valid && $job->hasFlexibleSchedule()) {
659  $type = JobScheduleType::from((int) $form->getInput('type'));
660  $value = match (true) {
661  $this->hasScheduleValue($type) => (int) $form->getInput(
662  $this->getScheduleValueFormElementName($type)
663  ),
664  default => null,
665  };
666 
667  $this->cron_repository->updateJobSchedule($job, $type, $value);
668  }
669 
670  if ($valid) {
671  $this->tpl->setOnScreenMessage('success', $this->lng->txt('cron_action_edit_success'), true);
672  $this->ctrl->redirect($this, 'render');
673  }
674  }
675 
676  $form->setValuesByPost();
677  $this->editLegacy($form);
678  }
hasScheduleValue(JobScheduleType $schedule_type)
getRequestValue(string $key, \ILIAS\Refinery\Transformation $trafo, bool $force_retrieval=false, $default=null)
$valid
const SYSTEM_FOLDER_ID
Definition: constants.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
editLegacy(?ilPropertyFormGUI $a_form=null)
initLegacyEditForm(?CronJob $job)
+ Here is the call graph for this function:

Field Documentation

◆ $actor

readonly ilObjUser ilCronManagerGUI::$actor
private

Definition at line 62 of file class.ilCronManagerGUI.php.

◆ $cron_manager

readonly JobManager ilCronManagerGUI::$cron_manager
private

Definition at line 61 of file class.ilCronManagerGUI.php.

◆ $cron_repository

readonly JobRepository ilCronManagerGUI::$cron_repository
private

Definition at line 55 of file class.ilCronManagerGUI.php.

Referenced by render().

◆ $ctrl

readonly ilCtrlInterface ilCronManagerGUI::$ctrl
private

Definition at line 49 of file class.ilCronManagerGUI.php.

Referenced by render().

◆ $error

readonly ilErrorHandling ilCronManagerGUI::$error
private

Definition at line 57 of file class.ilCronManagerGUI.php.

◆ $http

readonly ILIAS HTTP GlobalHttpState ilCronManagerGUI::$http
private

Definition at line 59 of file class.ilCronManagerGUI.php.

◆ $http_wrapper

readonly WrapperFactory ilCronManagerGUI::$http_wrapper
private

Definition at line 58 of file class.ilCronManagerGUI.php.

◆ $lng

readonly ilLanguage ilCronManagerGUI::$lng
private

Definition at line 48 of file class.ilCronManagerGUI.php.

Referenced by render(), and retrieveTableActionJobIds().

◆ $rbac

readonly ILIAS DI RBACServices ilCronManagerGUI::$rbac
private

Definition at line 56 of file class.ilCronManagerGUI.php.

◆ $refinery

readonly ILIAS Refinery Factory ilCronManagerGUI::$refinery
private

Definition at line 60 of file class.ilCronManagerGUI.php.

◆ $settings

readonly ilSetting ilCronManagerGUI::$settings
private

Definition at line 50 of file class.ilCronManagerGUI.php.

◆ $tpl

readonly ilGlobalTemplateInterface ilCronManagerGUI::$tpl
private

Definition at line 51 of file class.ilCronManagerGUI.php.

◆ $ui_factory

readonly Factory ilCronManagerGUI::$ui_factory
private

Definition at line 52 of file class.ilCronManagerGUI.php.

Referenced by retrieveTableActionJobIds().

◆ $ui_renderer

readonly Renderer ilCronManagerGUI::$ui_renderer
private

Definition at line 53 of file class.ilCronManagerGUI.php.

◆ $ui_service

readonly ilUIService ilCronManagerGUI::$ui_service
private

Definition at line 54 of file class.ilCronManagerGUI.php.

Referenced by retrieveTableActionJobIds().

◆ FORM_PARAM_GROUP_SCHEDULE

const ilCronManagerGUI::FORM_PARAM_GROUP_SCHEDULE = 'schedule'

Definition at line 46 of file class.ilCronManagerGUI.php.

◆ FORM_PARAM_JOB_INPUT

const ilCronManagerGUI::FORM_PARAM_JOB_INPUT = 'additional_job_input'

Definition at line 45 of file class.ilCronManagerGUI.php.

◆ FORM_PARAM_MAIN_SECTION

const ilCronManagerGUI::FORM_PARAM_MAIN_SECTION = 'main'

Definition at line 44 of file class.ilCronManagerGUI.php.

◆ FORM_PARAM_SCHEDULE_PREFIX

const ilCronManagerGUI::FORM_PARAM_SCHEDULE_PREFIX = 'schedule_'
private

Definition at line 43 of file class.ilCronManagerGUI.php.

◆ TABLE_ACTION_IDENTIFIER_NAME

const ilCronManagerGUI::TABLE_ACTION_IDENTIFIER_NAME = 'jid'
private

Definition at line 42 of file class.ilCronManagerGUI.php.

◆ TABLE_ACTION_NAMESPACE

const ilCronManagerGUI::TABLE_ACTION_NAMESPACE = ['cron', 'jobs']
private

Definition at line 40 of file class.ilCronManagerGUI.php.

◆ TABLE_ACTION_PARAM_NAME

const ilCronManagerGUI::TABLE_ACTION_PARAM_NAME = 'table_action'
private

Definition at line 41 of file class.ilCronManagerGUI.php.


The documentation for this class was generated from the following file: