ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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, ?CronJobScheduleType $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 (?CronJobScheduleType $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
CronJobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Private Member Functions

 initDependencies ()
 

Detailed Description

Member Function Documentation

◆ getDefaultScheduleType()

ilFileSystemCleanTempDirCron::getDefaultScheduleType ( )

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

86  {
87  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
88  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getDefaultScheduleValue()

ilFileSystemCleanTempDirCron::getDefaultScheduleValue ( )

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

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

◆ getDescription()

ilFileSystemCleanTempDirCron::getDescription ( )

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

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

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

◆ getId()

ilFileSystemCleanTempDirCron::getId ( )

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

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

◆ getTitle()

ilFileSystemCleanTempDirCron::getTitle ( )

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

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

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

◆ hasAutoActivation()

ilFileSystemCleanTempDirCron::hasAutoActivation ( )

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

75  : bool
76  {
77  return false;
78  }

◆ hasFlexibleSchedule()

ilFileSystemCleanTempDirCron::hasFlexibleSchedule ( )

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

80  : bool
81  {
82  return true;
83  }

◆ initDependencies()

ilFileSystemCleanTempDirCron::initDependencies ( )
private

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

Referenced by run().

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

◆ run()

ilFileSystemCleanTempDirCron::run ( )

Definition at line 95 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.

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

◆ $language

ilLanguage ilFileSystemCleanTempDirCron::$language
protected

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

◆ $logger

ilLogger ilFileSystemCleanTempDirCron::$logger
protected

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


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