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