ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
21 public function __construct($a_parent_obj, $a_parent_cmd)
22 {
23 global $ilCtrl, $lng;
24
25 $this->setId("crnmng"); // #14526 / #16391
26
27 parent::__construct($a_parent_obj, $a_parent_cmd);
28
29 $this->addColumn("", "", 1);
30 $this->addColumn($this->lng->txt("cron_job_id"), "title");
31 $this->addColumn($this->lng->txt("cron_component"), "component");
32 $this->addColumn($this->lng->txt("cron_schedule"), "schedule");
33 $this->addColumn($this->lng->txt("cron_status"), "status");
34 $this->addColumn($this->lng->txt("cron_status_info"), "");
35 $this->addColumn($this->lng->txt("cron_result"), "result");
36 $this->addColumn($this->lng->txt("cron_result_info"), "");
37 $this->addColumn($this->lng->txt("cron_last_run"), "last_run");
38 $this->addColumn($this->lng->txt("actions"), "");
39
40 $this->setTitle($this->lng->txt("cron_jobs"));
41 $this->setDefaultOrderField("title");
42
43 $this->setSelectAllCheckbox("mjid");
44 $this->addMultiCommand("activate", $lng->txt("cron_action_activate"));
45 $this->addMultiCommand("deactivate", $lng->txt("cron_action_deactivate"));
46 $this->addMultiCommand("reset", $lng->txt("cron_action_reset"));
47
48 $this->setRowTemplate("tpl.cron_job_row.html", "Services/Cron");
49 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
50
51 $this->getItems();
52 }
53
54 protected function parseJobToData(array $a_item, ilCronJob $job)
55 {
56 global $lng;
57
58 $res = $a_item;
59
60 $res["title"] = $job->getTitle();
61 $res["description"] = $job->getDescription();
62 $res["has_settings"] = $job->hasCustomSettings();
63
64 if(!$res["title"])
65 {
66 $res["title"] = $a_item["job_id"];
67 }
68
69 // schedule
70 if(!$job->hasFlexibleSchedule())
71 {
72 // schedule type changed
73 if($a_item["schedule_type"])
74 {
75 ilCronManager::updateJobSchedule($job, null, null);
76 }
77
78 $a_item["schedule_type"] = $job->getDefaultScheduleType();
79 $a_item["schedule_value"] = $job->getDefaultScheduleValue();
80 $res["editable_schedule"] = false;
81 }
82 else
83 {
84 // schedule type changed
85 if(!$a_item["schedule_type"])
86 {
87 $a_item["schedule_type"] = $job->getDefaultScheduleType();
88 $a_item["schedule_value"] = $job->getDefaultScheduleValue();
89 ilCronManager::updateJobSchedule($job, $a_item["schedule_type"],
90 $a_item["schedule_value"]);
91 }
92
93 $res["editable_schedule"] = true;
94 }
95
96 switch($a_item["schedule_type"])
97 {
99 $schedule = $lng->txt("cron_schedule_daily");
100 break;
101
103 $schedule = $lng->txt("cron_schedule_weekly");
104 break;
105
107 $schedule = $lng->txt("cron_schedule_monthly");
108 break;
109
111 $schedule = $lng->txt("cron_schedule_quarterly");
112 break;
113
115 $schedule = $lng->txt("cron_schedule_yearly");
116 break;
117
119 $schedule = sprintf($lng->txt("cron_schedule_in_minutes"), $a_item["schedule_value"]);
120 break;
121
123 $schedule = sprintf($lng->txt("cron_schedule_in_hours"), $a_item["schedule_value"]);
124 break;
125
127 $schedule = sprintf($lng->txt("cron_schedule_in_days"), $a_item["schedule_value"]);
128 break;
129 }
130 $res["schedule"] = $schedule;
131
132 // status
133 if($a_item["job_status"])
134 {
135 $res["status"] = $lng->txt("cron_status_active");
136 }
137 else
138 {
139 $res["status"] = $lng->txt("cron_status_inactive");
140 }
141
142 $status_info = array();
143 if($a_item["job_status_ts"])
144 {
145 $status_info[] = ilDatePresentation::formatDate(new ilDateTime($a_item["job_status_ts"], IL_CAL_UNIX));
146 }
147 if(!$a_item["job_status_type"])
148 {
149 $status_info[] = $lng->txt("cron_changed_by_crontab");
150 }
151 else
152 {
153 $status_info[] = ilUserUtil::getNamePresentation($a_item["job_status_user_id"]);
154 }
155 $res["status_info"] = implode("<br />", $status_info);
156
157 // result
158 $result = "-";
159 if($a_item["job_result_status"])
160 {
161 switch($a_item["job_result_status"])
162 {
164 $result = $lng->txt("cron_result_status_invalid_configuration");
165 break;
166
168 $result = $lng->txt("cron_result_status_no_action");
169 break;
170
172 $result = $lng->txt("cron_result_status_ok");
173 break;
174
176 $result = $lng->txt("cron_result_status_crashed");
177 break;
178
180 $result = $lng->txt("cron_result_status_reset");
181 break;
182
184 $result = $lng->txt("cron_result_status_fail");
185 break;
186 }
187 }
188 $res["result"] = $result;
189
190 $result_info = array();
191 if($a_item["job_result_dur"])
192 {
193 $result_info[] = ($a_item["job_result_dur"]/1000)." sec";
194 }
195 if($a_item["job_result_message"])
196 {
197 $result_info[] = $a_item["job_result_message"];
198 }
199 if(DEVMODE && $a_item["job_result_code"]) // #11866
200 {
201 $resultCode = $a_item["job_result_code"];
202 if(in_array($resultCode, ilCronJobResult::getCoreCodes()))
203 {
204 $result_info[] = $lng->txt('cro_job_rc_' . $resultCode);
205 }
206 else
207 {
208 $result_info[] = $resultCode;
209 }
210 }
211 if(!$a_item["job_result_type"])
212 {
213 $result_info[] = $lng->txt("cron_changed_by_crontab");
214 }
215 else
216 {
217 $result_info[] = ilUserUtil::getNamePresentation($a_item["job_result_user_id"]);
218 }
219 $res["result_info"] = implode("<br />", $result_info);
220
221 if($a_item["running_ts"])
222 {
223 $res["last_run"] = strtotime("+1year", $a_item["running_ts"]);
224 }
225 else if($a_item["job_result_ts"])
226 {
227 $res["last_run"] = $a_item["job_result_ts"];
228 }
229 else
230 {
231 $res["last_run"] = null;
232 }
233
234 $res['is_manually_executable'] = $job->isManuallyExecutable();
235
236 return $res;
237 }
238
239 protected function getItems()
240 {
241 global $ilPluginAdmin, $lng;
242
243 include_once "Services/User/classes/class.ilUserUtil.php";
244 include_once "Services/Cron/classes/class.ilCronJobResult.php";
245
246 // systems
248 foreach($data as $idx => $item)
249 {
250 $job = ilCronManager::getJobInstance($item["job_id"],
251 $item["component"], $item["class"], $item["path"]);
252 if($job)
253 {
254 $data[$idx] = $this->parseJobToData($item, $job);
255 }
256 }
257
258 // plugins
259 $lng->loadLanguageModule("cmps");
260 foreach(ilCronManager::getPluginJobs() as $item)
261 {
262 $job = $item[0];
263 $item = $item[1];
264
265 $item["job_id"] = "pl__".$item["component"]."__".$job->getId();
266 $item["component"] = $lng->txt("cmps_plugin")."/".$item["component"];
267
268 $data[] = $this->parseJobToData($item, $job);
269 }
270
271 $this->setData($data);
272 }
273
274 protected function fillRow($a_set)
275 {
276 global $ilCtrl, $lng;
277
278 $this->tpl->setVariable("VAL_ID", $a_set["title"]);
279 $this->tpl->setVariable("VAL_JID", $a_set["job_id"]);
280
281 if($a_set["description"])
282 {
283 $this->tpl->setVariable("VAL_DESC", $a_set["description"]);
284 }
285
286 $this->tpl->setVariable("VAL_COMPONENT", $a_set["component"]);
287 $this->tpl->setVariable("VAL_SCHEDULE", $a_set["schedule"]);
288 $this->tpl->setVariable("VAL_STATUS", $a_set["status"]);
289 $this->tpl->setVariable("VAL_STATUS_INFO", $a_set["status_info"]);
290 $this->tpl->setVariable("VAL_RESULT", $a_set["result"]);
291 $this->tpl->setVariable("VAL_RESULT_INFO", $a_set["result_info"]);
292 if($a_set["last_run"] > time())
293 {
294 $a_set["last_run"] = $lng->txt("cron_running_since")." ".
295 ilDatePresentation::formatDate(new ilDateTime($a_set["running_ts"], IL_CAL_UNIX));
296
297 // job has pinged
298 if($a_set["alive_ts"] != $a_set["running_ts"])
299 {
300 $a_set["last_run"] .= "<br />(Ping: ".
301 ilDatePresentation::formatDate(new ilDateTime($a_set["alive_ts"], IL_CAL_UNIX)).")";
302 }
303 }
304 else if($a_set["last_run"])
305 {
306 $a_set["last_run"] = ilDatePresentation::formatDate(new ilDateTime($a_set["last_run"], IL_CAL_UNIX));
307 }
308 $this->tpl->setVariable("VAL_LAST_RUN", $a_set["last_run"] ? $a_set["last_run"] : "-");
309
310
311 // actions
312
313 $actions = array();
314
315 if(!$a_set["running_ts"])
316 {
317 // reset
318 if($a_set["job_result_status"] == ilCronJobResult::STATUS_CRASHED)
319 {
320 $actions[] = "reset";
321 }
322 // activate
323 else if(!$a_set["job_status"])
324 {
325 $actions[] = "activate";
326 }
327 // deactivate
328 else
329 {
330 if($a_set['is_manually_executable'])
331 {
332 $actions[] = 'run';
333 }
334 $actions[] = "deactivate";
335 }
336 // edit (schedule)
337 if($a_set["editable_schedule"] || $a_set["has_settings"])
338 {
339 $actions[] = "edit";
340 }
341
342 $ilCtrl->setParameter($this->getParentObject(), "jid", $a_set["job_id"]);
343
344 foreach($actions as $action)
345 {
346 $this->tpl->setCurrentBlock("action_bl");
347 $this->tpl->setVariable("URL_ACTION",
348 $ilCtrl->getLinkTarget($this->getParentObject(), $action));
349 $this->tpl->setVariable("TXT_ACTION", $lng->txt("cron_action_".$action));
350 $this->tpl->parseCurrentBlock();
351 }
352
353 $ilCtrl->setParameter($this->getParentObject(), "jid", "");
354 }
355 }
356}
357
358?>
sprintf('%.4f', $callTime)
$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)
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)
Format a date @access public.
@classDescription Date and time handling
Class ilTable2GUI.
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.
getParentObject()
Get parent object.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
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.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
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)
Default behaviour is:
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17