ILIAS  release_8 Revision v8.24
ilCronJob Class Reference
+ Inheritance diagram for ilCronJob:
+ Collaboration diagram for ilCronJob:

Public Member Functions

 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 ()
 

Data Fields

const SCHEDULE_TYPE_DAILY = 1
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_HOURS = 3
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_DAYS = 4
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_WEEKLY = 5
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_MONTHLY = 6
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_QUARTERLY = 7
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_YEARLY = 8
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 

Protected Attributes

int $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Private Member Functions

 checkWeeklySchedule (DateTimeImmutable $last_run, DateTimeImmutable $now)
 
 checkSchedule (?DateTimeImmutable $last_run, ?int $schedule_type, ?int $schedule_value)
 

Detailed Description

Definition at line 21 of file class.ilCronJob.php.

Member Function Documentation

◆ activationWasToggled()

ilCronJob::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.

Furthermore only few dependencies may be available in the $DIC.

Parameters
ilDBInterface$db
ilSetting$setting
bool$a_currently_active
Returns
void

Reimplemented in ilForumCronNotification, ilMailCronNotification, and ilMembershipCronNotifications.

Definition at line 300 of file class.ilCronJob.php.

300 : void
301 {
302 }

Referenced by ilCronManagerImpl\activateJob(), and ilCronManagerImpl\deactivateJob().

+ Here is the caller graph for this function:

◆ addCustomSettingsToForm()

◆ addToExternalSettingsForm()

ilCronJob::addToExternalSettingsForm ( int  $a_form_id,
array &  $a_fields,
bool  $a_is_active 
)

◆ checkSchedule()

ilCronJob::checkSchedule ( ?DateTimeImmutable  $last_run,
?int  $schedule_type,
?int  $schedule_value 
)
private

Definition at line 82 of file class.ilCronJob.php.

82 : bool
83 {
84 if (null === $schedule_type) {
85 return false;
86 }
87
88 if (null === $last_run) {
89 return true;
90 }
91
92 if ($this->date_time_provider === null) {
93 $now = new DateTimeImmutable('@' . time(), new DateTimeZone(date_default_timezone_get()));
94 } else {
96 }
97
98 switch ($schedule_type) {
100 $last = $last_run->format('Y-m-d');
101 $ref = $now->format('Y-m-d');
102 return ($last !== $ref);
103
105 return $this->checkWeeklySchedule($last_run, $now);
106
108 $last = $last_run->format('Y-n');
109 $ref = $now->format('Y-n');
110 return ($last !== $ref);
111
113 $last = $last_run->format('Y') . '-' . ceil(((int) $last_run->format('n')) / 3);
114 $ref = $now->format('Y') . '-' . ceil(((int) $now->format('n')) / 3);
115 return ($last !== $ref);
116
118 $last = $last_run->format('Y');
119 $ref = $now->format('Y');
120 return ($last !== $ref);
121
123 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / 60);
124 return ($diff >= $schedule_value);
125
127 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60));
128 return ($diff >= $schedule_value);
129
131 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60 * 24));
132 return ($diff >= $schedule_value);
133 }
134
135 return false;
136 }
const SCHEDULE_TYPE_IN_DAYS
@depracated This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_IN_HOURS
@depracated This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_IN_MINUTES
@depracated This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_WEEKLY
@depracated This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_YEARLY
@depracated This will be replaced with an ENUM in ILIAS 9
checkWeeklySchedule(DateTimeImmutable $last_run, DateTimeImmutable $now)
const SCHEDULE_TYPE_DAILY
@depracated This will be replaced with an ENUM in ILIAS 9
Closure $date_time_provider
const SCHEDULE_TYPE_QUARTERLY
@depracated This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_MONTHLY
@depracated This will be replaced with an ENUM in ILIAS 9

References $date_time_provider, $schedule_type, $schedule_value, checkWeeklySchedule(), SCHEDULE_TYPE_DAILY, SCHEDULE_TYPE_IN_DAYS, SCHEDULE_TYPE_IN_HOURS, SCHEDULE_TYPE_IN_MINUTES, SCHEDULE_TYPE_MONTHLY, SCHEDULE_TYPE_QUARTERLY, SCHEDULE_TYPE_WEEKLY, and SCHEDULE_TYPE_YEARLY.

+ Here is the call graph for this function:

◆ checkWeeklySchedule()

ilCronJob::checkWeeklySchedule ( DateTimeImmutable  $last_run,
DateTimeImmutable  $now 
)
private

Definition at line 44 of file class.ilCronJob.php.

44 : bool
45 {
46 $last_year = (int) $last_run->format('Y');
47 $now_year = (int) $now->format('Y');
48
49 if ($last_year > $now_year) {
50 // Should never happen, don't execute otherwise
51 return false;
52 }
53
54 $last_week = $last_run->format('W');
55 $now_week = $now->format('W');
56
57 if ($last_week !== $now_week) {
58 // Week differs, always execute the job
59 return true;
60 }
61
62 // For all following cases, the week number is always identical
63
64 $last_month = (int) $last_run->format('m');
65 $now_month = (int) $now->format('m');
66
67 $is_within_same_week_in_same_year = ($last_year . '-' . $last_week) === ($now_year . '-' . $now_week);
68 if ($is_within_same_week_in_same_year) {
69 // Same week in same year, only execute if the month differs (2022-52 is valid for January and December)
70 return $last_month !== $now_month && $now->diff($last_run)->d > 7;
71 }
72
73 if ($now_year - $last_year > 1) {
74 // Always execute if the difference of years is greater than 1
75 return true;
76 }
77
78 // Execute for week number 52 in 2022 (last run) and week number 52 in December of 2022 (now), but not for week number 52 in January of 2022 (now)
79 return $last_month === $now_month;
80 }

References ILIAS\Repository\int().

Referenced by checkSchedule().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAllScheduleTypes()

ilCronJob::getAllScheduleTypes ( )

Get all available schedule types.

Returns
int[]

Definition at line 234 of file class.ilCronJob.php.

◆ getDefaultScheduleType()

◆ getDefaultScheduleValue()

◆ getDescription()

◆ getId()

◆ getScheduleType()

ilCronJob::getScheduleType ( )

Get current schedule type (if flexible)

Returns
int|null

Definition at line 191 of file class.ilCronJob.php.

191 : ?int
192 {
193 if ($this->schedule_type && $this->hasFlexibleSchedule()) {
195 }
196
197 return null;
198 }
hasFlexibleSchedule()

◆ getScheduleTypesWithValues()

ilCronJob::getScheduleTypesWithValues ( )
Returns
int[]

Definition at line 251 of file class.ilCronJob.php.

251 : array
252 {
253 return [
257 ];
258 }

◆ getScheduleValue()

ilCronJob::getScheduleValue ( )

Get current schedule value (if flexible)

Returns
int|null

Definition at line 204 of file class.ilCronJob.php.

204 : ?int
205 {
206 if ($this->schedule_value && $this->hasFlexibleSchedule()) {
208 }
209
210 return null;
211 }

◆ getTitle()

◆ getValidScheduleTypes()

ilCronJob::getValidScheduleTypes ( )

Returns a collection of all valid schedule types for a specific job.

Returns
int[]

Reimplemented in ilMailCronOrphanedMails, and ilSCCronTrash.

Definition at line 264 of file class.ilCronJob.php.

264 : array
265 {
266 return $this->getAllScheduleTypes();
267 }
getAllScheduleTypes()
Get all available schedule types.

Referenced by ilCronJobRepositoryImpl\updateJobSchedule().

+ Here is the caller graph for this function:

◆ hasAutoActivation()

◆ hasCustomSettings()

◆ hasFlexibleSchedule()

◆ isDue()

ilCronJob::isDue ( ?DateTimeImmutable  $last_run,
?int  $schedule_type,
?int  $schedule_value,
bool  $is_manually_executed = false 
)

Definition at line 169 of file class.ilCronJob.php.

174 : bool {
175 if ($is_manually_executed) {
176 return true;
177 }
178
179 if (!$this->hasFlexibleSchedule()) {
182 }
183
184 return $this->checkSchedule($last_run, $schedule_type, $schedule_value);
185 }
getDefaultScheduleType()
getDefaultScheduleValue()
checkSchedule(?DateTimeImmutable $last_run, ?int $schedule_type, ?int $schedule_value)

Referenced by ilCronManagerImpl\runJob().

+ Here is the caller graph for this function:

◆ isManuallyExecutable()

ilCronJob::isManuallyExecutable ( )

Definition at line 269 of file class.ilCronJob.php.

269 : bool
270 {
271 return true;
272 }

Referenced by ilCronManagerGUI\confirm().

+ Here is the caller graph for this function:

◆ run()

◆ saveCustomSettings()

◆ setDateTimeProvider()

ilCronJob::setDateTimeProvider ( ?Closure  $date_time_provider)
Parameters
Closure():DateTimeInterface|null$date_time_provider

Definition at line 141 of file class.ilCronJob.php.

141 : void
142 {
143 if ($date_time_provider !== null) {
144 $r = new ReflectionFunction($date_time_provider);
145 $return_type = $r->getReturnType();
146 if ($return_type !== null) {
147 $return_type = $return_type->getName();
148 }
149 $expected_type = DateTimeInterface::class;
150 if (!is_subclass_of($return_type, $expected_type)) {
151 throw new InvalidArgumentException(sprintf(
152 'The return type of the datetime provider must be of type %s',
153 $expected_type
154 ));
155 }
156
157 $r = new ReflectionFunction($date_time_provider);
158 $parameters = $r->getParameters();
159 if ($parameters !== []) {
160 throw new InvalidArgumentException(
161 'The datetime provider must not define any parameters',
162 );
163 }
164 }
165
166 $this->date_time_provider = $date_time_provider;
167 }

References $date_time_provider.

Referenced by ilCronManagerImpl\runJob().

+ Here is the caller graph for this function:

◆ setSchedule()

ilCronJob::setSchedule ( ?int  $a_type,
?int  $a_value 
)

Update current schedule (if flexible)

Parameters
int | null$a_type
int | null$a_value

Definition at line 218 of file class.ilCronJob.php.

218 : void
219 {
220 if (
221 $a_value &&
222 $this->hasFlexibleSchedule() &&
223 in_array($a_type, $this->getValidScheduleTypes(), true)
224 ) {
225 $this->schedule_type = $a_type;
226 $this->schedule_value = $a_value;
227 }
228 }
getValidScheduleTypes()
Returns a collection of all valid schedule types for a specific job.

Field Documentation

◆ $date_time_provider

Closure ilCronJob::$date_time_provider = null
protected

Definition at line 42 of file class.ilCronJob.php.

Referenced by checkSchedule(), and setDateTimeProvider().

◆ $schedule_type

int ilCronJob::$schedule_type = null
protected

Definition at line 40 of file class.ilCronJob.php.

Referenced by checkSchedule().

◆ $schedule_value

int ilCronJob::$schedule_value = null
protected

Definition at line 41 of file class.ilCronJob.php.

Referenced by checkSchedule().

◆ SCHEDULE_TYPE_DAILY

const ilCronJob::SCHEDULE_TYPE_DAILY = 1

@depracated This will be replaced with an ENUM in ILIAS 9

Definition at line 24 of file class.ilCronJob.php.

Referenced by checkSchedule(), ilCronManagerTableFilterMediator\filter(), ilCronManagerTableGUI\formatSchedule(), ilBookCronNotification\getDefaultScheduleType(), ilBookingPrefBookCron\getDefaultScheduleType(), ilXapiResultsCronjob\getDefaultScheduleType(), ilTimingsCronReminder\getDefaultScheduleType(), ilExcCronFeedbackNotification\getDefaultScheduleType(), ilExcCronReminders\getDefaultScheduleType(), ilCronUpdateOrgUnitPaths\getDefaultScheduleType(), ilSurveyCronNotification\getDefaultScheduleType(), ilCronFinishUnfinishedTestPasses\getDefaultScheduleType(), ilConsultationHourCron\getDefaultScheduleType(), ilCleanCOPageHistoryCronjob\getDefaultScheduleType(), ilFileSystemCleanTempDirCron\getDefaultScheduleType(), ilLDAPCronSynchronization\getDefaultScheduleType(), ilLTICronOutcomeService\getDefaultScheduleType(), ilMailCronNotification\getDefaultScheduleType(), ilMailCronOrphanedMails\getDefaultScheduleType(), ilMembershipCronMinMembers\getDefaultScheduleType(), ilMembershipCronNotifications\getDefaultScheduleType(), ilCronOerHarvester\getDefaultScheduleType(), ilLuceneIndexer\getDefaultScheduleType(), ilSkillNotifications\getDefaultScheduleType(), ilLPCronObjectStatistics\getDefaultScheduleType(), ilCronDeleteInactivatedUserAccounts\getDefaultScheduleType(), ilCronDeleteInactiveUserAccounts\getDefaultScheduleType(), ilCronDeleteNeverLoggedInUserAccounts\getDefaultScheduleType(), ilUserCronCheckAccounts\getDefaultScheduleType(), ilCronManagerGUI\getScheduleTypeFormElementName(), ilCronDeleteInactiveUserAccounts\getTimeDifferenceBySchedule(), ilMailCronOrphanedMails\getValidScheduleTypes(), ilSCCronTrash\getValidScheduleTypes(), CronJobScheduleTest\jobProvider(), CronJobEntityTest\testEffectiveScheduleCanBeDetermined(), and ilCronFinishUnfinishedTestPassesTest\testGetDefaultScheduleType().

◆ SCHEDULE_TYPE_IN_DAYS

◆ SCHEDULE_TYPE_IN_HOURS

◆ SCHEDULE_TYPE_IN_MINUTES

◆ SCHEDULE_TYPE_MONTHLY

◆ SCHEDULE_TYPE_QUARTERLY

◆ SCHEDULE_TYPE_WEEKLY

◆ SCHEDULE_TYPE_YEARLY


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