ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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.

References ILIAS\Cron\CronJob\getDefaultScheduleType(), ILIAS\Cron\CronJob\getDefaultScheduleValue(), ILIAS\Cron\CronJob\getDescription(), ILIAS\Cron\CronJob\getId(), ILIAS\Cron\CronJob\getTitle(), ILIAS\Cron\CronJob\hasAutoActivation(), ILIAS\Cron\CronJob\hasFlexibleSchedule(), ILIAS\Repository\int(), and ILIAS\Cron\CronJob\run().

287  : void
288  {
289  }
+ Here is the call graph for this function:

◆ addCustomSettingsToForm()

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

Definition at line 253 of file CronJob.php.

Referenced by ilCronManagerGUI\initLegacyEditForm().

253  : void
254  {
255  }
+ 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

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.

References ILIAS\Cron\CronJob\$date_time_provider, ILIAS\Cron\CronJob\checkWeeklySchedule(), null, and ILIAS\Cron\Job\Schedule\YEARLY.

Referenced by ILIAS\Cron\CronJob\isDue().

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 {
59  $now = ($this->date_time_provider)();
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  }
JobScheduleType $schedule_type
Definition: CronJob.php:28
checkWeeklySchedule(\DateTimeImmutable $last_run, \DateTimeImmutable $now)
Definition: CronJob.php:32
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Closure $date_time_provider
Definition: CronJob.php:30
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkWeeklySchedule()

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

Definition at line 32 of file CronJob.php.

Referenced by ILIAS\Cron\CronJob\checkSchedule().

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  }
+ Here is the caller graph for this function:

◆ getAllScheduleTypes()

ILIAS\Cron\CronJob::getAllScheduleTypes ( )

Get all available schedule types.

Returns
list<JobScheduleType>

Definition at line 196 of file CronJob.php.

Referenced by ILIAS\Cron\CronJob\getValidScheduleTypes(), ilCronManagerGUI\initEditForm(), and ilCronManagerGUI\initLegacyEditForm().

196  : array
197  {
198  return JobScheduleType::cases();
199  }
+ 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.

Referenced by ilCronManagerGUI\initEditForm().

245  : \ILIAS\UI\Component\Input\Container\Form\FormInput {
246  throw new \RuntimeException('Not implemented');
247  }
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ILIAS\Cron\CronJob::getDefaultScheduleType ( )
abstract

Referenced by ILIAS\Cron\CronJob\activationWasToggled(), and ILIAS\Cron\CronJob\isDue().

+ Here is the caller graph for this function:

◆ getDefaultScheduleValue()

ILIAS\Cron\CronJob::getDefaultScheduleValue ( )
abstract

Referenced by ILIAS\Cron\CronJob\activationWasToggled(), and ILIAS\Cron\CronJob\isDue().

+ Here is the caller graph for this function:

◆ getDescription()

ILIAS\Cron\CronJob::getDescription ( )
abstract

Referenced by ILIAS\Cron\CronJob\activationWasToggled().

+ Here is the caller graph for this function:

◆ getId()

ILIAS\Cron\CronJob::getId ( )
abstract

◆ getScheduleType()

ILIAS\Cron\CronJob::getScheduleType ( )

Get current schedule type (if flexible)

Definition at line 156 of file CronJob.php.

References ILIAS\Cron\CronJob\$schedule_type, ILIAS\Cron\CronJob\hasFlexibleSchedule(), and null.

Referenced by CronJobScheduleTest\testWeeklySchedules().

156  : ?JobScheduleType
157  {
158  if ($this->schedule_type && $this->hasFlexibleSchedule()) {
159  return $this->schedule_type;
160  }
161 
162  return null;
163  }
JobScheduleType $schedule_type
Definition: CronJob.php:28
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getScheduleTypesWithValues()

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

Definition at line 204 of file CronJob.php.

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

204  : array
205  {
206  return [
207  JobScheduleType::IN_MINUTES,
208  JobScheduleType::IN_HOURS,
209  JobScheduleType::IN_DAYS,
210  ];
211  }
+ 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.

References ILIAS\Cron\CronJob\$schedule_value, ILIAS\Cron\CronJob\hasFlexibleSchedule(), and null.

Referenced by CronJobScheduleTest\testWeeklySchedules().

168  : ?int
169  {
170  if ($this->schedule_value && $this->hasFlexibleSchedule()) {
171  return $this->schedule_value;
172  }
173 
174  return null;
175  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTitle()

ILIAS\Cron\CronJob::getTitle ( )
abstract

◆ getValidScheduleTypes()

ILIAS\Cron\CronJob::getValidScheduleTypes ( )

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

Returns
list<JobScheduleType>

Definition at line 217 of file CronJob.php.

References ILIAS\Cron\CronJob\getAllScheduleTypes().

Referenced by ilCronManagerGUI\initEditForm(), ilCronManagerGUI\initLegacyEditForm(), and ILIAS\Cron\CronJob\setSchedule().

217  : array
218  {
219  return $this->getAllScheduleTypes();
220  }
getAllScheduleTypes()
Get all available schedule types.
Definition: CronJob.php:196
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasAutoActivation()

ILIAS\Cron\CronJob::hasAutoActivation ( )
abstract

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

Referenced by ILIAS\Cron\CronJob\activationWasToggled().

+ Here is the caller graph for this function:

◆ hasCustomSettings()

ILIAS\Cron\CronJob::hasCustomSettings ( )

Definition at line 227 of file CronJob.php.

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

227  : bool
228  {
229  return false;
230  }
+ Here is the caller graph for this function:

◆ 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.

References ILIAS\Cron\CronJob\checkSchedule(), ILIAS\Cron\CronJob\getDefaultScheduleType(), ILIAS\Cron\CronJob\getDefaultScheduleValue(), and ILIAS\Cron\CronJob\hasFlexibleSchedule().

Referenced by CronJobScheduleTest\testSchedule(), and CronJobScheduleTest\testWeeklySchedules().

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  }
JobScheduleType $schedule_type
Definition: CronJob.php:28
checkSchedule(?\DateTimeImmutable $last_run, ?JobScheduleType $schedule_type, ?int $schedule_value)
Definition: CronJob.php:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isManuallyExecutable()

ILIAS\Cron\CronJob::isManuallyExecutable ( )

Definition at line 222 of file CronJob.php.

Referenced by ilCronManagerGUI\confirm().

222  : bool
223  {
224  return true;
225  }
+ Here is the caller graph for this function:

◆ run()

ILIAS\Cron\CronJob::run ( )
abstract

Referenced by ILIAS\Cron\CronJob\activationWasToggled().

+ Here is the caller graph for this function:

◆ saveCustomConfiguration()

ILIAS\Cron\CronJob::saveCustomConfiguration ( mixed  $form_data)
Parameters
mixed$form_dataThe form data provided by the KS (::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.

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

Definition at line 105 of file CronJob.php.

References ILIAS\Cron\CronJob\$date_time_provider, $r, and null.

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  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Closure $date_time_provider
Definition: CronJob.php:30
$r

◆ setSchedule()

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

Update current schedule (if flexible)

Definition at line 180 of file CronJob.php.

References ILIAS\Cron\CronJob\getValidScheduleTypes(), and ILIAS\Cron\CronJob\hasFlexibleSchedule().

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
+ Here is the call graph for this function:

◆ usesLegacyForms()

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

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

◆ $schedule_type

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

Definition at line 28 of file CronJob.php.

Referenced by ILIAS\Cron\CronJob\getScheduleType().

◆ $schedule_value

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

Definition at line 29 of file CronJob.php.

Referenced by ILIAS\Cron\CronJob\getScheduleValue().


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