ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLoggerCronCleanErrorFiles.php
Go to the documentation of this file.
1 <?php
2 
3 require_once("Services/Cron/classes/class.ilCronJob.php");
4 require_once("Services/Logging/classes/error/class.ilLoggingErrorSettings.php");
5 require_once("Services/Administration/classes/class.ilSetting.php");
6 require_once("Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
7 require_once("Services/Form/classes/class.ilTextInputGUI.php");
8 require_once("Services/Calendar/classes/class.ilDateTime.php");
9 require_once("Services/Cron/classes/class.ilCronJobResult.php");
10 require_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() {
49  return self::SCHEDULE_TYPE_IN_DAYS;
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() {
84  $result = new ilCronJobResult();
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 
122  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form) {
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 }
$files
Definition: add-vimline.php:18
ILIAS Setting Class.
$path
Definition: aliased.php:25
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
$result
This class represents a property form user interface.
Cron job application base class.
addItem($a_item)
Add Item (Property, SectionHeader).
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
This class represents a text property in a property form.
Date and time handling
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
Create styles array
The data for the language used.
const IL_CAL_DATE
settings()
Definition: settings.php:2
global $lng
Definition: privfeed.php:17
$ret
Definition: parser.php:6
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
Cron job result data container.
setValue($a_value)
Set Value.