ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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;
20
27 public function __construct($a_parent_obj, $a_parent_cmd, \ILIAS\DI\Container $dic = null)
28 {
29 if ($dic === null) {
30 global $DIC;
31 $dic = $DIC;
32 }
33
34 $this->language = $dic->language();
35 $this->controller = $dic->ctrl();
36
37 $this->setId("crnmng"); // #14526 / #16391
38
39 parent::__construct($a_parent_obj, $a_parent_cmd);
40
41 $this->addColumn("", "", 1);
42 $this->addColumn($this->lng->txt("cron_job_id"), "title");
43 $this->addColumn($this->lng->txt("cron_component"), "component");
44 $this->addColumn($this->lng->txt("cron_schedule"), "schedule");
45 $this->addColumn($this->lng->txt("cron_status"), "status");
46 $this->addColumn($this->lng->txt("cron_status_info"), "");
47 $this->addColumn($this->lng->txt("cron_result"), "result");
48 $this->addColumn($this->lng->txt("cron_result_info"), "");
49 $this->addColumn($this->lng->txt("cron_last_run"), "last_run");
50 $this->addColumn($this->lng->txt("actions"), "");
51
52 $this->setTitle($this->lng->txt("cron_jobs"));
53 $this->setDefaultOrderField("title");
54
55 $this->setSelectAllCheckbox("mjid");
56 $this->addMultiCommand("activate", $this->language->txt("cron_action_activate"));
57 $this->addMultiCommand("deactivate", $this->language->txt("cron_action_deactivate"));
58 $this->addMultiCommand("reset", $this->language->txt("cron_action_reset"));
59
60 $this->setRowTemplate("tpl.cron_job_row.html", "Services/Cron");
61 $this->setFormAction($this->controller->getFormAction($a_parent_obj, $a_parent_cmd));
62
63 $this->getItems();
64 }
65
66 protected function parseJobToData(array $a_item, ilCronJob $job)
67 {
68 $res = $a_item;
69
70 $res["title"] = $job->getTitle();
71 $res["description"] = $job->getDescription();
72 $res["has_settings"] = $job->hasCustomSettings();
73
74 if (!$res["title"]) {
75 $res["title"] = $a_item["job_id"];
76 }
77
78 // schedule
79 if (!$job->hasFlexibleSchedule()) {
80 // schedule type changed
81 if ($a_item["schedule_type"]) {
82 ilCronManager::updateJobSchedule($job, null, null);
83 }
84
85 $a_item["schedule_type"] = $job->getDefaultScheduleType();
86 $a_item["schedule_value"] = $job->getDefaultScheduleValue();
87 $res["editable_schedule"] = false;
88 } else {
89 // schedule type changed
90 if (!$a_item["schedule_type"]) {
91 $a_item["schedule_type"] = $job->getDefaultScheduleType();
92 $a_item["schedule_value"] = $job->getDefaultScheduleValue();
94 $job,
95 $a_item["schedule_type"],
96 $a_item["schedule_value"]
97 );
98 }
99
100 $res["editable_schedule"] = true;
101 }
102
103 switch ($a_item["schedule_type"]) {
105 $schedule = $this->language->txt("cron_schedule_daily");
106 break;
107
109 $schedule = $this->language->txt("cron_schedule_weekly");
110 break;
111
113 $schedule = $this->language->txt("cron_schedule_monthly");
114 break;
115
117 $schedule = $this->language->txt("cron_schedule_quarterly");
118 break;
119
121 $schedule = $this->language->txt("cron_schedule_yearly");
122 break;
123
125 $schedule = sprintf($this->language->txt("cron_schedule_in_minutes"), $a_item["schedule_value"]);
126 break;
127
129 $schedule = sprintf($this->language->txt("cron_schedule_in_hours"), $a_item["schedule_value"]);
130 break;
131
133 $schedule = sprintf($this->language->txt("cron_schedule_in_days"), $a_item["schedule_value"]);
134 break;
135 }
136 $res["schedule"] = $schedule;
137
138 // status
139 if ($a_item["job_status"]) {
140 $res["status"] = $this->language->txt("cron_status_active");
141 } else {
142 $res["status"] = $this->language->txt("cron_status_inactive");
143 }
144
145 $status_info = array();
146 if ($a_item["job_status_ts"]) {
147 $status_info[] = ilDatePresentation::formatDate(new ilDateTime($a_item["job_status_ts"], IL_CAL_UNIX));
148 }
149 if (!$a_item["job_status_type"]) {
150 $status_info[] = $this->language->txt("cron_changed_by_crontab");
151 } else {
152 $status_info[] = ilUserUtil::getNamePresentation($a_item["job_status_user_id"]);
153 }
154 $res["status_info"] = implode("<br />", $status_info);
155
156 // result
157 $result = "-";
158 if ($a_item["job_result_status"]) {
159 switch ($a_item["job_result_status"]) {
161 $result = $this->language->txt("cron_result_status_invalid_configuration");
162 break;
163
165 $result = $this->language->txt("cron_result_status_no_action");
166 break;
167
169 $result = $this->language->txt("cron_result_status_ok");
170 break;
171
173 $result = $this->language->txt("cron_result_status_crashed");
174 break;
175
177 $result = $this->language->txt("cron_result_status_reset");
178 break;
179
181 $result = $this->language->txt("cron_result_status_fail");
182 break;
183 }
184 }
185 $res["result"] = $result;
186
187 $result_info = array();
188 if ($a_item["job_result_dur"]) {
189 $result_info[] = ($a_item["job_result_dur"] / 1000) . " sec";
190 }
191
192 // #23391 / #11866
193 $resultCode = $a_item['job_result_code'];
194 if (in_array($resultCode, ilCronJobResult::getCoreCodes())) {
195 $result_info[] = $this->language->txt('cro_job_rc_' . $resultCode);
196 } else {
197 if ($a_item['job_result_message']) {
198 $result_info[] = $a_item['job_result_message'];
199 }
200 }
201
202 if (defined('DEVMODE') && DEVMODE) {
203 $result_info[] = $resultCode;
204 }
205
206 if (!$a_item["job_result_type"]) {
207 $result_info[] = $this->language->txt("cron_changed_by_crontab");
208 } else {
209 $result_info[] = ilUserUtil::getNamePresentation($a_item["job_result_user_id"]);
210 }
211 $res["result_info"] = implode("<br />", $result_info);
212
213 if ($a_item["running_ts"]) {
214 $res["last_run"] = strtotime("+1year", $a_item["running_ts"]);
215 } elseif ($a_item["job_result_ts"]) {
216 $res["last_run"] = $a_item["job_result_ts"];
217 } else {
218 $res["last_run"] = null;
219 }
220
221 $res['is_manually_executable'] = $job->isManuallyExecutable();
222
223 return $res;
224 }
225
226 protected function getItems()
227 {
228 include_once "Services/User/classes/class.ilUserUtil.php";
229 include_once "Services/Cron/classes/class.ilCronJobResult.php";
230
231 // systems
233 foreach ($data as $idx => $item) {
235 $item["job_id"],
236 $item["component"],
237 $item["class"],
238 $item["path"]
239 );
240 if ($job) {
241 $data[$idx] = $this->parseJobToData($item, $job);
242 }
243 }
244
245 // plugins
246 $this->language->loadLanguageModule("cmps");
247 foreach (ilCronManager::getPluginJobs() as $item) {
248 $job = $item[0];
249 $item = $item[1];
250
251 $item["job_id"] = "pl__" . $item["component"] . "__" . $job->getId();
252 $item["component"] = $this->language->txt("cmps_plugin") . "/" . $item["component"];
253
254 $data[] = $this->parseJobToData($item, $job);
255 }
256
257 $this->setData($data);
258 }
259
260 protected function fillRow($a_set)
261 {
262 $this->tpl->setVariable("VAL_ID", $a_set["title"]);
263 $this->tpl->setVariable("VAL_JID", $a_set["job_id"]);
264
265 if ($a_set["description"]) {
266 $this->tpl->setVariable("VAL_DESC", $a_set["description"]);
267 }
268
269 $this->tpl->setVariable("VAL_COMPONENT", $a_set["component"]);
270 $this->tpl->setVariable("VAL_SCHEDULE", $a_set["schedule"]);
271 $this->tpl->setVariable("VAL_STATUS", $a_set["status"]);
272 $this->tpl->setVariable("VAL_STATUS_INFO", $a_set["status_info"]);
273 $this->tpl->setVariable("VAL_RESULT", $a_set["result"]);
274 $this->tpl->setVariable("VAL_RESULT_INFO", $a_set["result_info"]);
275 if ($a_set["last_run"] > time()) {
276 $a_set["last_run"] = $this->language->txt("cron_running_since") . " " .
277 ilDatePresentation::formatDate(new ilDateTime($a_set["running_ts"], IL_CAL_UNIX));
278
279 // job has pinged
280 if ($a_set["alive_ts"] != $a_set["running_ts"]) {
281 $a_set["last_run"] .= "<br />(Ping: " .
282 ilDatePresentation::formatDate(new ilDateTime($a_set["alive_ts"], IL_CAL_UNIX)) . ")";
283 }
284 } elseif ($a_set["last_run"]) {
285 $a_set["last_run"] = ilDatePresentation::formatDate(new ilDateTime($a_set["last_run"], IL_CAL_UNIX));
286 }
287 $this->tpl->setVariable("VAL_LAST_RUN", $a_set["last_run"] ? $a_set["last_run"] : "-");
288
289
290 // actions
291
292 $actions = array();
293
294 if (!$a_set["running_ts"]) {
295 // reset
296 if ($a_set["job_result_status"] == ilCronJobResult::STATUS_CRASHED) {
297 $actions[] = "reset";
298 }
299 // activate
300 elseif (!$a_set["job_status"]) {
301 $actions[] = "activate";
302 }
303 // deactivate
304 else {
305 if ($a_set['is_manually_executable']) {
306 $actions[] = 'run';
307 }
308 $actions[] = "deactivate";
309 }
310 // edit (schedule)
311 if ($a_set["editable_schedule"] || $a_set["has_settings"]) {
312 $actions[] = "edit";
313 }
314
315 $this->controller->setParameter($this->getParentObject(), "jid", $a_set["job_id"]);
316
317 foreach ($actions as $action) {
318 $this->tpl->setCurrentBlock("action_bl");
319 $this->tpl->setVariable(
320 "URL_ACTION",
321 $this->controller->getLinkTarget($this->getParentObject(), $action)
322 );
323 $this->tpl->setVariable("TXT_ACTION", $this->language->txt("cron_action_" . $action));
324 $this->tpl->parseCurrentBlock();
325 }
326
327 $this->controller->setParameter($this->getParentObject(), "jid", "");
328 }
329 }
330}
$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.
parseJobToData(array $a_item, ilCronJob $job)
__construct($a_parent_obj, $a_parent_cmd, \ILIAS\DI\Container $dic=null)
Constructor.
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:
$action
Class HTTPServicesTest.
Class BaseForm.
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res