ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 array TABLE_ACTION_NAMESPACE = ['cron', 'jobs']
 
const string TABLE_ACTION_PARAM_NAME = 'table_action'
 
const string TABLE_ACTION_IDENTIFIER_NAME = 'jid'
 
const string 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 704 of file class.ilCronManagerGUI.php.

References confirm().

Referenced by handleTableActions().

704  : void
705  {
706  $this->confirm('activate');
707  }
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 144 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().

148  : array {
149  $problematic_jobs = $filtered_jobs->filter(static function (JobEntity $entity): bool {
150  return $entity->getJobResultStatus() === JobResult::STATUS_CRASHED;
151  });
152  if (count($problematic_jobs) > 0) {
153  $problematic_jobs_info = $this->ui_factory->messageBox()->info(
154  $this->lng->txt('cron_jobs_with_required_intervention')
155  )->withLinks(
156  array_map(
157  function (JobEntity $entity): \ILIAS\UI\Component\Link\Standard {
158  return $this->ui_factory->link()->standard(
159  $entity->getEffectiveTitle(),
160  '#job-' . $entity->getEffectiveJobId()
161  );
162  },
163  (new OrderedJobEntities(
164  $problematic_jobs,
165  OrderedJobEntities::ORDER_BY_NAME
166  ))->toArray()
167  )
168  );
169 
170  if (in_array($message, $components, true)) {
171  $components = array_merge(
172  array_slice($components, 0, array_search($message, $components, true) + 1),
173  [$problematic_jobs_info],
174  array_slice($components, array_search($message, $components, true) + 1)
175  );
176  } else {
177  array_unshift($components, $problematic_jobs_info);
178  }
179  }
180 
181  return $components;
182  }
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 865 of file class.ilCronManagerGUI.php.

References $data, and null.

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

◆ confirm()

ilCronManagerGUI::confirm ( string  $a_action)
protected

Definition at line 805 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().

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

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

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

◆ confirmedDeactivate()

ilCronManagerGUI::confirmedDeactivate ( )

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

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

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

◆ confirmedReset()

ilCronManagerGUI::confirmedReset ( )

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

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

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

◆ confirmedRun()

ilCronManagerGUI::confirmedRun ( )

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

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

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

◆ deactivate()

ilCronManagerGUI::deactivate ( )

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

References confirm().

Referenced by handleTableActions().

731  : void
732  {
733  $this->confirm('deactivate');
734  }
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 325 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().

325  : void
326  {
327  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
328  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
329  }
330 
331  if ($form === null) {
332  $job_ids = $this->retrieveTableActionJobIds();
333  if (count($job_ids) !== 1) {
334  $this->ctrl->redirect($this, 'render');
335  }
336 
337  $job_id = current($job_ids);
338  $job = $this->cron_repository->getJobInstanceById($job_id);
339  if ($job && $job->usesLegacyForms()) {
340  $this->ctrl->setParameter($this, $this->getJobIdParameterName(), $job->getId());
341  $this->ctrl->redirect($this, 'editLegacy');
342  }
343 
344  $form = $this->initEditForm($job);
345  }
346 
347  $this->tpl->setContent($this->ui_renderer->render($form));
348  }
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 350 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().

350  : void
351  {
352  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
353  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
354  }
355 
356  if ($a_form === null) {
357  $job_ids = $this->retrieveTableActionJobIds();
358  if (count($job_ids) !== 1) {
359  $this->ctrl->redirect($this, 'render');
360  }
361 
362  $job_id = current($job_ids);
363  $job = $this->cron_repository->getJobInstanceById($job_id);
364  $a_form = $this->initLegacyEditForm($job);
365  }
366 
367  $this->tpl->setContent($a_form->getHTML());
368  }
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 224 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.

224  : void
225  {
226  if (!$this->rbac->system()->checkAccess('visible,read', SYSTEM_FOLDER_ID)) {
227  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
228  }
229 
230  $class = $this->ctrl->getNextClass($this) ?? '';
231 
232  switch (strtolower($class)) {
233  case strtolower(ilPropertyFormGUI::class):
234  $job_id = $this->getRequestValue($this->getJobIdParameterName(), $this->refinery->kindlyTo()->string());
235  $job = $this->cron_repository->getJobInstanceById(ilUtil::stripSlashes($job_id));
236  $form = $this->initLegacyEditForm($job);
237  $this->ctrl->forwardCommand($form);
238  break;
239  }
240 
241  $cmd = $this->ctrl->getCmd('render');
242  $this->$cmd();
243  }
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 184 of file class.ilCronManagerGUI.php.

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

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

◆ getMultiActionData()

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

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

References $res, and retrieveTableActionJobIds().

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

785  : array
786  {
787  $res = [];
788 
789  $job_ids = [];
790  try {
791  $job_ids = $this->retrieveTableActionJobIds();
792  } catch (\ILIAS\Refinery\ConstraintViolationException|OutOfBoundsException) {
793  }
794 
795  foreach ($job_ids as $job_id) {
796  $job = $this->cron_repository->getJobInstanceById($job_id);
797  if ($job instanceof CronJob) {
798  $res[$job_id] = $job;
799  }
800  }
801 
802  return $res;
803  }
$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 193 of file class.ilCronManagerGUI.php.

References Vendor\Package\$e, and null.

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

198  {
199  $exc = null;
200 
201  try {
202  if ($force_retrieval || $this->http_wrapper->query()->has($key)) {
203  return $this->http_wrapper->query()->retrieve($key, $trafo);
204  }
205  } catch (OutOfBoundsException $e) {
206  $exc = $e;
207  }
208 
209  try {
210  if ($force_retrieval || $this->http_wrapper->post()->has($key)) {
211  return $this->http_wrapper->post()->retrieve($key, $trafo);
212  }
213  } catch (OutOfBoundsException $e) {
214  $exc = $e;
215  }
216 
217  if ($force_retrieval && $exc) {
218  throw $exc;
219  }
220 
221  return $default ?? null;
222  }
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 370 of file class.ilCronManagerGUI.php.

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

Referenced by initEditForm(), and initLegacyEditForm().

370  : string
371  {
372  return match ($schedule_type) {
373  JobScheduleType::DAILY => $this->lng->txt('cron_schedule_daily'),
374  JobScheduleType::WEEKLY => $this->lng->txt('cron_schedule_weekly'),
375  JobScheduleType::MONTHLY => $this->lng->txt('cron_schedule_monthly'),
376  JobScheduleType::QUARTERLY => $this->lng->txt('cron_schedule_quarterly'),
377  JobScheduleType::YEARLY => $this->lng->txt('cron_schedule_yearly'),
378  JobScheduleType::IN_MINUTES => sprintf($this->lng->txt('cron_schedule_in_minutes'), 'x'),
379  JobScheduleType::IN_HOURS => sprintf($this->lng->txt('cron_schedule_in_hours'), 'x'),
380  JobScheduleType::IN_DAYS => sprintf($this->lng->txt('cron_schedule_in_days'), 'x'),
381  };
382  }
+ 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 384 of file class.ilCronManagerGUI.php.

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

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

◆ getTableActionParameterName()

ilCronManagerGUI::getTableActionParameterName ( )
private

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

Referenced by handleTableActions().

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

◆ handleTableActions()

ilCronManagerGUI::handleTableActions ( )
private

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

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

245  : void
246  {
247  $action = $this->http_wrapper->query()->retrieve(
249  $this->refinery->byTrying([
250  $this->refinery->kindlyTo()->string(),
251  $this->refinery->always('')
252  ])
253  );
254  match ($action) {
255  'run' => $this->run(),
256  'activate' => $this->activate(),
257  'deactivate' => $this->deactivate(),
258  'reset' => $this->reset(),
259  'edit' => $this->edit(),
260  default => $this->render()
261  };
262  }
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 399 of file class.ilCronManagerGUI.php.

Referenced by update(), and updateLegacy().

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

◆ initEditForm()

ilCronManagerGUI::initEditForm ( ?CronJob  $job)
protected

Definition at line 408 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().

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

515  {
516  if (!($job instanceof CronJob)) {
517  $this->ctrl->redirect($this, 'render');
518  }
519 
520  $this->ctrl->setParameter($this, $this->getJobIdParameterName(), $job->getId());
521 
522  $jobs_data = $this->cron_repository->getCronJobData($job->getId());
523  $job_data = $jobs_data[0];
524 
525  $form = new ilPropertyFormGUI();
526  $form->setFormAction($this->ctrl->getFormAction($this, 'updateLegacy'));
527  $form->setTitle($this->lng->txt('cron_action_edit') . ': "' . $job->getTitle() . '"');
528 
529  if ($job->hasFlexibleSchedule()) {
530  $type = new ilRadioGroupInputGUI($this->lng->txt('cron_schedule_type'), 'type');
531  $type->setRequired(true);
532  $type->setValue($job_data['schedule_type'] === null ? null : (string) $job_data['schedule_type']);
533 
534  foreach ($job->getAllScheduleTypes() as $schedule_type) {
535  if (!in_array($schedule_type, $job->getValidScheduleTypes(), true)) {
536  continue;
537  }
538 
539  $option = new ilRadioOption(
540  $this->getScheduleTypeFormElementName($schedule_type),
541  (string) $schedule_type->value
542  );
543  $type->addOption($option);
544 
545  if (in_array($schedule_type, $job->getScheduleTypesWithValues(), true)) {
546  $scheduleValue = new ilNumberInputGUI(
547  $this->lng->txt('cron_schedule_value'),
548  $this->getScheduleValueFormElementName($schedule_type)
549  );
550  $scheduleValue->allowDecimals(false);
551  $scheduleValue->setRequired(true);
552  $scheduleValue->setSize(5);
553  if (is_numeric($job_data['schedule_type']) &&
554  JobScheduleType::tryFrom((int) $job_data['schedule_type']) === $schedule_type) {
555  $scheduleValue->setValue(
556  $job_data['schedule_value'] === null ? null : (string) $job_data['schedule_value']
557  );
558  }
559  $option->addSubItem($scheduleValue);
560  }
561  }
562 
563  $form->addItem($type);
564  }
565 
566  if ($job->hasCustomSettings()) {
567  $job->addCustomSettingsToForm($form);
568  }
569 
570  $form->addCommandButton('updateLegacy', $this->lng->txt('save'));
571  $form->addCommandButton('render', $this->lng->txt('cancel'));
572 
573  return $form;
574  }
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 264 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().

264  : void
265  {
266  $tstamp = $this->lng->txt('cronjob_last_start_unknown');
267  if ($this->settings->get('last_cronjob_start_ts')) {
269  new ilDateTime(
270  $this->settings->get('last_cronjob_start_ts'),
272  )
273  );
274  }
275 
276  $message = $this->ui_factory->messageBox()->info($this->lng->txt('cronjob_last_start') . ': ' . $tstamp);
277 
278  $cronJobs = $this->cron_repository->findAll();
279 
280  $tableFilterMediator = new JobTableFilterMediator(
281  $cronJobs,
282  $this->ui_factory,
283  $this->ui_service,
284  $this->lng
285  );
286  $filter = $tableFilterMediator->filter(
287  $this->ctrl->getFormAction(
288  $this,
289  'render',
290  '',
291  true
292  )
293  );
294 
295  $filtered_jobs = $tableFilterMediator->filteredJobs(
296  $filter
297  );
298 
299  $tbl = new JobTable(
300  $this,
301  'handleTableActions',
302  self::TABLE_ACTION_NAMESPACE,
303  self::TABLE_ACTION_PARAM_NAME,
304  self::TABLE_ACTION_IDENTIFIER_NAME,
305  $this->ui_factory,
306  $this->http->request(),
307  $this->ctrl,
308  $this->lng,
309  $filtered_jobs,
311  $this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)
312  );
313 
314  $this->tpl->setContent(
315  $this->ui_renderer->render(
316  $this->addProblematicItemsInfo(
317  $filtered_jobs,
318  $message,
319  [$message, $filter, $tbl->getComponent()]
320  )
321  )
322  );
323  }
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 758 of file class.ilCronManagerGUI.php.

References confirm().

Referenced by handleTableActions().

758  : void
759  {
760  $this->confirm('reset');
761  }
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 fn(JobEntity $entity): string => $entity->getEffectiveJobId(),
126  $tableFilterMediator->filteredJobs(
127  $filter
128  )->toArray()
129  );
130  }
131 
132  return $ids;
133  }
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 678 of file class.ilCronManagerGUI.php.

References confirm().

Referenced by handleTableActions().

678  : void
679  {
680  $this->confirm('run');
681  }
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 576 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.

576  : void
577  {
578  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
579  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
580  }
581 
582  $job_id = $this->getRequestValue($this->getJobIdParameterName(), $this->refinery->kindlyTo()->string());
583  if (!$job_id) {
584  $this->ctrl->redirect($this, 'render');
585  }
586 
587  $job = $this->cron_repository->getJobInstanceById($job_id);
588  $form = $this->initEditForm($job);
589 
590  $form_valid = false;
591  $form_data = null;
592  if ($this->http->request()->getMethod() === 'POST') {
593  $form = $form->withRequest($this->http->request());
594  $form_data = $form->getData();
595  $form_valid = $form_data !== null;
596  }
597 
598  if (!$form_valid) {
599  $this->edit($form);
600  return;
601  }
602 
603  if ($job instanceof CronJob) {
604  if ($job->hasFlexibleSchedule()) {
605  $schedule_group = $form_data[self::FORM_PARAM_MAIN_SECTION][self::FORM_PARAM_GROUP_SCHEDULE];
606 
607  $type = JobScheduleType::from(
608  (int) ltrim($schedule_group[0], self::FORM_PARAM_SCHEDULE_PREFIX)
609  );
610 
611  $value = match (true) {
612  $this->hasScheduleValue($type) => (int) $schedule_group[1][$this->getScheduleValueFormElementName(
613  $type
614  )],
615  default => null,
616  };
617 
618  $this->cron_repository->updateJobSchedule($job, $type, $value);
619  }
620 
621  if ($job->hasCustomSettings()) {
622  $job->saveCustomConfiguration($form_data[self::FORM_PARAM_JOB_INPUT]);
623  }
624 
625  $this->tpl->setOnScreenMessage('success', $this->lng->txt('cron_action_edit_success'), true);
626  $this->ctrl->redirect($this, 'render');
627  }
628 
629  $this->edit($form);
630  }
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 636 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.

636  : void
637  {
638  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
639  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
640  }
641 
642  $job_id = $this->getRequestValue($this->getJobIdParameterName(), $this->refinery->kindlyTo()->string());
643  if (!$job_id) {
644  $this->ctrl->redirect($this, 'render');
645  }
646 
647  $job = $this->cron_repository->getJobInstanceById($job_id);
648 
649  $form = $this->initLegacyEditForm($job);
650  if ($job instanceof CronJob && $form->checkInput()) {
651  $valid = true;
652  if ($job->hasCustomSettings() && !$job->saveCustomSettings($form)) {
653  $valid = false;
654  }
655 
656  if ($valid && $job->hasFlexibleSchedule()) {
657  $type = JobScheduleType::from((int) $form->getInput('type'));
658  $value = match (true) {
659  $this->hasScheduleValue($type) => (int) $form->getInput(
660  $this->getScheduleValueFormElementName($type)
661  ),
662  default => null,
663  };
664 
665  $this->cron_repository->updateJobSchedule($job, $type, $value);
666  }
667 
668  if ($valid) {
669  $this->tpl->setOnScreenMessage('success', $this->lng->txt('cron_action_edit_success'), true);
670  $this->ctrl->redirect($this, 'render');
671  }
672  }
673 
674  $form->setValuesByPost();
675  $this->editLegacy($form);
676  }
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 string ilCronManagerGUI::FORM_PARAM_SCHEDULE_PREFIX = 'schedule_'
private

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

◆ TABLE_ACTION_IDENTIFIER_NAME

const string ilCronManagerGUI::TABLE_ACTION_IDENTIFIER_NAME = 'jid'
private

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

◆ TABLE_ACTION_NAMESPACE

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

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

◆ TABLE_ACTION_PARAM_NAME

const string 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: