ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCronManagerTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Table/classes/class.ilTable2GUI.php';
5include_once './Services/Cron/classes/class.ilCronJobResult.php';
6
14{
16 private $language;
18 private $controller;
20 private $mayWrite;
21
29 public function __construct(
30 object $a_parent_obj,
31 $a_parent_cmd,
32 \ILIAS\DI\Container $dic = null,
33 bool $mayWrite = false
34 ) {
35 if ($dic === null) {
36 global $DIC;
37 $dic = $DIC;
38 }
39
40 $this->language = $dic->language();
41 $this->controller = $dic->ctrl();
42 $this->mayWrite = $mayWrite;
43
44 $this->setId('crnmng'); // #14526 / #16391
45
46 parent::__construct($a_parent_obj, $a_parent_cmd);
47
48 if ($this->mayWrite) {
49 $this->addColumn("", "", 1);
50 }
51 $this->addColumn($this->lng->txt('cron_job_id'), 'title');
52 $this->addColumn($this->lng->txt('cron_component'), 'component');
53 $this->addColumn($this->lng->txt('cron_schedule'), 'schedule');
54 $this->addColumn($this->lng->txt('cron_status'), 'status');
55 $this->addColumn($this->lng->txt('cron_status_info'), '');
56 $this->addColumn($this->lng->txt('cron_result'), 'result');
57 $this->addColumn($this->lng->txt('cron_result_info'), '');
58 $this->addColumn($this->lng->txt('cron_last_run'), 'last_run');
59 if ($this->mayWrite) {
60 $this->addColumn($this->lng->txt('actions'), '');
61 }
62
63 $this->setTitle($this->lng->txt('cron_jobs'));
64 $this->setDefaultOrderField('title');
65
66 if ($this->mayWrite) {
67 $this->setSelectAllCheckbox('mjid');
68 $this->addMultiCommand('activate', $this->language->txt('cron_action_activate'));
69 $this->addMultiCommand('deactivate', $this->language->txt('cron_action_deactivate'));
70 $this->addMultiCommand('reset', $this->language->txt('cron_action_reset'));
71 }
72
73 $this->setRowTemplate('tpl.cron_job_row.html', 'Services/Cron');
74 $this->setFormAction($this->controller->getFormAction($a_parent_obj, $a_parent_cmd));
75 }
76
82 private function formatSchedule(ilCronJobEntity $entity, array $row) : string
83 {
84 $schedule = '';
85 switch ($entity->getEffectiveScheduleType()) {
87 $schedule = $this->language->txt('cron_schedule_daily');
88 break;
89
91 $schedule = $this->language->txt('cron_schedule_weekly');
92 break;
93
95 $schedule = $this->language->txt('cron_schedule_monthly');
96 break;
97
99 $schedule = $this->language->txt('cron_schedule_quarterly');
100 break;
101
103 $schedule = $this->language->txt('cron_schedule_yearly');
104 break;
105
107 $schedule = sprintf(
108 $this->language->txt('cron_schedule_in_minutes'),
110 );
111 break;
112
114 $schedule = sprintf(
115 $this->language->txt('cron_schedule_in_hours'),
117 );
118 break;
119
121 $schedule = sprintf(
122 $this->language->txt('cron_schedule_in_days'),
124 );
125 break;
126 }
127
128 return $schedule;
129 }
130
136 private function formatStatusInfo(ilCronJobEntity $entity) : string
137 {
138 $status_info = [];
139 if ($entity->getJobStatusTimestamp()) {
140 $status_info[] = ilDatePresentation::formatDate(
142 );
143 }
144
145 if ($entity->getJobStatusType()) {
146 $status_info[] = ilUserUtil::getNamePresentation($entity->getJobStatusUsrId());
147 } else {
148 $status_info[] = $this->language->txt('cron_changed_by_crontab');
149 }
150
151 return implode('<br />', $status_info);
152 }
153
158 private function formatResult(ilCronJobEntity $entity) : string
159 {
160 $result = '-';
161 if ($entity->getJobResultStatus()) {
162 switch ($entity->getJobResultStatus()) {
164 $result = $this->language->txt('cron_result_status_invalid_configuration');
165 break;
166
168 $result = $this->language->txt('cron_result_status_no_action');
169 break;
170
172 $result = $this->language->txt('cron_result_status_ok');
173 break;
174
176 $result = $this->language->txt('cron_result_status_crashed');
177 break;
178
180 $result = $this->language->txt('cron_result_status_reset');
181 break;
182
184 $result = $this->language->txt('cron_result_status_fail');
185 break;
186 }
187 }
188
189 return $result;
190 }
191
196 private function formatResultInfo(ilCronJobEntity $entity) : string
197 {
198 $result_info = [];
199 if ($entity->getJobResultDuration()) {
200 $result_info[] = ($entity->getJobResultDuration() / 1000) . ' sec';
201 }
202
203 // #23391 / #11866
204 $resultCode = $entity->getJobResultCode();
205 if (in_array($resultCode, ilCronJobResult::getCoreCodes())) {
206 $result_info[] = $this->language->txt('cro_job_rc_' . $resultCode);
207 } elseif ($entity->getJobResultMessage()) {
208 $result_info[] = $entity->getJobResultMessage();
209 }
210
211 if (defined('DEVMODE') && DEVMODE) {
212 $result_info[] = $resultCode;
213 }
214
215 if ($entity->getJobResultType()) {
216 $result_info[] = ilUserUtil::getNamePresentation($entity->getJobResultUsrId());
217 } else {
218 $result_info[] = $this->language->txt('cron_changed_by_crontab');
219 }
220
221 return implode('<br />', $result_info);
222 }
223
229 public function populate(ilCronJobCollection $collection) : self
230 {
231 $this->setData(array_map(function (ilCronJobEntity $entity) : array {
232 $row = [];
233
234 $row['schedule'] = $this->formatSchedule($entity, $row);
235 $row['status'] = $this->language->txt('cron_status_inactive');
236 if ($entity->getJobStatus()) {
237 $row['status'] = $this->language->txt('cron_status_active');
238 }
239 $row['status_info'] = $this->formatStatusInfo($entity);
240 $row['result'] = $this->formatResult($entity);
241 $row['result_info'] = $this->formatResultInfo($entity);
242
243 $row['last_run'] = null;
244 if ($entity->getRunningTimestamp()) {
245 $row['last_run'] = strtotime('+1year', $entity->getRunningTimestamp());
246 } elseif ($entity->getJobResultTimestamp()) {
247 $row['last_run'] = $entity->getJobResultTimestamp();
248 }
249
250 $row['job_id'] = $entity->getJobId();
251 $row['component'] = $entity->getComponent();
252 if ($entity->isPlugin()) {
253 $row['job_id'] = 'pl__' . $row['component'] . '__' . $row['job_id'];
254 $row['component'] = $this->language->txt('cmps_plugin') . '/' . $row['component'];
255 }
256
257 $row['title'] = $entity->getEffectiveTitle();
258 $row['description'] = $entity->getJob()->getDescription();
259 $row['is_manually_executable'] = $entity->getJob()->isManuallyExecutable();
260 $row['has_settings'] = $entity->getJob()->hasCustomSettings();
261 $row['job_result_status'] = $entity->getJobResultStatus();
262 $row['job_status'] = $entity->getJobStatus();
263 $row['alive_ts'] = $entity->getAliveTimestamp();
264 $row['running_ts'] = $entity->getRunningTimestamp();
265
266 if ($entity->getJob()->hasFlexibleSchedule()) {
267 $row['editable_schedule'] = true;
268 if (!$entity->getScheduleType()) {
270 $entity->getJob(),
271 $entity->getEffectiveScheduleType(),
273 );
274 }
275 } elseif ($entity->getScheduleType()) {
276 ilCronManager::updateJobSchedule($entity->getJob(), null, null);
277 }
278
279 return $row;
280 }, $collection->toArray()));
281
282 return $this;
283 }
284
288 protected function fillRow($a_set)
289 {
290 if ($this->mayWrite) {
291 $this->tpl->setVariable('VAL_JID', $a_set['job_id']);
292 }
293 $this->tpl->setVariable('VAL_ID', $a_set['title']);
294
295 if ($a_set['description']) {
296 $this->tpl->setVariable('VAL_DESC', $a_set['description']);
297 }
298
299 $this->tpl->setVariable('VAL_COMPONENT', $a_set['component']);
300 $this->tpl->setVariable('VAL_SCHEDULE', $a_set['schedule']);
301 $this->tpl->setVariable('VAL_STATUS', $a_set['status']);
302 $this->tpl->setVariable('VAL_STATUS_INFO', $a_set['status_info']);
303 $this->tpl->setVariable('VAL_RESULT', $a_set['result']);
304 $this->tpl->setVariable('VAL_RESULT_INFO', $a_set['result_info']);
305 if ($a_set['last_run'] > time()) {
306 $a_set['last_run'] = $this->language->txt('cron_running_since') . ' ' .
307 ilDatePresentation::formatDate(new ilDateTime($a_set['running_ts'], IL_CAL_UNIX));
308
309 // job has pinged
310 if ($a_set['alive_ts'] != $a_set['running_ts']) {
311 $a_set['last_run'] .= '<br />(Ping: ' .
312 ilDatePresentation::formatDate(new ilDateTime($a_set['alive_ts'], IL_CAL_UNIX)) . ')';
313 }
314 } elseif ($a_set['last_run']) {
315 $a_set['last_run'] = ilDatePresentation::formatDate(new ilDateTime($a_set['last_run'], IL_CAL_UNIX));
316 }
317 $this->tpl->setVariable('VAL_LAST_RUN', $a_set['last_run'] ? $a_set['last_run'] : '-');
318
319 $actions = [];
320 if ($this->mayWrite && !$a_set['running_ts']) {
321 if ($a_set['job_result_status'] == ilCronJobResult::STATUS_CRASHED) {
322 $actions[] = 'reset';
323 } elseif (!$a_set['job_status']) {
324 $actions[] = 'activate';
325 } else {
326 if ($a_set['is_manually_executable']) {
327 $actions[] = 'run';
328 }
329 $actions[] = 'deactivate';
330 }
331
332 if ($a_set['editable_schedule'] || $a_set['has_settings']) {
333 $actions[] = 'edit';
334 }
335
336 $this->controller->setParameter($this->getParentObject(), 'jid', $a_set['job_id']);
337 foreach ($actions as $action) {
338 $this->tpl->setCurrentBlock('action_bl');
339 $this->tpl->setVariable(
340 'URL_ACTION',
341 $this->controller->getLinkTarget($this->getParentObject(), $action)
342 );
343 $this->tpl->setVariable('TXT_ACTION', $this->language->txt('cron_action_' . $action));
344 $this->tpl->parseCurrentBlock();
345 }
346 $this->controller->setParameter($this->getParentObject(), 'jid', '');
347 }
348 }
349}
$result
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Class ilCronJobEntity.
const SCHEDULE_TYPE_IN_DAYS
const SCHEDULE_TYPE_IN_HOURS
const SCHEDULE_TYPE_IN_MINUTES
const SCHEDULE_TYPE_WEEKLY
const SCHEDULE_TYPE_YEARLY
const SCHEDULE_TYPE_DAILY
const SCHEDULE_TYPE_QUARTERLY
const SCHEDULE_TYPE_MONTHLY
List all active cron jobs.
formatResultInfo(ilCronJobEntity $entity)
formatStatusInfo(ilCronJobEntity $entity)
formatSchedule(ilCronJobEntity $entity, array $row)
fillRow($a_set)
Standard Version of Fill Row.Most likely to be overwritten by derived class.
__construct(object $a_parent_obj, $a_parent_cmd, \ILIAS\DI\Container $dic=null, bool $mayWrite=false)
ilCronManagerTableGUI constructor.
formatResult(ilCronJobEntity $entity)
populate(ilCronJobCollection $collection)
static updateJobSchedule(ilCronJob $a_job, $a_schedule_type, $a_schedule_value)
Update job schedule.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Class ilTable2GUI.
getParentObject()
Get parent object.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
setData($a_data)
set table data @access public
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
global $DIC
Definition: goto.php:24
Class ilCronJobCollection.
language()
Definition: language.php:2
Class HTTPServicesTest.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
$dic
Definition: result.php:13