ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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

 $rbac
 
 $error
 
 $dic
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCronManagerGUI::__construct ( )

ilCronManagerGUI constructor.

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

References $DIC, and settings().

48  {
49  global $DIC;
50 
51  $this->lng = $DIC->language();
52  $this->ctrl = $DIC->ctrl();
53  $this->settings = $DIC->settings();
54  $this->tpl = $DIC->ui()->mainTemplate();
55  $this->dic = $DIC;
56  $this->rbac = $DIC->rbac();
57  $this->error = $DIC['ilErr'];
58 
59  $this->lng->loadLanguageModule('cron');
60  }
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

Member Function Documentation

◆ activate()

ilCronManagerGUI::activate ( )

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

323  {
324  $this->confirm("activate");
325  }

◆ addToExternalSettingsForm()

ilCronManagerGUI::addToExternalSettingsForm (   $a_form_id)

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

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

476  {
477  $fields = array();
478 
480  foreach ($data as $item) {
482  $item["job_id"],
483  $item["component"],
484  $item["class"],
485  $item["path"]
486  );
487 
488  if (method_exists($job, "addToExternalSettingsForm")) {
489  $job->addToExternalSettingsForm($a_form_id, $fields, $item["job_status"]);
490  }
491  }
492 
493  if (sizeof($fields)) {
494  return array("cron_jobs" => array("jumpToCronJobs", $fields));
495  }
496  }
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 327 of file class.ilCronManagerGUI.php.

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

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  $jobs = $this->getMultiActionData();
334  if ($jobs) {
335  foreach ($jobs as $job) {
336  if (ilCronManager::isJobInactive($job->getId())) {
338  ilCronManager::activateJob($job, true);
339  }
340  }
341 
342  ilUtil::sendSuccess($this->lng->txt("cron_action_activate_success"), true);
343  }
344 
345  $this->ctrl->redirect($this, "render");
346  }
static activateJob(ilCronJob $a_job, $a_manual=false)
Activate cron job.
static isJobInactive($a_job_id)
Check if given job is currently inactive.
static resetJob(ilCronJob $a_job)
Reset job.
+ Here is the call graph for this function:

◆ confirmedDeactivate()

ilCronManagerGUI::confirmedDeactivate ( )

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

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

354  {
355  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
356  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
357  }
358 
359  $jobs = $this->getMultiActionData();
360  if ($jobs) {
361  foreach ($jobs as $job) {
362  if (ilCronManager::isJobActive($job->getId())) {
363  ilCronManager::deactivateJob($job, true);
364  }
365  }
366 
367  ilUtil::sendSuccess($this->lng->txt("cron_action_deactivate_success"), true);
368  }
369 
370  $this->ctrl->redirect($this, "render");
371  }
static deactivateJob(ilCronJob $a_job, $a_manual=false)
Deactivate cron job.
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 378 of file class.ilCronManagerGUI.php.

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

379  {
380  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
381  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
382  }
383 
384  $jobs = $this->getMultiActionData();
385  if ($jobs) {
386  foreach ($jobs as $job) {
388  }
389  ilUtil::sendSuccess($this->lng->txt("cron_action_reset_success"), true);
390  }
391 
392  $this->ctrl->redirect($this, "render");
393  }
static resetJob(ilCronJob $a_job)
Reset job.
+ Here is the call graph for this function:

◆ confirmedRun()

ilCronManagerGUI::confirmedRun ( )

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

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

305  {
306  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
307  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
308  }
309 
310  $job_id = $_GET["jid"];
311  if ($job_id) {
312  if (ilCronManager::runJobManual($job_id)) {
313  ilUtil::sendSuccess($this->lng->txt("cron_action_run_success"), true);
314  } else {
315  ilUtil::sendFailure($this->lng->txt("cron_action_run_fail"), true);
316  }
317  }
318 
319  $this->ctrl->redirect($this, "render");
320  }
$_GET["client_id"]
static runJobManual($a_job_id)
Run single job manually.
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 348 of file class.ilCronManagerGUI.php.

349  {
350  $this->confirm("deactivate");
351  }

◆ edit()

ilCronManagerGUI::edit ( ilPropertyFormGUI  $a_form = null)

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

References initEditForm().

Referenced by update().

102  {
103  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
104  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
105  }
106 
107  $id = $_REQUEST["jid"];
108  if (!$id) {
109  $this->ctrl->redirect($this, "render");
110  }
111 
112  if (!$a_form) {
113  $a_form = $this->initEditForm($id);
114  }
115 
116  $this->tpl->setContent($a_form->getHTML());
117  }
+ 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().

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 ($class) {
71  case "ilpropertyformgui":
72  $form = $this->initEditForm($_REQUEST['jid']);
73  $this->ctrl->forwardCommand($form);
74  break;
75  }
76  $cmd = $this->ctrl->getCmd("render");
77  $this->$cmd();
78 
79  return true;
80  }
+ Here is the call graph for this function:

◆ getMultiActionData()

ilCronManagerGUI::getMultiActionData ( )
protected

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

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

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

396  {
397  $res = array();
398 
399  if ($_REQUEST["jid"]) {
400  $job_id = trim($_REQUEST["jid"]);
401  $job = ilCronManager::getJobInstanceById($job_id);
402  if ($job) {
403  $res[$job_id] = $job;
404  }
405  } elseif (is_array($_REQUEST["mjid"])) {
406  foreach ($_REQUEST["mjid"] as $job_id) {
407  $job = ilCronManager::getJobInstanceById($job_id);
408  if ($job) {
409  $res[$job_id] = $job;
410  }
411  }
412  }
413 
414  return $res;
415  }
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 124 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().

125  {
126  switch ($scheduleTypeId) {
128  return $this->lng->txt('cron_schedule_daily');
129 
131  return $this->lng->txt('cron_schedule_weekly');
132 
134  return $this->lng->txt('cron_schedule_monthly');
135 
137  return $this->lng->txt('cron_schedule_quarterly');
138 
140  return $this->lng->txt('cron_schedule_yearly');
141 
143  return sprintf($this->lng->txt('cron_schedule_in_minutes'), 'x');
144 
146  return sprintf($this->lng->txt('cron_schedule_in_hours'), 'x');
147 
149  return sprintf($this->lng->txt('cron_schedule_in_days'), 'x');
150  }
151 
152  throw new \InvalidArgumentException(sprintf('The passed argument %s is invalid!', var_export($scheduleTypeId, 1)));
153  }
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 160 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().

161  {
162  switch ($scheduleTypeId) {
164  return 'smini';
165 
167  return 'shri';
168 
170  return 'sdyi';
171  }
172 
173  throw new \InvalidArgumentException(sprintf('The passed argument %s is invalid!', var_export($scheduleTypeId, 1)));
174  }
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 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 update().

180  : bool
181  {
182  return in_array(
183  $scheduleTypeId,
184  [
188  ]
189  );
190  }
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 192 of file class.ilCronManagerGUI.php.

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

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

193  {
194  $job = ilCronManager::getJobInstanceById($a_job_id);
195  if (!$job) {
196  $this->ctrl->redirect($this, "render");
197  }
198 
199  $this->ctrl->setParameter($this, "jid", $a_job_id);
200 
201  $data = array_pop(ilCronManager::getCronJobData($job->getId()));
202 
203  include_once("Services/Cron/classes/class.ilCronJob.php");
204  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
205  $form = new ilPropertyFormGUI();
206  $form->setFormAction($this->ctrl->getFormAction($this, "update"));
207  $form->setTitle($this->lng->txt("cron_action_edit") . ': "' . $job->getTitle() . '"');
208 
209  if ($job->hasFlexibleSchedule()) {
210  $type = new ilRadioGroupInputGUI($this->lng->txt('cron_schedule_type'), 'type');
211  $type->setRequired(true);
212  $type->setValue($data['schedule_type']);
213 
214  foreach ($job->getAllScheduleTypes() as $typeId) {
215  if (!in_array($typeId, $job->getValidScheduleTypes())) {
216  continue;
217  }
218 
219  $option = new ilRadioOption(
220  $this->getScheduleTypeFormElementName($typeId),
221  $typeId
222  );
223  $type->addOption($option);
224 
225  if (in_array($typeId, $job->getScheduleTypesWithValues())) {
226  $scheduleValue = new ilNumberInputGUI(
227  $this->lng->txt('cron_schedule_value'),
228  $this->getScheduleValueFormElementName($typeId)
229  );
230  $scheduleValue->allowDecimals(false);
231  $scheduleValue->setRequired(true);
232  $scheduleValue->setSize(5);
233  if ($data['schedule_type'] == $typeId) {
234  $scheduleValue->setValue($data['schedule_value']);
235  }
236  $option->addSubItem($scheduleValue);
237  }
238  }
239 
240  $form->addItem($type);
241  }
242 
243  if ($job->hasCustomSettings()) {
244  $job->addCustomSettingsToForm($form);
245  }
246 
247  $form->addCommandButton("update", $this->lng->txt("save"));
248  $form->addCommandButton("render", $this->lng->txt("cancel"));
249 
250  return $form;
251  }
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 82 of file class.ilCronManagerGUI.php.

References ilDatePresentation\formatDate(), IL_CAL_UNIX, ilUtil\sendInfo(), and settings().

83  {
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  } else {
87  $tstamp = $this->lng->txt('cronjob_last_start_unknown');
88  }
89  ilUtil::sendInfo($this->lng->txt('cronjob_last_start') . ": " . $tstamp);
90 
91  include_once "Services/Cron/classes/class.ilCronManagerTableGUI.php";
92  $tbl = new ilCronManagerTableGUI(
93  $this,
94  "render",
95  $this->dic,
96  $this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)
97  );
98  $this->tpl->setContent($tbl->getHTML());
99  }
settings()
Definition: settings.php:2
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
List all active cron jobs.
+ Here is the call graph for this function:

◆ reset()

ilCronManagerGUI::reset ( )

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

374  {
375  $this->confirm("reset");
376  }

◆ run()

ilCronManagerGUI::run ( )

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

300  {
301  $this->confirm("run");
302  }

◆ update()

ilCronManagerGUI::update ( )

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

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

254  {
255  if (!$this->rbac->system()->checkAccess('write', SYSTEM_FOLDER_ID)) {
256  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
257  }
258 
259  $id = $_REQUEST["jid"];
260  if (!$id) {
261  $this->ctrl->redirect($this, "render");
262  }
263 
264  $form = $this->initEditForm($id);
265  if ($form->checkInput()) {
267  if ($job) {
268  $valid = true;
269  if ($job->hasCustomSettings() &&
270  !$job->saveCustomSettings($form)) {
271  $valid = false;
272  }
273 
274  if ($valid && $job->hasFlexibleSchedule()) {
275  $type = $form->getInput("type");
276  switch (true) {
277  case $this->hasScheduleValue($type):
278  $value = $form->getInput($this->getScheduleValueFormElementName($type));
279  break;
280 
281  default:
282  $value = null;
283  break;
284  }
285 
287  }
288  if ($valid) {
289  ilUtil::sendSuccess($this->lng->txt("cron_action_edit_success"), true);
290  $this->ctrl->redirect($this, "render");
291  }
292  }
293  }
294 
295  $form->setValuesByPost();
296  $this->edit($form);
297  }
getScheduleValueFormElementName(int $scheduleTypeId)
$type
$valid
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 26 of file class.ilCronManagerGUI.php.

◆ $dic

ilCronManagerGUI::$dic
private

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

◆ $error

ilCronManagerGUI::$error
private

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

◆ $lng

ilCronManagerGUI::$lng
protected

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

◆ $rbac

ilCronManagerGUI::$rbac
private

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

◆ $settings

ilCronManagerGUI::$settings
protected

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

◆ $tpl

ilCronManagerGUI::$tpl
protected

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


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