ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 global $lng;
17
18 $this->lng = $lng;
19 $this->lng->loadLanguageModule("logging");
20 $this->settings = new ilSetting('log');
21 $this->error_settings = ilLoggingErrorSettings::getInstance();
22 }
23
27 public function getId() {
28 return "log_error_file_cleanup";
29 }
30
34 public function getTitle() {
35 return $this->lng->txt("log_error_file_cleanup_title");
36 }
37
41 public function getDescription() {
42 return $this->lng->txt("log_error_file_cleanup_info");
43 }
44
48 public function getDefaultScheduleType() {
50 }
51
55 public function getDefaultScheduleValue() {
56 return 10;
57 }
58
62 public function hasAutoActivation() {
63 return false;
64 }
65
69 public function hasFlexibleSchedule() {
70 return true;
71 }
72
76 public function hasCustomSettings() {
77 return true;
78 }
79
83 public function run() {
85 $files = $this->readLogDir($this->error_settings->folder());
86 $delete_date = new ilDateTime(date("Y-m-d"), IL_CAL_DATE);
87 $delete_date->increment(ilDateTime::DAY, (-1 * $this->settings->get('clear_older_then')));
88
89 foreach ($files as $file) {
90 $file_date = date("Y-m-d", filemtime($this->error_settings->folder()."/".$file));
91
92 if($file_date <= $delete_date->get(IL_CAL_DATE)) {
93 $this->deleteFile($this->error_settings->folder()."/".$file);
94 }
95 }
96
98 return $result;
99 }
100
101 protected function readLogDir($path) {
102 $ret = array();
103
104 $folder = dir($path);
105 while ($file_name = $folder->read()) {
106 if (filetype($path."/".$file_name) != "dir") {
107 $ret[] = $file_name;
108 }
109 }
110 $folder->close();
111
112 return $ret;
113 }
114
115 protected function deleteFile($path) {
116 unlink($path);
117 }
118
123 $clear_older_then = new ilTextInputGUI($this->lng->txt('frm_clear_older_then'), 'clear_older_then');
124 $clear_older_then->setValue($this->settings->get('clear_older_then'));
125 $clear_older_then->setInfo($this->lng->txt('frm_clear_older_then_info'));
126
127 $a_form->addItem($clear_older_then);
128 }
129
134 public function saveCustomSettings(ilPropertyFormGUI $a_form)
135 {
136 $this->settings->set('clear_older_then', $a_form->getInput('clear_older_then'));
137 return true;
138 }
139}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$result
$files
Definition: add-vimline.php:18
$path
Definition: aliased.php:25
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