ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCronManagerGUI Class Reference

Class ilCronManagerGUI. More...

+ Collaboration diagram for ilCronManagerGUI:

Public Member Functions

 __construct ()
 ilCronManagerGUI constructor. More...
 
 executeCommand ()
 
 edit (ilPropertyFormGUI $a_form=null)
 
 update ()
 
 run ()
 
 confirmedRun ()
 
 activate ()
 
 confirmedActivate ()
 
 deactivate ()
 
 confirmedDeactivate ()
 
 reset ()
 
 confirmedReset ()
 
 addToExternalSettingsForm ($a_form_id)
 

Protected Member Functions

 render ()
 
 getScheduleTypeFormElementName (int $scheduleTypeId)
 
 getScheduleValueFormElementName (int $scheduleTypeId)
 
 hasScheduleValue (int $scheduleTypeId)
 
 initEditForm ($a_job_id)
 
 getMultiActionData ()
 

Protected Attributes

 $lng
 
 $ctrl
 
 $settings
 
 $tpl
 

Private Attributes

 $uiFactory
 
 $uiRenderer
 
 $uiService
 
 $repository
 
 $rbac
 
 $error
 
 $dic
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCronManagerGUI::__construct ( )

ilCronManagerGUI constructor.

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

References $DIC, repository(), and settings().

42  {
43  global $DIC;
44 
45  $this->lng = $DIC->language();
46  $this->ctrl = $DIC->ctrl();
47  $this->settings = $DIC->settings();
48  $this->tpl = $DIC->ui()->mainTemplate();
49  $this->uiFactory = $DIC->ui()->factory();
50  $this->uiRenderer = $DIC->ui()->renderer();
51  $this->uiRenderer = $DIC->ui()->renderer();
52  $this->uiService = $DIC->uiService();
53  $this->dic = $DIC;
54  $this->rbac = $DIC->rbac();
55  $this->error = $DIC['ilErr'];
56  $this->repository = new ilCronJobRepositoryImpl();
57 
58  $this->lng->loadLanguageModule('cron');
59  $this->lng->loadLanguageModule('cmps');
60  }
settings()
Definition: settings.php:2
repository()
Definition: repository.php:5
global $DIC
Definition: goto.php:24
Class ilCronJobRepositoryImpl.
+ Here is the call graph for this function:

Member Function Documentation

◆ activate()

ilCronManagerGUI::activate ( )

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

344  {
345  $this->confirm("activate");
346  }

◆ addToExternalSettingsForm()

ilCronManagerGUI::addToExternalSettingsForm (   $a_form_id)

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

References $data, ilCronManager\getCronJobData(), and ilCronManager\getJobInstance().

498  {
499  $fields = array();
500 
502  foreach ($data as $item) {
504  $item["job_id"],
505  $item["component"],
506  $item["class"],
507  $item["path"]
508  );
509 
510  if (method_exists($job, "addToExternalSettingsForm")) {
511  $job->addToExternalSettingsForm($a_form_id, $fields, $item["job_status"]);
512  }
513  }
514 
515  if (sizeof($fields)) {
516  return array("cron_jobs" => array("jumpToCronJobs", $fields));
517  }
518  }
static getJobInstance($a_id, $a_component, $a_class, $a_path=null)
Get job instance (by job data)
$data
Definition: storeScorm.php:23
static getCronJobData($a_id=null, $a_include_inactive=true)
Get cron job configuration/execution data.
+ Here is the call graph for this function:

◆ confirmedActivate()

ilCronManagerGUI::confirmedActivate ( )

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

References ilCronManager\activateJob(), getMultiActionData(), ilCronManager\isJobInactive(), ilCronManager\resetJob(), and SYSTEM_FOLDER_ID.

349  {
350  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
351  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
352  }
353 
354  $jobs = $this->getMultiActionData();
355  if ($jobs) {
356  foreach ($jobs as $job) {
357  if (ilCronManager::isJobInactive($job->getId())) {
359  ilCronManager::activateJob($job, true);
360  }
361  }
362 
363  ilUtil::sendSuccess($this->lng->txt("cron_action_activate_success"), true);
364  }
365 
366  $this->ctrl->redirect($this, "render");
367  }
static activateJob(ilCronJob $a_job, $a_manual=false)
Activate cron job.
static isJobInactive($a_job_id)
Check if given job is currently inactive.
const SYSTEM_FOLDER_ID
Definition: constants.php:33
static resetJob(ilCronJob $a_job)
Reset job.
+ Here is the call graph for this function:

◆ confirmedDeactivate()

ilCronManagerGUI::confirmedDeactivate ( )

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

References ilCronManager\deactivateJob(), getMultiActionData(), ilCronManager\isJobActive(), and SYSTEM_FOLDER_ID.

375  {
376  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
377  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
378  }
379 
380  $jobs = $this->getMultiActionData();
381  if ($jobs) {
382  foreach ($jobs as $job) {
383  if (ilCronManager::isJobActive($job->getId())) {
384  ilCronManager::deactivateJob($job, true);
385  }
386  }
387 
388  ilUtil::sendSuccess($this->lng->txt("cron_action_deactivate_success"), true);
389  }
390 
391  $this->ctrl->redirect($this, "render");
392  }
static deactivateJob(ilCronJob $a_job, $a_manual=false)
Deactivate cron job.
const SYSTEM_FOLDER_ID
Definition: constants.php:33
static isJobActive($a_job_id)
Check if given job is currently active.
+ Here is the call graph for this function:

◆ confirmedReset()

ilCronManagerGUI::confirmedReset ( )

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

References getMultiActionData(), ilCronManager\resetJob(), and SYSTEM_FOLDER_ID.

400  {
401  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
402  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
403  }
404 
405  $jobs = $this->getMultiActionData();
406  if ($jobs) {
407  foreach ($jobs as $job) {
409  }
410  ilUtil::sendSuccess($this->lng->txt("cron_action_reset_success"), true);
411  }
412 
413  $this->ctrl->redirect($this, "render");
414  }
const SYSTEM_FOLDER_ID
Definition: constants.php:33
static resetJob(ilCronJob $a_job)
Reset job.
+ Here is the call graph for this function:

◆ confirmedRun()

ilCronManagerGUI::confirmedRun ( )

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

References $_GET, ilCronManager\runJobManual(), ilUtil\sendFailure(), and SYSTEM_FOLDER_ID.

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  $job_id = $_GET["jid"];
332  if ($job_id) {
333  if (ilCronManager::runJobManual($job_id)) {
334  ilUtil::sendSuccess($this->lng->txt("cron_action_run_success"), true);
335  } else {
336  ilUtil::sendFailure($this->lng->txt("cron_action_run_fail"), true);
337  }
338  }
339 
340  $this->ctrl->redirect($this, "render");
341  }
$_GET["client_id"]
static runJobManual($a_job_id)
Run single job manually.
const SYSTEM_FOLDER_ID
Definition: constants.php:33
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
+ Here is the call graph for this function:

◆ deactivate()

ilCronManagerGUI::deactivate ( )

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

370  {
371  $this->confirm("deactivate");
372  }

◆ edit()

ilCronManagerGUI::edit ( ilPropertyFormGUI  $a_form = null)

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

References initEditForm(), and SYSTEM_FOLDER_ID.

Referenced by update().

122  {
123  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
124  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
125  }
126 
127  $id = $_REQUEST["jid"];
128  if (!$id) {
129  $this->ctrl->redirect($this, "render");
130  }
131 
132  if (!$a_form) {
133  $a_form = $this->initEditForm($id);
134  }
135 
136  $this->tpl->setContent($a_form->getHTML());
137  }
const SYSTEM_FOLDER_ID
Definition: constants.php:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilCronManagerGUI::executeCommand ( )

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

References initEditForm(), ilUtil\stripSlashes(), and SYSTEM_FOLDER_ID.

62  : void
63  {
64  if (!$this->rbac->system()->checkAccess('visible,read', SYSTEM_FOLDER_ID)) {
65  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
66  }
67 
68  $class = $this->ctrl->getNextClass($this);
69 
70  switch (strtolower($class)) {
71  case strtolower(ilPropertyFormGUI::class):
72  $form = $this->initEditForm(ilUtil::stripSlashes($_REQUEST['jid']));
73  $this->ctrl->forwardCommand($form);
74  break;
75  }
76 
77  $cmd = $this->ctrl->getCmd('render');
78  $this->$cmd();
79  }
const SYSTEM_FOLDER_ID
Definition: constants.php:33
+ Here is the call graph for this function:

◆ getMultiActionData()

ilCronManagerGUI::getMultiActionData ( )
protected

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

References $res, ilCronManager\getJobInstanceById(), ilUtil\sendFailure(), and SYSTEM_FOLDER_ID.

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

417  {
418  $res = array();
419 
420  if ($_REQUEST["jid"]) {
421  $job_id = trim($_REQUEST["jid"]);
422  $job = ilCronManager::getJobInstanceById($job_id);
423  if ($job) {
424  $res[$job_id] = $job;
425  }
426  } elseif (is_array($_REQUEST["mjid"])) {
427  foreach ($_REQUEST["mjid"] as $job_id) {
428  $job = ilCronManager::getJobInstanceById($job_id);
429  if ($job) {
430  $res[$job_id] = $job;
431  }
432  }
433  }
434 
435  return $res;
436  }
foreach($_POST as $key=> $value) $res
static getJobInstanceById($a_job_id)
Get job instance (by job id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getScheduleTypeFormElementName()

ilCronManagerGUI::getScheduleTypeFormElementName ( int  $scheduleTypeId)
protected
Parameters
int$scheduleTypeId
Returns
string
Exceptions

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

References ilCronJob\SCHEDULE_TYPE_DAILY, ilCronJob\SCHEDULE_TYPE_IN_DAYS, ilCronJob\SCHEDULE_TYPE_IN_HOURS, ilCronJob\SCHEDULE_TYPE_IN_MINUTES, ilCronJob\SCHEDULE_TYPE_MONTHLY, ilCronJob\SCHEDULE_TYPE_QUARTERLY, ilCronJob\SCHEDULE_TYPE_WEEKLY, and ilCronJob\SCHEDULE_TYPE_YEARLY.

Referenced by initEditForm().

145  {
146  switch ($scheduleTypeId) {
148  return $this->lng->txt('cron_schedule_daily');
149 
151  return $this->lng->txt('cron_schedule_weekly');
152 
154  return $this->lng->txt('cron_schedule_monthly');
155 
157  return $this->lng->txt('cron_schedule_quarterly');
158 
160  return $this->lng->txt('cron_schedule_yearly');
161 
163  return sprintf($this->lng->txt('cron_schedule_in_minutes'), 'x');
164 
166  return sprintf($this->lng->txt('cron_schedule_in_hours'), 'x');
167 
169  return sprintf($this->lng->txt('cron_schedule_in_days'), 'x');
170  }
171 
172  throw new \InvalidArgumentException(sprintf('The passed argument %s is invalid!', var_export($scheduleTypeId, 1)));
173  }
const SCHEDULE_TYPE_IN_MINUTES
const SCHEDULE_TYPE_MONTHLY
const SCHEDULE_TYPE_WEEKLY
const SCHEDULE_TYPE_IN_DAYS
const SCHEDULE_TYPE_YEARLY
const SCHEDULE_TYPE_DAILY
const SCHEDULE_TYPE_QUARTERLY
const SCHEDULE_TYPE_IN_HOURS
+ Here is the caller graph for this function:

◆ getScheduleValueFormElementName()

ilCronManagerGUI::getScheduleValueFormElementName ( int  $scheduleTypeId)
protected
Parameters
int$scheduleTypeId
Returns
string
Exceptions

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

References ilCronJob\SCHEDULE_TYPE_IN_DAYS, ilCronJob\SCHEDULE_TYPE_IN_HOURS, and ilCronJob\SCHEDULE_TYPE_IN_MINUTES.

Referenced by initEditForm(), and update().

181  {
182  switch ($scheduleTypeId) {
184  return 'smini';
185 
187  return 'shri';
188 
190  return 'sdyi';
191  }
192 
193  throw new \InvalidArgumentException(sprintf('The passed argument %s is invalid!', var_export($scheduleTypeId, 1)));
194  }
const SCHEDULE_TYPE_IN_MINUTES
const SCHEDULE_TYPE_IN_DAYS
const SCHEDULE_TYPE_IN_HOURS
+ Here is the caller graph for this function:

◆ hasScheduleValue()

ilCronManagerGUI::hasScheduleValue ( int  $scheduleTypeId)
protected
Parameters
int$scheduleTypeId
Returns
bool

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

References ilCronJob\SCHEDULE_TYPE_IN_DAYS, ilCronJob\SCHEDULE_TYPE_IN_HOURS, and ilCronJob\SCHEDULE_TYPE_IN_MINUTES.

Referenced by update().

200  : bool
201  {
202  return in_array(
203  $scheduleTypeId,
204  [
208  ]
209  );
210  }
const SCHEDULE_TYPE_IN_MINUTES
const SCHEDULE_TYPE_IN_DAYS
const SCHEDULE_TYPE_IN_HOURS
+ Here is the caller graph for this function:

◆ initEditForm()

ilCronManagerGUI::initEditForm (   $a_job_id)
protected

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

References $data, $type, ilNumberInputGUI\allowDecimals(), ilCronManager\getCronJobData(), ilCronManager\getJobInstanceById(), getScheduleTypeFormElementName(), and getScheduleValueFormElementName().

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

213  {
214  $job = ilCronManager::getJobInstanceById($a_job_id);
215  if (!$job) {
216  $this->ctrl->redirect($this, "render");
217  }
218 
219  $this->ctrl->setParameter($this, "jid", $a_job_id);
220 
221  $jobData = ilCronManager::getCronJobData($job->getId());
222  $data = array_pop($jobData);
223 
224  include_once("Services/Cron/classes/class.ilCronJob.php");
225  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
226  $form = new ilPropertyFormGUI();
227  $form->setFormAction($this->ctrl->getFormAction($this, "update"));
228  $form->setTitle($this->lng->txt("cron_action_edit") . ': "' . $job->getTitle() . '"');
229 
230  if ($job->hasFlexibleSchedule()) {
231  $type = new ilRadioGroupInputGUI($this->lng->txt('cron_schedule_type'), 'type');
232  $type->setRequired(true);
233  $type->setValue($data['schedule_type']);
234 
235  foreach ($job->getAllScheduleTypes() as $typeId) {
236  if (!in_array($typeId, $job->getValidScheduleTypes())) {
237  continue;
238  }
239 
240  $option = new ilRadioOption(
241  $this->getScheduleTypeFormElementName($typeId),
242  $typeId
243  );
244  $type->addOption($option);
245 
246  if (in_array($typeId, $job->getScheduleTypesWithValues())) {
247  $scheduleValue = new ilNumberInputGUI(
248  $this->lng->txt('cron_schedule_value'),
249  $this->getScheduleValueFormElementName($typeId)
250  );
251  $scheduleValue->allowDecimals(false);
252  $scheduleValue->setRequired(true);
253  $scheduleValue->setSize(5);
254  if ($data['schedule_type'] == $typeId) {
255  $scheduleValue->setValue($data['schedule_value']);
256  }
257  $option->addSubItem($scheduleValue);
258  }
259  }
260 
261  $form->addItem($type);
262  }
263 
264  if ($job->hasCustomSettings()) {
265  $job->addCustomSettingsToForm($form);
266  }
267 
268  $form->addCommandButton("update", $this->lng->txt("save"));
269  $form->addCommandButton("render", $this->lng->txt("cancel"));
270 
271  return $form;
272  }
This class represents an option in a radio group.
$data
Definition: storeScorm.php:23
getScheduleValueFormElementName(int $scheduleTypeId)
This class represents a property form user interface.
$type
allowDecimals($a_value)
Toggle Decimals.
static getCronJobData($a_id=null, $a_include_inactive=true)
Get cron job configuration/execution data.
This class represents a property in a property form.
static getJobInstanceById($a_job_id)
Get job instance (by job id)
This class represents a number property in a property form.
getScheduleTypeFormElementName(int $scheduleTypeId)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ilCronManagerGUI::render ( )
protected

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

References $message, ilDatePresentation\formatDate(), IL_CAL_UNIX, repository(), settings(), and SYSTEM_FOLDER_ID.

81  : void
82  {
83  $tstamp = $this->lng->txt('cronjob_last_start_unknown');
84  if ($this->settings->get('last_cronjob_start_ts')) {
85  $tstamp = ilDatePresentation::formatDate(new ilDateTime($this->settings->get('last_cronjob_start_ts'), IL_CAL_UNIX));
86  }
87 
88  $message = $this->uiFactory->messageBox()->info($this->lng->txt('cronjob_last_start') . ': ' . $tstamp);
89 
90  $cronJobs = $this->repository->findAll();
91 
92  $tableFilterMediator = new ilCronManagerTableFilterMediator(
93  $cronJobs,
94  $this->uiFactory,
95  $this->uiService,
96  $this->lng
97  );
98  $filter = $tableFilterMediator->filter($this->ctrl->getFormAction(
99  $this,
100  'render',
101  '',
102  true
103  ));
104 
105  $tbl = new ilCronManagerTableGUI(
106  $this,
107  'render',
108  $this->dic,
109  $this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)
110  );
111  $this->tpl->setContent(implode('', [
112  $this->uiRenderer->render([$message, $filter]),
113  $tbl->populate(
114  $tableFilterMediator->filteredJobs(
115  $filter
116  )
117  )->getHTML()
118  ]));
119  }
settings()
Definition: settings.php:2
Class ilCronManagerTableFilterMediator.
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
const SYSTEM_FOLDER_ID
Definition: constants.php:33
repository()
Definition: repository.php:5
$message
Definition: xapiexit.php:14
List all active cron jobs.
+ Here is the call graph for this function:

◆ reset()

ilCronManagerGUI::reset ( )

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

395  {
396  $this->confirm("reset");
397  }

◆ run()

ilCronManagerGUI::run ( )

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

321  {
322  $this->confirm("run");
323  }

◆ update()

ilCronManagerGUI::update ( )

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

References $type, $valid, edit(), ilCronManager\getJobInstanceById(), getScheduleValueFormElementName(), hasScheduleValue(), initEditForm(), SYSTEM_FOLDER_ID, and ilCronManager\updateJobSchedule().

275  {
276  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
277  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
278  }
279 
280  $id = $_REQUEST["jid"];
281  if (!$id) {
282  $this->ctrl->redirect($this, "render");
283  }
284 
285  $form = $this->initEditForm($id);
286  if ($form->checkInput()) {
288  if ($job) {
289  $valid = true;
290  if ($job->hasCustomSettings() &&
291  !$job->saveCustomSettings($form)) {
292  $valid = false;
293  }
294 
295  if ($valid && $job->hasFlexibleSchedule()) {
296  $type = $form->getInput("type");
297  switch (true) {
298  case $this->hasScheduleValue($type):
299  $value = $form->getInput($this->getScheduleValueFormElementName($type));
300  break;
301 
302  default:
303  $value = null;
304  break;
305  }
306 
308  }
309  if ($valid) {
310  ilUtil::sendSuccess($this->lng->txt("cron_action_edit_success"), true);
311  $this->ctrl->redirect($this, "render");
312  }
313  }
314  }
315 
316  $form->setValuesByPost();
317  $this->edit($form);
318  }
getScheduleValueFormElementName(int $scheduleTypeId)
$type
$valid
const SYSTEM_FOLDER_ID
Definition: constants.php:33
static getJobInstanceById($a_job_id)
Get job instance (by job id)
hasScheduleValue(int $scheduleTypeId)
edit(ilPropertyFormGUI $a_form=null)
static updateJobSchedule(ilCronJob $a_job, $a_schedule_type, $a_schedule_value)
Update job schedule.
+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilCronManagerGUI::$ctrl
protected

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

◆ $dic

ilCronManagerGUI::$dic
private

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

◆ $error

ilCronManagerGUI::$error
private

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

◆ $lng

ilCronManagerGUI::$lng
protected

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

◆ $rbac

ilCronManagerGUI::$rbac
private

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

◆ $repository

ilCronManagerGUI::$repository
private

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

◆ $settings

ilCronManagerGUI::$settings
protected

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

◆ $tpl

ilCronManagerGUI::$tpl
protected

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

◆ $uiFactory

ilCronManagerGUI::$uiFactory
private

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

◆ $uiRenderer

ilCronManagerGUI::$uiRenderer
private

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

◆ $uiService

ilCronManagerGUI::$uiService
private

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


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