ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLoggerCronCleanErrorFiles.php
Go to the documentation of this file.
1<?php
2
3require_once("Services/Cron/classes/class.ilCronJob.php");
4require_once("Services/Logging/classes/error/class.ilLoggingErrorSettings.php");
5require_once("Services/Administration/classes/class.ilSetting.php");
6require_once("Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
7require_once("Services/Form/classes/class.ilTextInputGUI.php");
8require_once("Services/Calendar/classes/class.ilDateTime.php");
9require_once("Services/Cron/classes/class.ilCronJobResult.php");
10require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
11
12
14{
16
17 public function __construct()
18 {
19 global $DIC;
20
21 $lng = $DIC['lng'];
22
23 $this->lng = $lng;
24 $this->lng->loadLanguageModule("logging");
25 $this->settings = new ilSetting('log');
26 $this->error_settings = ilLoggingErrorSettings::getInstance();
27 }
28
32 public function getId()
33 {
34 return "log_error_file_cleanup";
35 }
36
40 public function getTitle()
41 {
42 return $this->lng->txt("log_error_file_cleanup_title");
43 }
44
48 public function getDescription()
49 {
50 return $this->lng->txt("log_error_file_cleanup_info");
51 }
52
56 public function getDefaultScheduleType()
57 {
59 }
60
64 public function getDefaultScheduleValue()
65 {
66 return 10;
67 }
68
72 public function hasAutoActivation()
73 {
74 return false;
75 }
76
80 public function hasFlexibleSchedule()
81 {
82 return true;
83 }
84
88 public function hasCustomSettings()
89 {
90 return true;
91 }
92
96 public function run()
97 {
99 $folder = $this->error_settings->folder();
100 if (!is_dir($folder)) {
102 $result->setMessage($this->lng->txt("log_error_path_not_configured_or_wrong"));
103 return $result;
104 }
105
106 $offset = $this->settings->get('clear_older_then');
107 if (!$offset) {
109 }
110
111 $files = $this->readLogDir($folder);
112 $delete_date = new ilDateTime(date("Y-m-d"), IL_CAL_DATE);
113 $delete_date->increment(ilDateTime::DAY, (-1 * $offset));
114
115 foreach ($files as $file) {
116 $file_date = date("Y-m-d", filemtime($this->error_settings->folder() . "/" . $file));
117
118 if ($file_date <= $delete_date->get(IL_CAL_DATE)) {
119 $this->deleteFile($this->error_settings->folder() . "/" . $file);
120 }
121 }
122
124 return $result;
125 }
126
127 protected function readLogDir($path)
128 {
129 $ret = array();
130
131 $folder = dir($path);
132 while ($file_name = $folder->read()) {
133 if (filetype($path . "/" . $file_name) != "dir") {
134 $ret[] = $file_name;
135 }
136 }
137 $folder->close();
138
139 return $ret;
140 }
141
142 protected function deleteFile($path)
143 {
144 unlink($path);
145 }
146
151 {
152 $offset = $this->settings->get('clear_older_then');
153 if (!$offset) {
155 }
156 $clear_older_then = new ilNumberInputGUI($this->lng->txt('frm_clear_older_then'), 'clear_older_then');
157 $clear_older_then->allowDecimals(false);
158 $clear_older_then->setMinValue(1, true);
159 $clear_older_then->setValue($offset);
160 $clear_older_then->setInfo($this->lng->txt('frm_clear_older_then_info'));
161
162 $a_form->addItem($clear_older_then);
163 }
164
169 public function saveCustomSettings(ilPropertyFormGUI $a_form)
170 {
171 $this->settings->set('clear_older_then', $a_form->getInput('clear_older_then'));
172 return true;
173 }
174}
$result
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_IN_DAYS
@classDescription Date and time handling
hasFlexibleSchedule()
Can the schedule be configured?boolean
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
Add custom settings to form.
getDefaultScheduleValue()
Get schedule value.int|array
hasCustomSettings()
Has cron job any custom setting which can be edited?boolean
hasAutoActivation()
Is to be activated on "installation".boolean
This class represents a number property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
ILIAS Setting Class.
global $DIC
Definition: goto.php:24
$ret
Definition: parser.php:6
$lng
settings()
Definition: settings.php:2