ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
15 public function __construct()
16 {
17 global $lng;
18
19 $this->lng = $lng;
20 $this->lng->loadLanguageModule("logging");
21 $this->settings = new ilSetting('log');
22 $this->error_settings = ilLoggingErrorSettings::getInstance();
23 }
24
28 public function getId()
29 {
30 return "log_error_file_cleanup";
31 }
32
36 public function getTitle()
37 {
38 return $this->lng->txt("log_error_file_cleanup_title");
39 }
40
44 public function getDescription()
45 {
46 return $this->lng->txt("log_error_file_cleanup_info");
47 }
48
52 public function getDefaultScheduleType()
53 {
55 }
56
60 public function getDefaultScheduleValue()
61 {
62 return 10;
63 }
64
68 public function hasAutoActivation()
69 {
70 return false;
71 }
72
76 public function hasFlexibleSchedule()
77 {
78 return true;
79 }
80
84 public function hasCustomSettings()
85 {
86 return true;
87 }
88
92 public function run()
93 {
95 $folder = $this->error_settings->folder();
96 if (!is_dir($folder)) {
98 $result->setMessage($this->lng->txt("log_error_path_not_configured_or_wrong"));
99 return $result;
100 }
101
102 $files = $this->readLogDir($folder);
103 $delete_date = new ilDateTime(date("Y-m-d"), IL_CAL_DATE);
104 $delete_date->increment(ilDateTime::DAY, (-1 * $this->settings->get('clear_older_then')));
105
106 foreach ($files as $file) {
107 $file_date = date("Y-m-d", filemtime($this->error_settings->folder() . "/" . $file));
108
109 if ($file_date <= $delete_date->get(IL_CAL_DATE)) {
110 $this->deleteFile($this->error_settings->folder() . "/" . $file);
111 }
112 }
113
115 return $result;
116 }
117
118 protected function readLogDir($path)
119 {
120 $ret = array();
121
122 $folder = dir($path);
123 while ($file_name = $folder->read()) {
124 if (filetype($path . "/" . $file_name) != "dir") {
125 $ret[] = $file_name;
126 }
127 }
128 $folder->close();
129
130 return $ret;
131 }
132
133 protected function deleteFile($path)
134 {
135 unlink($path);
136 }
137
142 {
143 $clear_older_then = new ilTextInputGUI($this->lng->txt('frm_clear_older_then'), 'clear_older_then');
144 $clear_older_then->setValue($this->settings->get('clear_older_then'));
145 $clear_older_then->setInfo($this->lng->txt('frm_clear_older_then_info'));
146
147 $a_form->addItem($clear_older_then);
148 }
149
154 public function saveCustomSettings(ilPropertyFormGUI $a_form)
155 {
156 $this->settings->set('clear_older_then', $a_form->getInput('clear_older_then'));
157 return true;
158 }
159}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$result
$files
Definition: add-vimline.php:18
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 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.
This class represents a text property in a property form.
$ret
Definition: parser.php:6
global $lng
Definition: privfeed.php:17
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
settings()
Definition: settings.php:2