ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Cron\CronJob Class Reference
+ Inheritance diagram for ILIAS\Cron\CronJob:
+ Collaboration diagram for ILIAS\Cron\CronJob:

Public Member Functions

 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

JobScheduleType $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, ?JobScheduleType $schedule_type, ?int $schedule_value)
 

Detailed Description

Definition at line 26 of file CronJob.php.

Member Function Documentation

◆ activationWasToggled()

ILIAS\Cron\CronJob::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.

Definition at line 287 of file CronJob.php.

287 : void
288 {
289 }

◆ addCustomSettingsToForm()

ILIAS\Cron\CronJob::addCustomSettingsToForm ( \ilPropertyFormGUI  $a_form)
Deprecated:

Definition at line 253 of file CronJob.php.

253 : void
254 {
255 }

Referenced by ilCronManagerGUI\initLegacyEditForm().

+ Here is the caller graph for this function:

◆ addToExternalSettingsForm()

ILIAS\Cron\CronJob::addToExternalSettingsForm ( int  $a_form_id,
array &  $a_fields,
bool  $a_is_active 
)
Parameters
array<string,mixed>$a_fields

Reimplemented in ilCalendarCronRemoteReader, ilForumCronNotification, ilLDAPCronSynchronization, ilMembershipCronNotifications, and ilCronOerHarvester.

Definition at line 279 of file CronJob.php.

279 : void
280 {
281 }

◆ checkSchedule()

ILIAS\Cron\CronJob::checkSchedule ( ?\DateTimeImmutable  $last_run,
?JobScheduleType  $schedule_type,
?int  $schedule_value 
)
private

Definition at line 43 of file CronJob.php.

47 : bool {
48 if (null === $schedule_type) {
49 return false;
50 }
51
52 if (null === $last_run) {
53 return true;
54 }
55
56 if ($this->date_time_provider === null) {
57 $now = new \DateTimeImmutable('@' . time(), new \DateTimeZone(date_default_timezone_get()));
58 } else {
60 }
61
62 switch ($schedule_type) {
63 case JobScheduleType::DAILY:
64 $last = $last_run->format('Y-m-d');
65 $ref = $now->format('Y-m-d');
66 return ($last !== $ref);
67
68 case JobScheduleType::WEEKLY:
69 return $this->checkWeeklySchedule($last_run, $now);
70
71 case JobScheduleType::MONTHLY:
72 $last = $last_run->format('Y-n');
73 $ref = $now->format('Y-n');
74 return ($last !== $ref);
75
76 case JobScheduleType::QUARTERLY:
77 $last = $last_run->format('Y') . '-' . ceil(((int) $last_run->format('n')) / 3);
78 $ref = $now->format('Y') . '-' . ceil(((int) $now->format('n')) / 3);
79 return ($last !== $ref);
80
82 $last = $last_run->format('Y');
83 $ref = $now->format('Y');
84 return ($last !== $ref);
85
86 case JobScheduleType::IN_MINUTES:
87 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / 60);
88 return ($diff >= $schedule_value);
89
90 case JobScheduleType::IN_HOURS:
91 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60));
92 return ($diff >= $schedule_value);
93
94 case JobScheduleType::IN_DAYS:
95 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60 * 24));
96 return ($diff >= $schedule_value);
97 }
98
99 return false;
100 }
Closure $date_time_provider
Definition: CronJob.php:30
JobScheduleType $schedule_type
Definition: CronJob.php:28
checkWeeklySchedule(\DateTimeImmutable $last_run, \DateTimeImmutable $now)
Definition: CronJob.php:32

◆ checkWeeklySchedule()

ILIAS\Cron\CronJob::checkWeeklySchedule ( \DateTimeImmutable  $last_run,
\DateTimeImmutable  $now 
)
private

Definition at line 32 of file CronJob.php.

32 : bool
33 {
34 if ($last_run > $now) {
35 // Defensive check: last run is in the future → don't run again
36 return false;
37 }
38
39 // We are using ISO week/year to handle issues with week #52/#53 (see: https://mantis.ilias.de/view.php?id=36118 / https://en.wikipedia.org/wiki/ISO_8601#Week_dates)
40 return $last_run->format('o-W') !== $now->format('o-W');
41 }

◆ getAllScheduleTypes()

ILIAS\Cron\CronJob::getAllScheduleTypes ( )

Get all available schedule types.

Returns
list<JobScheduleType>

Definition at line 196 of file CronJob.php.

196 : array
197 {
198 return JobScheduleType::cases();
199 }

Referenced by ilCronManagerGUI\initEditForm(), and ilCronManagerGUI\initLegacyEditForm().

+ Here is the caller graph for this function:

◆ getCustomConfigurationInput()

ILIAS\Cron\CronJob::getCustomConfigurationInput ( \ILIAS\UI\Factory  $ui_factory,
\ILIAS\Refinery\Factory  $factory,
\ilLanguage  $lng 
)

Definition at line 241 of file CronJob.php.

246 throw new \RuntimeException('Not implemented');
247 }
This describes inputs that can be used in forms.
Definition: FormInput.php:33

Referenced by ilCronManagerGUI\initEditForm().

+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

◆ getDefaultScheduleValue()

◆ getDescription()

◆ getId()

◆ getScheduleType()

ILIAS\Cron\CronJob::getScheduleType ( )

Get current schedule type (if flexible)

Definition at line 156 of file CronJob.php.

157 {
158 if ($this->schedule_type && $this->hasFlexibleSchedule()) {
160 }
161
162 return null;
163 }

◆ getScheduleTypesWithValues()

ILIAS\Cron\CronJob::getScheduleTypesWithValues ( )
Returns
list<JobScheduleType>

Definition at line 204 of file CronJob.php.

204 : array
205 {
206 return [
207 JobScheduleType::IN_MINUTES,
208 JobScheduleType::IN_HOURS,
209 JobScheduleType::IN_DAYS,
210 ];
211 }

Referenced by ilCronManagerGUI\initEditForm(), and ilCronManagerGUI\initLegacyEditForm().

+ Here is the caller graph for this function:

◆ getScheduleValue()

ILIAS\Cron\CronJob::getScheduleValue ( )

Get current schedule value (if flexible)

Definition at line 168 of file CronJob.php.

168 : ?int
169 {
170 if ($this->schedule_value && $this->hasFlexibleSchedule()) {
172 }
173
174 return null;
175 }

◆ getTitle()

◆ getValidScheduleTypes()

ILIAS\Cron\CronJob::getValidScheduleTypes ( )

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

Returns
list<JobScheduleType>

Reimplemented in ilAuthDestroyExpiredSessionsCron, ilMailCronOrphanedMails, and ilSCCronTrash.

Definition at line 217 of file CronJob.php.

217 : array
218 {
219 return $this->getAllScheduleTypes();
220 }
getAllScheduleTypes()
Get all available schedule types.
Definition: CronJob.php:196

Referenced by ilCronManagerGUI\initEditForm(), and ilCronManagerGUI\initLegacyEditForm().

+ Here is the caller graph for this function:

◆ hasAutoActivation()

◆ hasCustomSettings()

◆ hasFlexibleSchedule()

◆ isDue()

ILIAS\Cron\CronJob::isDue ( ?\DateTimeImmutable  $last_run,
?JobScheduleType  $schedule_type,
?int  $schedule_value,
bool  $is_manually_executed = false 
)

Definition at line 135 of file CronJob.php.

140 : bool {
141 if ($is_manually_executed) {
142 return true;
143 }
144
145 if (!$this->hasFlexibleSchedule()) {
148 }
149
150 return $this->checkSchedule($last_run, $schedule_type, $schedule_value);
151 }
checkSchedule(?\DateTimeImmutable $last_run, ?JobScheduleType $schedule_type, ?int $schedule_value)
Definition: CronJob.php:43

◆ isManuallyExecutable()

ILIAS\Cron\CronJob::isManuallyExecutable ( )

Reimplemented in ilAuthDestroyExpiredSessionsCron.

Definition at line 222 of file CronJob.php.

222 : bool
223 {
224 return true;
225 }

Referenced by ilCronManagerGUI\confirm().

+ Here is the caller graph for this function:

◆ run()

◆ saveCustomConfiguration()

ILIAS\Cron\CronJob::saveCustomConfiguration ( mixed  $form_data)
Parameters
mixed$form_dataThe form data provided by the KS (\ILIAS\UI\Component\Input\Container\Container::getData)). The types and structure depend on the structure provided by getCustomConfigurationInput. It might be a single value or a array<string, mixed>-like structure.

Reimplemented in ilMailCronNotification.

Definition at line 262 of file CronJob.php.

262 : void
263 {
264 throw new \RuntimeException('Not implemented');
265 }

◆ saveCustomSettings()

ILIAS\Cron\CronJob::saveCustomSettings ( \ilPropertyFormGUI  $a_form)
Deprecated:

Definition at line 271 of file CronJob.php.

271 : bool
272 {
273 return true;
274 }

◆ setDateTimeProvider()

ILIAS\Cron\CronJob::setDateTimeProvider ( ?\Closure  $date_time_provider)
Parameters

Closure():\DateTimeInterface|null $date_time_provider

Definition at line 105 of file CronJob.php.

105 : void
106 {
107 if ($date_time_provider !== null) {
108 $r = new \ReflectionFunction($date_time_provider);
109 $return_type = $r->getReturnType();
110 if ($return_type instanceof \ReflectionNamedType) {
111 $return_type = $return_type->getName();
112 }
113 $expected_type = \DateTimeInterface::class;
114 if (!is_subclass_of($return_type, $expected_type)) {
115 throw new \InvalidArgumentException(
116 \sprintf(
117 'The return type of the datetime provider must be of type %s',
118 $expected_type
119 )
120 );
121 }
122
123 $r = new \ReflectionFunction($date_time_provider);
124 $parameters = $r->getParameters();
125 if ($parameters !== []) {
126 throw new \InvalidArgumentException(
127 'The datetime provider must not define any parameters',
128 );
129 }
130 }
131
132 $this->date_time_provider = $date_time_provider;
133 }

◆ setSchedule()

ILIAS\Cron\CronJob::setSchedule ( ?JobScheduleType  $a_type,
?int  $a_value 
)

Update current schedule (if flexible)

Definition at line 180 of file CronJob.php.

180 : void
181 {
182 if (
183 $a_value &&
184 $this->hasFlexibleSchedule() &&
185 \in_array($a_type, $this->getValidScheduleTypes(), true)
186 ) {
187 $this->schedule_type = $a_type;
188 $this->schedule_value = $a_value;
189 }
190 }
getValidScheduleTypes()
Returns a collection of all valid schedule types for a specific job.
Definition: CronJob.php:217

◆ usesLegacyForms()

ILIAS\Cron\CronJob::usesLegacyForms ( )
Deprecated:

Reimplemented in ilMailCronNotification.

Definition at line 236 of file CronJob.php.

236 : bool
237 {
238 return true;
239 }

Field Documentation

◆ $date_time_provider

Closure ILIAS\Cron\CronJob::$date_time_provider = null
protected

Definition at line 30 of file CronJob.php.

◆ $schedule_type

JobScheduleType ILIAS\Cron\CronJob::$schedule_type = null
protected

Definition at line 28 of file CronJob.php.

◆ $schedule_value

int ILIAS\Cron\CronJob::$schedule_value = null
protected

Definition at line 29 of file CronJob.php.


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