ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCronManagerGUI::__construct ( )

ilCronManagerGUI constructor.

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

References $DIC, 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 
50  $this->lng->loadLanguageModule('cron');
51  }
settings()
Definition: settings.php:2
global $DIC
Definition: saml.php:7
+ Here is the call graph for this function:

Member Function Documentation

◆ activate()

ilCronManagerGUI::activate ( )

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

293  {
294  $this->confirm("activate");
295  }

◆ addToExternalSettingsForm()

ilCronManagerGUI::addToExternalSettingsForm (   $a_form_id)

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

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

430  {
431  $fields = array();
432 
434  foreach ($data as $item) {
436  $item["job_id"],
437  $item["component"],
438  $item["class"],
439  $item["path"]
440  );
441 
442  if (method_exists($job, "addToExternalSettingsForm")) {
443  $job->addToExternalSettingsForm($a_form_id, $fields, $item["job_status"]);
444  }
445  }
446 
447  if (sizeof($fields)) {
448  return array("cron_jobs" => array("jumpToCronJobs", $fields));
449  }
450  }
static getJobInstance($a_id, $a_component, $a_class, $a_path=null)
Get job instance (by job data)
static getCronJobData($a_id=null, $a_include_inactive=true)
Get cron job configuration/execution data.
$data
Definition: bench.php:6
+ Here is the call graph for this function:

◆ confirmedActivate()

ilCronManagerGUI::confirmedActivate ( )

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

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

298  {
299  $jobs = $this->getMultiActionData();
300  if ($jobs) {
301  foreach ($jobs as $job) {
302  if (ilCronManager::isJobInactive($job->getId())) {
304  ilCronManager::activateJob($job, true);
305  }
306  }
307 
308  ilUtil::sendSuccess($this->lng->txt("cron_action_activate_success"), true);
309  }
310 
311  $this->ctrl->redirect($this, "render");
312  }
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 319 of file class.ilCronManagerGUI.php.

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

320  {
321  $jobs = $this->getMultiActionData();
322  if ($jobs) {
323  foreach ($jobs as $job) {
324  if (ilCronManager::isJobActive($job->getId())) {
325  ilCronManager::deactivateJob($job, true);
326  }
327  }
328 
329  ilUtil::sendSuccess($this->lng->txt("cron_action_deactivate_success"), true);
330  }
331 
332  $this->ctrl->redirect($this, "render");
333  }
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 340 of file class.ilCronManagerGUI.php.

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

341  {
342  $jobs = $this->getMultiActionData();
343  if ($jobs) {
344  foreach ($jobs as $job) {
346  }
347  ilUtil::sendSuccess($this->lng->txt("cron_action_reset_success"), true);
348  }
349 
350  $this->ctrl->redirect($this, "render");
351  }
static resetJob(ilCronJob $a_job)
Reset job.
+ Here is the call graph for this function:

◆ confirmedRun()

ilCronManagerGUI::confirmedRun ( )

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

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

279  {
280  $job_id = $_GET["jid"];
281  if ($job_id) {
282  if (ilCronManager::runJobManual($job_id)) {
283  ilUtil::sendSuccess($this->lng->txt("cron_action_run_success"), true);
284  } else {
285  ilUtil::sendFailure($this->lng->txt("cron_action_run_fail"), true);
286  }
287  }
288 
289  $this->ctrl->redirect($this, "render");
290  }
$_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 314 of file class.ilCronManagerGUI.php.

315  {
316  $this->confirm("deactivate");
317  }

◆ edit()

ilCronManagerGUI::edit ( ilPropertyFormGUI  $a_form = null)

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

References $id, and initEditForm().

Referenced by update().

84  {
85  $id = $_REQUEST["jid"];
86  if (!$id) {
87  $this->ctrl->redirect($this, "render");
88  }
89 
90  if (!$a_form) {
91  $a_form = $this->initEditForm($id);
92  }
93 
94  $this->tpl->setContent($a_form->getHTML());
95  }
if(!array_key_exists('StateId', $_REQUEST)) $id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilCronManagerGUI::executeCommand ( )

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

References $form, and initEditForm().

54  {
55  $class = $this->ctrl->getNextClass($this);
56 
57  switch ($class) {
58  case "ilpropertyformgui":
59  $form = $this->initEditForm($_REQUEST['jid']);
60  $this->ctrl->forwardCommand($form);
61  break;
62  }
63  $cmd = $this->ctrl->getCmd("render");
64  $this->$cmd();
65 
66  return true;
67  }
if(isset($_POST['submit'])) $form
+ Here is the call graph for this function:

◆ getMultiActionData()

ilCronManagerGUI::getMultiActionData ( )
protected

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

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

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

354  {
355  $res = array();
356 
357  if ($_REQUEST["jid"]) {
358  $job_id = trim($_REQUEST["jid"]);
359  $job = ilCronManager::getJobInstanceById($job_id);
360  if ($job) {
361  $res[$job_id] = $job;
362  }
363  } elseif (is_array($_REQUEST["mjid"])) {
364  foreach ($_REQUEST["mjid"] as $job_id) {
365  $job = ilCronManager::getJobInstanceById($job_id);
366  if ($job) {
367  $res[$job_id] = $job;
368  }
369  }
370  }
371 
372  return $res;
373  }
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 102 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().

103  {
104  switch ($scheduleTypeId) {
106  return $this->lng->txt('cron_schedule_daily');
107 
109  return $this->lng->txt('cron_schedule_weekly');
110 
112  return $this->lng->txt('cron_schedule_monthly');
113 
115  return $this->lng->txt('cron_schedule_quarterly');
116 
118  return $this->lng->txt('cron_schedule_yearly');
119 
121  return sprintf($this->lng->txt('cron_schedule_in_minutes'), 'x');
122 
124  return sprintf($this->lng->txt('cron_schedule_in_hours'), 'x');
125 
127  return sprintf($this->lng->txt('cron_schedule_in_days'), 'x');
128  }
129 
130  throw new \InvalidArgumentException(sprintf('The passed argument %s is invalid!', var_export($scheduleTypeId, 1)));
131  }
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 138 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().

139  {
140  switch ($scheduleTypeId) {
142  return 'smini';
143 
145  return 'shri';
146 
148  return 'sdyi';
149  }
150 
151  throw new \InvalidArgumentException(sprintf('The passed argument %s is invalid!', var_export($scheduleTypeId, 1)));
152  }
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 158 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().

158  : bool
159  {
160  return in_array(
161  $scheduleTypeId,
162  [
166  ]
167  );
168  }
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 170 of file class.ilCronManagerGUI.php.

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

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

171  {
172  $job = ilCronManager::getJobInstanceById($a_job_id);
173  if (!$job) {
174  $this->ctrl->redirect($this, "render");
175  }
176 
177  $this->ctrl->setParameter($this, "jid", $a_job_id);
178 
179  $data = array_pop(ilCronManager::getCronJobData($job->getId()));
180 
181  include_once("Services/Cron/classes/class.ilCronJob.php");
182  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
183  $form = new ilPropertyFormGUI();
184  $form->setFormAction($this->ctrl->getFormAction($this, "update"));
185  $form->setTitle($this->lng->txt("cron_action_edit") . ': "' . $job->getTitle() . '"');
186 
187  if ($job->hasFlexibleSchedule()) {
188  $type = new ilRadioGroupInputGUI($this->lng->txt('cron_schedule_type'), 'type');
189  $type->setRequired(true);
190  $type->setValue($data['schedule_type']);
191 
192  foreach ($job->getAllScheduleTypes() as $typeId) {
193  if (!in_array($typeId, $job->getValidScheduleTypes())) {
194  continue;
195  }
196 
197  $option = new ilRadioOption(
198  $this->getScheduleTypeFormElementName($typeId),
199  $typeId
200  );
201  $type->addOption($option);
202 
203  if (in_array($typeId, $job->getScheduleTypesWithValues())) {
204  $scheduleValue = new ilNumberInputGUI(
205  $this->lng->txt('cron_schedule_value'),
206  $this->getScheduleValueFormElementName($typeId)
207  );
208  $scheduleValue->allowDecimals(false);
209  $scheduleValue->setRequired(true);
210  $scheduleValue->setSize(5);
211  if ($data['schedule_type'] == $typeId) {
212  $scheduleValue->setValue($data['schedule_value']);
213  }
214  $option->addSubItem($scheduleValue);
215  }
216  }
217 
218  $form->addItem($type);
219  }
220 
221  if ($job->hasCustomSettings()) {
222  $job->addCustomSettingsToForm($form);
223  }
224 
225  $form->addCommandButton("update", $this->lng->txt("save"));
226  $form->addCommandButton("render", $this->lng->txt("cancel"));
227 
228  return $form;
229  }
This class represents an option in a radio group.
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)
if(isset($_POST['submit'])) $form
This class represents a number property in a property form.
getScheduleTypeFormElementName(int $scheduleTypeId)
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ilCronManagerGUI::render ( )
protected

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

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

70  {
71  if ($this->settings->get('last_cronjob_start_ts')) {
72  $tstamp = ilDatePresentation::formatDate(new ilDateTime($this->settings->get('last_cronjob_start_ts'), IL_CAL_UNIX));
73  } else {
74  $tstamp = $this->lng->txt('cronjob_last_start_unknown');
75  }
76  ilUtil::sendInfo($this->lng->txt('cronjob_last_start') . ": " . $tstamp);
77 
78  include_once "Services/Cron/classes/class.ilCronManagerTableGUI.php";
79  $tbl = new ilCronManagerTableGUI($this, "render");
80  $this->tpl->setContent($tbl->getHTML());
81  }
settings()
Definition: settings.php:2
$tbl
Definition: example_048.php:81
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.
Date and time handling
List all active cron jobs.
+ Here is the call graph for this function:

◆ reset()

ilCronManagerGUI::reset ( )

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

336  {
337  $this->confirm("reset");
338  }

◆ run()

ilCronManagerGUI::run ( )

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

274  {
275  $this->confirm("run");
276  }

◆ update()

ilCronManagerGUI::update ( )

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

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

232  {
233  $id = $_REQUEST["jid"];
234  if (!$id) {
235  $this->ctrl->redirect($this, "render");
236  }
237 
238  $form = $this->initEditForm($id);
239  if ($form->checkInput()) {
241  if ($job) {
242  $valid = true;
243  if ($job->hasCustomSettings() &&
244  !$job->saveCustomSettings($form)) {
245  $valid = false;
246  }
247 
248  if ($valid && $job->hasFlexibleSchedule()) {
249  $type = $form->getInput("type");
250  switch (true) {
251  case $this->hasScheduleValue($type):
252  $value = $form->getInput($this->getScheduleValueFormElementName($type));
253  break;
254 
255  default:
256  $value = null;
257  break;
258  }
259 
261  }
262  if ($valid) {
263  ilUtil::sendSuccess($this->lng->txt("cron_action_edit_success"), true);
264  $this->ctrl->redirect($this, "render");
265  }
266  }
267  }
268 
269  $form->setValuesByPost();
270  $this->edit($form);
271  }
getScheduleValueFormElementName(int $scheduleTypeId)
$type
$valid
if(!array_key_exists('StateId', $_REQUEST)) $id
static getJobInstanceById($a_job_id)
Get job instance (by job id)
if(isset($_POST['submit'])) $form
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.

◆ $lng

ilCronManagerGUI::$lng
protected

Definition at line 21 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: