‪TYPO3CMS  10.4
RecyclerGarbageCollectionTask.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
34 {
41  public ‪$numberOfDays = 0;
42 
49  public function ‪execute()
50  {
51  $recyclerFolders = [];
52  $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
53  // takes only _recycler_ folder on the first level into account
54  foreach ($storageRepository->findAll() as $storage) {
55  $rootLevelFolder = $storage->getRootLevelFolder(false);
56  foreach ($rootLevelFolder->getSubfolders() as $subFolder) {
57  if ($subFolder->getRole() === $subFolder::ROLE_RECYCLER) {
58  $recyclerFolders[] = $subFolder;
59  break;
60  }
61  }
62  }
63 
64  // Execute cleanup
65  $seconds = 60 * 60 * 24 * (int)$this->numberOfDays;
66  $timestamp = ‪$GLOBALS['EXEC_TIME'] - $seconds;
67  foreach ($recyclerFolders as $recyclerFolder) {
68  $this->‪cleanupRecycledFiles($recyclerFolder, $timestamp);
69  }
70  return true;
71  }
72 
80  protected function ‪cleanupRecycledFiles(‪Folder $folder, $timestamp)
81  {
82  foreach ($folder->‪getFiles() as $file) {
83  if ($timestamp > $file->getModificationTime()) {
84  $file->delete();
85  }
86  }
87  foreach ($folder->‪getSubfolders() as $subFolder) {
88  $this->‪cleanupRecycledFiles($subFolder, $timestamp);
89  // if no more files and subdirectories are in the folder, remove the folder as well
90  if ($subFolder->getFileCount() === 0 && count($subFolder->getSubfolders()) === 0) {
91  $subFolder->delete(true);
92  }
93  }
94  }
95 }
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionTask\$numberOfDays
‪int $numberOfDays
Definition: RecyclerGarbageCollectionTask.php:40
‪TYPO3\CMS\Scheduler\Task
Definition: AbstractTask.php:16
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:35
‪TYPO3\CMS\Core\Resource\Folder\getSubfolders
‪Folder[] getSubfolders($start=0, $numberOfItems=0, $filterMode=self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive=false)
Definition: Folder.php:290
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:31
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionTask\cleanupRecycledFiles
‪cleanupRecycledFiles(Folder $folder, $timestamp)
Definition: RecyclerGarbageCollectionTask.php:79
‪TYPO3\CMS\Core\Resource\Folder\getFiles
‪TYPO3 CMS Core Resource File[] getFiles($start=0, $numberOfItems=0, $filterMode=self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive=false, $sort='', $sortRev=false)
Definition: Folder.php:218
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionTask
Definition: RecyclerGarbageCollectionTask.php:34
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionTask\execute
‪bool execute()
Definition: RecyclerGarbageCollectionTask.php:48
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46