ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $res["title"] = $a_item["job_id"];
66 }
67
68 // schedule
69 if (!$job->hasFlexibleSchedule()) {
70 // schedule type changed
71 if ($a_item["schedule_type"]) {
72 ilCronManager::updateJobSchedule($job, null, null);
73 }
74
75 $a_item["schedule_type"] = $job->getDefaultScheduleType();
76 $a_item["schedule_value"] = $job->getDefaultScheduleValue();
77 $res["editable_schedule"] = false;
78 } else {
79 // schedule type changed
80 if (!$a_item["schedule_type"]) {
81 $a_item["schedule_type"] = $job->getDefaultScheduleType();
82 $a_item["schedule_value"] = $job->getDefaultScheduleValue();
84 $job,
85 $a_item["schedule_type"],
86 $a_item["schedule_value"]
87 );
88 }
89
90 $res["editable_schedule"] = true;
91 }
92
93 switch ($a_item["schedule_type"]) {
95 $schedule = $lng->txt("cron_schedule_daily");
96 break;
97
99 $schedule = $lng->txt("cron_schedule_weekly");
100 break;
101
103 $schedule = $lng->txt("cron_schedule_monthly");
104 break;
105
107 $schedule = $lng->txt("cron_schedule_quarterly");
108 break;
109
111 $schedule = $lng->txt("cron_schedule_yearly");
112 break;
113
115 $schedule = sprintf($lng->txt("cron_schedule_in_minutes"), $a_item["schedule_value"]);
116 break;
117
119 $schedule = sprintf($lng->txt("cron_schedule_in_hours"), $a_item["schedule_value"]);
120 break;
121
123 $schedule = sprintf($lng->txt("cron_schedule_in_days"), $a_item["schedule_value"]);
124 break;
125 }
126 $res["schedule"] = $schedule;
127
128 // status
129 if ($a_item["job_status"]) {
130 $res["status"] = $lng->txt("cron_status_active");
131 } else {
132 $res["status"] = $lng->txt("cron_status_inactive");
133 }
134
135 $status_info = array();
136 if ($a_item["job_status_ts"]) {
137 $status_info[] = ilDatePresentation::formatDate(new ilDateTime($a_item["job_status_ts"], IL_CAL_UNIX));
138 }
139 if (!$a_item["job_status_type"]) {
140 $status_info[] = $lng->txt("cron_changed_by_crontab");
141 } else {
142 $status_info[] = ilUserUtil::getNamePresentation($a_item["job_status_user_id"]);
143 }
144 $res["status_info"] = implode("<br />", $status_info);
145
146 // result
147 $result = "-";
148 if ($a_item["job_result_status"]) {
149 switch ($a_item["job_result_status"]) {
151 $result = $lng->txt("cron_result_status_invalid_configuration");
152 break;
153
155 $result = $lng->txt("cron_result_status_no_action");
156 break;
157
159 $result = $lng->txt("cron_result_status_ok");
160 break;
161
163 $result = $lng->txt("cron_result_status_crashed");
164 break;
165
167 $result = $lng->txt("cron_result_status_reset");
168 break;
169
171 $result = $lng->txt("cron_result_status_fail");
172 break;
173 }
174 }
175 $res["result"] = $result;
176
177 $result_info = array();
178 if ($a_item["job_result_dur"]) {
179 $result_info[] = ($a_item["job_result_dur"]/1000) . " sec";
180 }
181
182 // #23391 / #11866
183 $resultCode = $a_item['job_result_code'];
184 if (in_array($resultCode, ilCronJobResult::getCoreCodes())) {
185 $result_info[] = $lng->txt('cro_job_rc_' . $resultCode);
186 } else {
187 if ($a_item['job_result_message']) {
188 $result_info[] = $a_item['job_result_message'];
189 }
190 }
191
192 if (defined('DEVMODE') && DEVMODE) {
193 $result_info[] = $resultCode;
194 }
195
196 if (!$a_item["job_result_type"]) {
197 $result_info[] = $lng->txt("cron_changed_by_crontab");
198 } else {
199 $result_info[] = ilUserUtil::getNamePresentation($a_item["job_result_user_id"]);
200 }
201 $res["result_info"] = implode("<br />", $result_info);
202
203 if ($a_item["running_ts"]) {
204 $res["last_run"] = strtotime("+1year", $a_item["running_ts"]);
205 } elseif ($a_item["job_result_ts"]) {
206 $res["last_run"] = $a_item["job_result_ts"];
207 } else {
208 $res["last_run"] = null;
209 }
210
211 $res['is_manually_executable'] = $job->isManuallyExecutable();
212
213 return $res;
214 }
215
216 protected function getItems()
217 {
218 global $ilPluginAdmin, $lng;
219
220 include_once "Services/User/classes/class.ilUserUtil.php";
221 include_once "Services/Cron/classes/class.ilCronJobResult.php";
222
223 // systems
225 foreach ($data as $idx => $item) {
227 $item["job_id"],
228 $item["component"],
229 $item["class"],
230 $item["path"]
231 );
232 if ($job) {
233 $data[$idx] = $this->parseJobToData($item, $job);
234 }
235 }
236
237 // plugins
238 $lng->loadLanguageModule("cmps");
239 foreach (ilCronManager::getPluginJobs() as $item) {
240 $job = $item[0];
241 $item = $item[1];
242
243 $item["job_id"] = "pl__" . $item["component"] . "__" . $job->getId();
244 $item["component"] = $lng->txt("cmps_plugin") . "/" . $item["component"];
245
246 $data[] = $this->parseJobToData($item, $job);
247 }
248
249 $this->setData($data);
250 }
251
252 protected function fillRow($a_set)
253 {
254 global $ilCtrl, $lng;
255
256 $this->tpl->setVariable("VAL_ID", $a_set["title"]);
257 $this->tpl->setVariable("VAL_JID", $a_set["job_id"]);
258
259 if ($a_set["description"]) {
260 $this->tpl->setVariable("VAL_DESC", $a_set["description"]);
261 }
262
263 $this->tpl->setVariable("VAL_COMPONENT", $a_set["component"]);
264 $this->tpl->setVariable("VAL_SCHEDULE", $a_set["schedule"]);
265 $this->tpl->setVariable("VAL_STATUS", $a_set["status"]);
266 $this->tpl->setVariable("VAL_STATUS_INFO", $a_set["status_info"]);
267 $this->tpl->setVariable("VAL_RESULT", $a_set["result"]);
268 $this->tpl->setVariable("VAL_RESULT_INFO", $a_set["result_info"]);
269 if ($a_set["last_run"] > time()) {
270 $a_set["last_run"] = $lng->txt("cron_running_since") . " " .
271 ilDatePresentation::formatDate(new ilDateTime($a_set["running_ts"], IL_CAL_UNIX));
272
273 // job has pinged
274 if ($a_set["alive_ts"] != $a_set["running_ts"]) {
275 $a_set["last_run"] .= "<br />(Ping: " .
276 ilDatePresentation::formatDate(new ilDateTime($a_set["alive_ts"], IL_CAL_UNIX)) . ")";
277 }
278 } elseif ($a_set["last_run"]) {
279 $a_set["last_run"] = ilDatePresentation::formatDate(new ilDateTime($a_set["last_run"], IL_CAL_UNIX));
280 }
281 $this->tpl->setVariable("VAL_LAST_RUN", $a_set["last_run"] ? $a_set["last_run"] : "-");
282
283
284 // actions
285
286 $actions = array();
287
288 if (!$a_set["running_ts"]) {
289 // reset
290 if ($a_set["job_result_status"] == ilCronJobResult::STATUS_CRASHED) {
291 $actions[] = "reset";
292 }
293 // activate
294 elseif (!$a_set["job_status"]) {
295 $actions[] = "activate";
296 }
297 // deactivate
298 else {
299 if ($a_set['is_manually_executable']) {
300 $actions[] = 'run';
301 }
302 $actions[] = "deactivate";
303 }
304 // edit (schedule)
305 if ($a_set["editable_schedule"] || $a_set["has_settings"]) {
306 $actions[] = "edit";
307 }
308
309 $ilCtrl->setParameter($this->getParentObject(), "jid", $a_set["job_id"]);
310
311 foreach ($actions as $action) {
312 $this->tpl->setCurrentBlock("action_bl");
313 $this->tpl->setVariable(
314 "URL_ACTION",
315 $ilCtrl->getLinkTarget($this->getParentObject(), $action)
316 );
317 $this->tpl->setVariable("TXT_ACTION", $lng->txt("cron_action_" . $action));
318 $this->tpl->parseCurrentBlock();
319 }
320
321 $ilCtrl->setParameter($this->getParentObject(), "jid", "");
322 }
323 }
324}
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, $a_skip_day=false, $a_include_wd=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.
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.
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
global $ilCtrl
Definition: ilias.php:18
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
foreach($_POST as $key=> $value) $res