ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilFileSystemCleanTempDirCron Class Reference

Class ilFileSystemCleanTempDirCron. More...

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

Public Member Functions

 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 
- Public Member Functions inherited from ILIAS\Cron\CronJob
 setDateTimeProvider (?\Closure $date_time_provider)
 
 isDue (?\DateTimeImmutable $last_run, ?JobScheduleType $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 (?JobScheduleType $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 ()
 
 usesLegacyForms ()
 
 getCustomConfigurationInput (\ILIAS\UI\Factory $ui_factory, \ILIAS\Refinery\Factory $factory, \ilLanguage $lng)
 
 addCustomSettingsToForm (\ilPropertyFormGUI $a_form)
 
 saveCustomConfiguration (mixed $form_data)
 
 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

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

Private Member Functions

 initDependencies ()
 

Detailed Description

Member Function Documentation

◆ getDefaultScheduleType()

ilFileSystemCleanTempDirCron::getDefaultScheduleType ( )

Reimplemented from ILIAS\Cron\CronJob.

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

89 {
90 return JobScheduleType::DAILY;
91 }

◆ getDefaultScheduleValue()

ilFileSystemCleanTempDirCron::getDefaultScheduleValue ( )

Reimplemented from ILIAS\Cron\CronJob.

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

93 : ?int
94 {
95 return 1;
96 }

◆ getDescription()

ilFileSystemCleanTempDirCron::getDescription ( )

Reimplemented from ILIAS\Cron\CronJob.

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

73 : string
74 {
75 return $this->language->txt("file_system_clean_temp_dir_cron_info");
76 }

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

+ Here is the call graph for this function:

◆ getId()

ilFileSystemCleanTempDirCron::getId ( )

Reimplemented from ILIAS\Cron\CronJob.

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

63 : string
64 {
65 return "file_system_clean_temp_dir";
66 }

◆ getTitle()

ilFileSystemCleanTempDirCron::getTitle ( )

Reimplemented from ILIAS\Cron\CronJob.

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

68 : string
69 {
70 return $this->language->txt('file_system_clean_temp_dir_cron');
71 }

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

+ Here is the call graph for this function:

◆ hasAutoActivation()

ilFileSystemCleanTempDirCron::hasAutoActivation ( )

Is to be activated on "installation", does only work for ILIAS core cron jobs.

Reimplemented from ILIAS\Cron\CronJob.

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

78 : bool
79 {
80 return false;
81 }

◆ hasFlexibleSchedule()

ilFileSystemCleanTempDirCron::hasFlexibleSchedule ( )

Reimplemented from ILIAS\Cron\CronJob.

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

83 : bool
84 {
85 return true;
86 }

◆ initDependencies()

ilFileSystemCleanTempDirCron::initDependencies ( )
private

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

59 : void
60 {
61 }

Referenced by run().

+ Here is the caller graph for this function:

◆ run()

ilFileSystemCleanTempDirCron::run ( )

Reimplemented from ILIAS\Cron\CronJob.

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

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

References Vendor\Package\$a, Vendor\Package\$b, $path, ILIAS\Repository\filesystem(), initDependencies(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Field Documentation

◆ $filesystem

Filesystem ilFileSystemCleanTempDirCron::$filesystem
protected

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

◆ $language

ilLanguage ilFileSystemCleanTempDirCron::$language
protected

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

◆ $logger

ilLogger ilFileSystemCleanTempDirCron::$logger
protected

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


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