ILIAS  release_8 Revision v8.23
ilFileSystemCleanTempDirCron Class Reference

Class ilFileSystemCleanTempDirCron. More...

+ Inheritance diagram for ilFileSystemCleanTempDirCron:
+ Collaboration diagram for ilFileSystemCleanTempDirCron:

Public Member Functions

 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?int $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule (?int $a_type, ?int $a_value)
 Update current schedule (if flexible) More...
 
 getAllScheduleTypes ()
 Get all available schedule types. More...
 
 getScheduleTypesWithValues ()
 
 getValidScheduleTypes ()
 Returns a collection of all valid schedule types for a specific job. More...
 
 isManuallyExecutable ()
 
 hasCustomSettings ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
 activationWasToggled (ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
 Important: This method is (also) called from the setup process, where the constructor of an ilCronJob ist NOT executed. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 

Protected Attributes

ILIAS Filesystem Filesystem $filesystem
 
ilLanguage $language
 
ilLogger $logger
 
- Protected Attributes inherited from ilCronJob
int $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Private Member Functions

 initDependencies ()
 

Additional Inherited Members

- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_HOURS = 3
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_DAYS = 4
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_WEEKLY = 5
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_MONTHLY = 6
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_QUARTERLY = 7
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_YEARLY = 8
 This will be replaced with an ENUM in ILIAS 9 More...
 

Detailed Description

Member Function Documentation

◆ getDefaultScheduleType()

ilFileSystemCleanTempDirCron::getDefaultScheduleType ( )

Definition at line 84 of file class.ilFileSystemCleanTempDirCron.php.

84  : int
85  {
86  return self::SCHEDULE_TYPE_DAILY;
87  }

◆ getDefaultScheduleValue()

ilFileSystemCleanTempDirCron::getDefaultScheduleValue ( )

Definition at line 89 of file class.ilFileSystemCleanTempDirCron.php.

89  : ?int
90  {
91  return 1;
92  }

◆ getDescription()

ilFileSystemCleanTempDirCron::getDescription ( )

Definition at line 69 of file class.ilFileSystemCleanTempDirCron.php.

References ILIAS\UI\examples\Symbol\Glyph\Language\language().

69  : string
70  {
71  return $this->language->txt("file_system_clean_temp_dir_cron_info");
72  }
+ Here is the call graph for this function:

◆ getId()

ilFileSystemCleanTempDirCron::getId ( )

Definition at line 59 of file class.ilFileSystemCleanTempDirCron.php.

59  : string
60  {
61  return "file_system_clean_temp_dir";
62  }

◆ getTitle()

ilFileSystemCleanTempDirCron::getTitle ( )

Definition at line 64 of file class.ilFileSystemCleanTempDirCron.php.

References ILIAS\UI\examples\Symbol\Glyph\Language\language().

64  : string
65  {
66  return $this->language->txt('file_system_clean_temp_dir_cron');
67  }
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilFileSystemCleanTempDirCron::hasAutoActivation ( )

Definition at line 74 of file class.ilFileSystemCleanTempDirCron.php.

74  : bool
75  {
76  return false;
77  }

◆ hasFlexibleSchedule()

ilFileSystemCleanTempDirCron::hasFlexibleSchedule ( )

Definition at line 79 of file class.ilFileSystemCleanTempDirCron.php.

79  : bool
80  {
81  return true;
82  }

◆ initDependencies()

ilFileSystemCleanTempDirCron::initDependencies ( )
private

Definition at line 55 of file class.ilFileSystemCleanTempDirCron.php.

Referenced by run().

55  : void
56  {
57  }
+ Here is the caller graph for this function:

◆ run()

ilFileSystemCleanTempDirCron::run ( )

Definition at line 94 of file class.ilFileSystemCleanTempDirCron.php.

References Vendor\Package\$a, Vendor\Package\$b, $path, ILIAS\Repository\filesystem(), ILIAS\Filesystem\DTO\Metadata\getPath(), initDependencies(), ILIAS\Repository\logger(), and ilCronJobResult\STATUS_OK.

95  {
96  $this->initDependencies();
97  // only delete files and folders older than ten days to prevent issues with ongoing processes (e.g. zipping a folder)
98  $date = "until 10 day ago";
99 
100  // files are deleted before folders to prevent issues that would arise when trying to delete a (no longer existing) file in a deleted folder.
101  $files = $this->filesystem->finder()->in([""]);
102  $files = $files->files();
103  $files = $files->date($date);
104  $files = $files->getIterator();
105  $files->rewind();
106  $deleted_files = [];
107  while ($files->valid()) {
108  try {
109  $file_match = $files->current();
110  $path = $file_match->getPath();
111  if ($file_match->isFile()) {
112  $this->filesystem->delete($path);
113  $deleted_files[] = $path;
114  }
115  $files->next();
116  } catch (Throwable $t) {
117  $this->logger->error(
118  "Cron Job \"Clean temp directory\" could not delete " . $path
119  . "due to the following exception: " . $t->getMessage()
120  );
121  $files->next();
122  }
123  }
124 
125  // the folders are sorted based on their path length to ensure that nested folders are deleted first
126  // thereby preventing any issues due to deletion attempts on no longer existing folders.
127  $folders = $this->filesystem->finder()->in([""]);
128  $folders = $folders->directories();
129  $folders = $folders->date($date);
130  $folders = $folders->sort(fn (
131  Metadata $a,
132  Metadata $b
133  ): int => strlen($a->getPath()) - strlen($b->getPath()));
134  $folders = $folders->reverseSorting();
135  $folders = $folders->getIterator();
136 
137  $deleted_folders = [];
138 
139  $folders->rewind();
140  while ($folders->valid()) {
141  try {
142  $folder_match = $folders->current();
143  $path = $folder_match->getPath();
144  if ($folder_match->isDir()) {
145  $this->filesystem->deleteDir($path);
146  $deleted_folders[] = $path;
147  }
148  $folders->next();
149  } catch (Throwable $t) {
150  $this->logger->error(
151  "Cron Job \"Clean temp directory\" could not delete " . $path
152  . "due to the following exception: " . $t->getMessage()
153  );
154  $folders->next();
155  }
156  }
157 
158  $num_folders = count($deleted_folders);
159  $num_files = count($deleted_files);
160 
161  $result = new ilCronJobResult();
162  $result->setMessage($num_folders . " folders and " . $num_files . " files have been deleted.");
163  $result->setStatus(ilCronJobResult::STATUS_OK);
164  return $result;
165  }
getPath()
The path to the file or directory.
Definition: Metadata.php:56
$path
Definition: ltiservices.php:32
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

Field Documentation

◆ $filesystem

ILIAS Filesystem Filesystem ilFileSystemCleanTempDirCron::$filesystem
protected

Definition at line 29 of file class.ilFileSystemCleanTempDirCron.php.

◆ $language

ilLanguage ilFileSystemCleanTempDirCron::$language
protected

Definition at line 31 of file class.ilFileSystemCleanTempDirCron.php.

◆ $logger

ilLogger ilFileSystemCleanTempDirCron::$logger
protected

Definition at line 33 of file class.ilFileSystemCleanTempDirCron.php.


The documentation for this class was generated from the following file: