ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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;
17
19 private $controller;
21 private $mayWrite;
22
31 public function __construct($a_parent_obj, $a_parent_cmd, \ILIAS\DI\Container $dic = null, bool $mayWrite = false)
32 {
33 if ($dic === null) {
34 global $DIC;
35 $dic = $DIC;
36 }
37
38 $this->language = $dic->language();
39 $this->controller = $dic->ctrl();
40 $this->mayWrite = $mayWrite;
41
42 $this->setId("crnmng"); // #14526 / #16391
43
44 parent::__construct($a_parent_obj, $a_parent_cmd);
45
46 if ($this->mayWrite) {
47 $this->addColumn("", "", 1);
48 }
49 $this->addColumn($this->lng->txt("cron_job_id"), "title");
50 $this->addColumn($this->lng->txt("cron_component"), "component");
51 $this->addColumn($this->lng->txt("cron_schedule"), "schedule");
52 $this->addColumn($this->lng->txt("cron_status"), "status");
53 $this->addColumn($this->lng->txt("cron_status_info"), "");
54 $this->addColumn($this->lng->txt("cron_result"), "result");
55 $this->addColumn($this->lng->txt("cron_result_info"), "");
56 $this->addColumn($this->lng->txt("cron_last_run"), "last_run");
57 if ($this->mayWrite) {
58 $this->addColumn($this->lng->txt("actions"), "");
59 }
60
61 $this->setTitle($this->lng->txt("cron_jobs"));
62 $this->setDefaultOrderField("title");
63
64 if ($this->mayWrite) {
65 $this->setSelectAllCheckbox("mjid");
66 $this->addMultiCommand("activate", $this->language->txt("cron_action_activate"));
67 $this->addMultiCommand("deactivate", $this->language->txt("cron_action_deactivate"));
68 $this->addMultiCommand("reset", $this->language->txt("cron_action_reset"));
69 }
70
71 $this->setRowTemplate("tpl.cron_job_row.html", "Services/Cron");
72 $this->setFormAction($this->controller->getFormAction($a_parent_obj, $a_parent_cmd));
73
74 $this->getItems();
75 }
76
77 protected function parseJobToData(array $a_item, ilCronJob $job)
78 {
79 $res = $a_item;
80
81 $res["title"] = $job->getTitle();
82 $res["description"] = $job->getDescription();
83 $res["has_settings"] = $job->hasCustomSettings();
84
85 if (!$res["title"]) {
86 $res["title"] = $a_item["job_id"];
87 }
88
89 // schedule
90 if (!$job->hasFlexibleSchedule()) {
91 // schedule type changed
92 if ($a_item["schedule_type"]) {
93 ilCronManager::updateJobSchedule($job, null, null);
94 }
95
96 $a_item["schedule_type"] = $job->getDefaultScheduleType();
97 $a_item["schedule_value"] = $job->getDefaultScheduleValue();
98 $res["editable_schedule"] = false;
99 } else {
100 // schedule type changed
101 if (!$a_item["schedule_type"]) {
102 $a_item["schedule_type"] = $job->getDefaultScheduleType();
103 $a_item["schedule_value"] = $job->getDefaultScheduleValue();
105 $job,
106 $a_item["schedule_type"],
107 $a_item["schedule_value"]
108 );
109 }
110
111 $res["editable_schedule"] = true;
112 }
113
114 switch ($a_item["schedule_type"]) {
116 $schedule = $this->language->txt("cron_schedule_daily");
117 break;
118
120 $schedule = $this->language->txt("cron_schedule_weekly");
121 break;
122
124 $schedule = $this->language->txt("cron_schedule_monthly");
125 break;
126
128 $schedule = $this->language->txt("cron_schedule_quarterly");
129 break;
130
132 $schedule = $this->language->txt("cron_schedule_yearly");
133 break;
134
136 $schedule = sprintf($this->language->txt("cron_schedule_in_minutes"), $a_item["schedule_value"]);
137 break;
138
140 $schedule = sprintf($this->language->txt("cron_schedule_in_hours"), $a_item["schedule_value"]);
141 break;
142
144 $schedule = sprintf($this->language->txt("cron_schedule_in_days"), $a_item["schedule_value"]);
145 break;
146 }
147 $res["schedule"] = $schedule;
148
149 // status
150 if ($a_item["job_status"]) {
151 $res["status"] = $this->language->txt("cron_status_active");
152 } else {
153 $res["status"] = $this->language->txt("cron_status_inactive");
154 }
155
156 $status_info = array();
157 if ($a_item["job_status_ts"]) {
158 $status_info[] = ilDatePresentation::formatDate(new ilDateTime($a_item["job_status_ts"], IL_CAL_UNIX));
159 }
160 if (!$a_item["job_status_type"]) {
161 $status_info[] = $this->language->txt("cron_changed_by_crontab");
162 } else {
163 $status_info[] = ilUserUtil::getNamePresentation($a_item["job_status_user_id"]);
164 }
165 $res["status_info"] = implode("<br />", $status_info);
166
167 // result
168 $result = "-";
169 if ($a_item["job_result_status"]) {
170 switch ($a_item["job_result_status"]) {
172 $result = $this->language->txt("cron_result_status_invalid_configuration");
173 break;
174
176 $result = $this->language->txt("cron_result_status_no_action");
177 break;
178
180 $result = $this->language->txt("cron_result_status_ok");
181 break;
182
184 $result = $this->language->txt("cron_result_status_crashed");
185 break;
186
188 $result = $this->language->txt("cron_result_status_reset");
189 break;
190
192 $result = $this->language->txt("cron_result_status_fail");
193 break;
194 }
195 }
196 $res["result"] = $result;
197
198 $result_info = array();
199 if ($a_item["job_result_dur"]) {
200 $result_info[] = ($a_item["job_result_dur"] / 1000) . " sec";
201 }
202
203 // #23391 / #11866
204 $resultCode = $a_item['job_result_code'];
205 if (in_array($resultCode, ilCronJobResult::getCoreCodes())) {
206 $result_info[] = $this->language->txt('cro_job_rc_' . $resultCode);
207 } else {
208 if ($a_item['job_result_message']) {
209 $result_info[] = $a_item['job_result_message'];
210 }
211 }
212
213 if (defined('DEVMODE') && DEVMODE) {
214 $result_info[] = $resultCode;
215 }
216
217 if (!$a_item["job_result_type"]) {
218 $result_info[] = $this->language->txt("cron_changed_by_crontab");
219 } else {
220 $result_info[] = ilUserUtil::getNamePresentation($a_item["job_result_user_id"]);
221 }
222 $res["result_info"] = implode("<br />", $result_info);
223
224 if ($a_item["running_ts"]) {
225 $res["last_run"] = strtotime("+1year", $a_item["running_ts"]);
226 } elseif ($a_item["job_result_ts"]) {
227 $res["last_run"] = $a_item["job_result_ts"];
228 } else {
229 $res["last_run"] = null;
230 }
231
232 $res['is_manually_executable'] = $job->isManuallyExecutable();
233
234 return $res;
235 }
236
237 protected function getItems()
238 {
239 include_once "Services/User/classes/class.ilUserUtil.php";
240 include_once "Services/Cron/classes/class.ilCronJobResult.php";
241
242 // systems
244 foreach ($data as $idx => $item) {
246 $item["job_id"],
247 $item["component"],
248 $item["class"],
249 $item["path"]
250 );
251 if ($job) {
252 $data[$idx] = $this->parseJobToData($item, $job);
253 }
254 }
255
256 // plugins
257 $this->language->loadLanguageModule("cmps");
258 foreach (ilCronManager::getPluginJobs() as $item) {
259 $job = $item[0];
260 $item = $item[1];
261
262 $item["job_id"] = "pl__" . $item["component"] . "__" . $job->getId();
263 $item["component"] = $this->language->txt("cmps_plugin") . "/" . $item["component"];
264
265 $data[] = $this->parseJobToData($item, $job);
266 }
267
268 $this->setData($data);
269 }
270
271 protected function fillRow($a_set)
272 {
273 if ($this->mayWrite) {
274 $this->tpl->setVariable("VAL_JID", $a_set["job_id"]);
275 }
276 $this->tpl->setVariable("VAL_ID", $a_set["title"]);
277
278 if ($a_set["description"]) {
279 $this->tpl->setVariable("VAL_DESC", $a_set["description"]);
280 }
281
282 $this->tpl->setVariable("VAL_COMPONENT", $a_set["component"]);
283 $this->tpl->setVariable("VAL_SCHEDULE", $a_set["schedule"]);
284 $this->tpl->setVariable("VAL_STATUS", $a_set["status"]);
285 $this->tpl->setVariable("VAL_STATUS_INFO", $a_set["status_info"]);
286 $this->tpl->setVariable("VAL_RESULT", $a_set["result"]);
287 $this->tpl->setVariable("VAL_RESULT_INFO", $a_set["result_info"]);
288 if ($a_set["last_run"] > time()) {
289 $a_set["last_run"] = $this->language->txt("cron_running_since") . " " .
290 ilDatePresentation::formatDate(new ilDateTime($a_set["running_ts"], IL_CAL_UNIX));
291
292 // job has pinged
293 if ($a_set["alive_ts"] != $a_set["running_ts"]) {
294 $a_set["last_run"] .= "<br />(Ping: " .
295 ilDatePresentation::formatDate(new ilDateTime($a_set["alive_ts"], IL_CAL_UNIX)) . ")";
296 }
297 } elseif ($a_set["last_run"]) {
298 $a_set["last_run"] = ilDatePresentation::formatDate(new ilDateTime($a_set["last_run"], IL_CAL_UNIX));
299 }
300 $this->tpl->setVariable("VAL_LAST_RUN", $a_set["last_run"] ? $a_set["last_run"] : "-");
301
302
303 // actions
304
305 $actions = array();
306
307 if ($this->mayWrite && !$a_set["running_ts"]) {
308 // reset
309 if ($a_set["job_result_status"] == ilCronJobResult::STATUS_CRASHED) {
310 $actions[] = "reset";
311 }
312 // activate
313 elseif (!$a_set["job_status"]) {
314 $actions[] = "activate";
315 }
316 // deactivate
317 else {
318 if ($a_set['is_manually_executable']) {
319 $actions[] = 'run';
320 }
321 $actions[] = "deactivate";
322 }
323 // edit (schedule)
324 if ($a_set["editable_schedule"] || $a_set["has_settings"]) {
325 $actions[] = "edit";
326 }
327
328 $this->controller->setParameter($this->getParentObject(), "jid", $a_set["job_id"]);
329
330 foreach ($actions as $action) {
331 $this->tpl->setCurrentBlock("action_bl");
332 $this->tpl->setVariable(
333 "URL_ACTION",
334 $this->controller->getLinkTarget($this->getParentObject(), $action)
335 );
336 $this->tpl->setVariable("TXT_ACTION", $this->language->txt("cron_action_" . $action));
337 $this->tpl->parseCurrentBlock();
338 }
339
340 $this->controller->setParameter($this->getParentObject(), "jid", "");
341 }
342 }
343}
$result
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Cron job application base class.
const SCHEDULE_TYPE_IN_DAYS
getDefaultScheduleType()
Get schedule type.
getDescription()
Get description.
const SCHEDULE_TYPE_IN_HOURS
getDefaultScheduleValue()
Get schedule value.
hasCustomSettings()
Has cron job any custom setting which can be edited?
const SCHEDULE_TYPE_IN_MINUTES
isManuallyExecutable()
Defines whether or not a cron job can be started manually.
const SCHEDULE_TYPE_WEEKLY
const SCHEDULE_TYPE_YEARLY
const SCHEDULE_TYPE_DAILY
hasFlexibleSchedule()
Can the schedule be configured?
const SCHEDULE_TYPE_QUARTERLY
const SCHEDULE_TYPE_MONTHLY
getTitle()
Get title.
List all active cron jobs.
__construct($a_parent_obj, $a_parent_cmd, \ILIAS\DI\Container $dic=null, bool $mayWrite=false)
Constructor.
parseJobToData(array $a_item, ilCronJob $job)
fillRow($a_set)
Standard Version of Fill Row.
static getCronJobData($a_id=null, $a_include_inactive=true)
Get cron job configuration/execution data.
static getJobInstance($a_id, $a_component, $a_class, $a_path=null)
Get job instance (by job data)
static updateJobSchedule(ilCronJob $a_job, $a_schedule_type, $a_schedule_value)
Update job schedule.
static getPluginJobs($a_only_active=false)
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:
language()
Definition: language.php:2
Class HTTPServicesTest.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
$dic
Definition: result.php:13
foreach($_POST as $key=> $value) $res
$DIC
Definition: xapitoken.php:46