TYPO3 CMS  TYPO3_6-2
RecyclerGarbageCollectionTask.php
Go to the documentation of this file.
1 <?php
3 
26 
33  public $numberOfDays = 0;
34 
40  protected $recyclerDirectory = '_recycler_';
41 
47  public function execute() {
48  // There is no file ctime on windows, so this task disables itself if OS = win
49  if (TYPO3_OS == 'WIN') {
50  throw new \BadMethodCallException('This task is not reliable for Windows OS', 1308270454);
51  }
52  $seconds = 60 * 60 * 24 * (int)$this->numberOfDays;
53  $timestamp = $GLOBALS['EXEC_TIME'] - $seconds;
54  // Get fileadmin directory
55  $directory = PATH_site . 'fileadmin/';
56  if (!empty($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'])) {
57  $directory = PATH_site . trim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']);
58  }
59  // Execute cleanup
60  return $this->cleanupRecycledFiles($directory, $timestamp);
61  }
62 
72  protected function cleanupRecycledFiles($directory, $timestamp) {
74  $timestamp = (int)$timestamp;
75  // Check if given directory exists
76  if (!@is_dir($directory)) {
77  throw new \RuntimeException('Given directory "' . $directory . '" does not exist', 1301614535);
78  }
79  // Find all _recycler_ directories
80  $directoryContent = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
81  foreach ($directoryContent as $fileName => $file) {
82  // Skip directories and files without recycler directory in absolute path
83  $filePath = $file->getPath();
84  if (substr($filePath, strrpos($filePath, '/') + 1) !== $this->recyclerDirectory) {
85  continue;
86  }
87  // Remove files from _recycler_ that where moved to this folder for more than 'number of days'
88  if ($file->isFile() && $timestamp > $file->getCTime()) {
89  if (!@unlink($fileName)) {
90  throw new \RuntimeException('Could not remove file "' . $fileName . '"', 1301614537);
91  }
92  }
93  }
94  return TRUE;
95  }
96 
97 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)