19declare(strict_types=1);
34 if ($last_run > $now) {
40 return $last_run->format(
'o-W') !== $now->format(
'o-W');
44 ?\DateTimeImmutable $last_run,
52 if (
null === $last_run) {
56 if ($this->date_time_provider ===
null) {
57 $now = new \DateTimeImmutable(
'@' . time(),
new \DateTimeZone(date_default_timezone_get()));
63 case JobScheduleType::DAILY:
64 $last = $last_run->format(
'Y-m-d');
65 $ref = $now->format(
'Y-m-d');
66 return ($last !== $ref);
68 case JobScheduleType::WEEKLY:
71 case JobScheduleType::MONTHLY:
72 $last = $last_run->format(
'Y-n');
73 $ref = $now->format(
'Y-n');
74 return ($last !== $ref);
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);
82 $last = $last_run->format(
'Y');
83 $ref = $now->format(
'Y');
84 return ($last !== $ref);
86 case JobScheduleType::IN_MINUTES:
87 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / 60);
90 case JobScheduleType::IN_HOURS:
91 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60));
94 case JobScheduleType::IN_DAYS:
95 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60 * 24));
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();
113 $expected_type = \DateTimeInterface::class;
114 if (!is_subclass_of($return_type, $expected_type)) {
115 throw new \InvalidArgumentException(
117 'The return type of the datetime provider must be of type %s',
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',
132 $this->date_time_provider = $date_time_provider;
136 ?\DateTimeImmutable $last_run,
138 ?
int $schedule_value,
139 bool $is_manually_executed =
false
141 if ($is_manually_executed) {
145 if (!$this->hasFlexibleSchedule()) {
146 $schedule_type = $this->getDefaultScheduleType();
147 $schedule_value = $this->getDefaultScheduleValue();
150 return $this->checkSchedule($last_run, $schedule_type, $schedule_value);
158 if ($this->schedule_type && $this->hasFlexibleSchedule()) {
159 return $this->schedule_type;
170 if ($this->schedule_value && $this->hasFlexibleSchedule()) {
171 return $this->schedule_value;
184 $this->hasFlexibleSchedule() &&
185 \in_array($a_type, $this->getValidScheduleTypes(),
true)
187 $this->schedule_type = $a_type;
188 $this->schedule_value = $a_value;
198 return JobScheduleType::cases();
207 JobScheduleType::IN_MINUTES,
208 JobScheduleType::IN_HOURS,
209 JobScheduleType::IN_DAYS,
219 return $this->getAllScheduleTypes();
235 #[\Deprecated('Will be removed without any alternative, KS/UI forms will be expected', since: '13.0')]
246 throw new \RuntimeException(
'Not implemented');
252 #[\Deprecated('Will be removed without any alternative, KS/UI forms will be expected', since: '13.0')]
264 throw new \RuntimeException(
'Not implemented');
270 #[\Deprecated('Will be removed without any alternative, KS/UI forms will be expected', since: '13.0')]
291 abstract public function getId(): string;
getScheduleType()
Get current schedule type (if flexible)
checkSchedule(?\DateTimeImmutable $last_run, ?JobScheduleType $schedule_type, ?int $schedule_value)
getDefaultScheduleValue()
isDue(?\DateTimeImmutable $last_run, ?JobScheduleType $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
getCustomConfigurationInput(\ILIAS\UI\Factory $ui_factory, \ILIAS\Refinery\Factory $factory, \ilLanguage $lng)
Closure $date_time_provider
setDateTimeProvider(?\Closure $date_time_provider)
saveCustomConfiguration(mixed $form_data)
setSchedule(?JobScheduleType $a_type, ?int $a_value)
Update current schedule (if flexible)
JobScheduleType $schedule_type
getAllScheduleTypes()
Get all available schedule types.
getScheduleTypesWithValues()
getValidScheduleTypes()
Returns a collection of all valid schedule types for a specific job.
addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active)
getScheduleValue()
Get current schedule value (if flexible)
addCustomSettingsToForm(\ilPropertyFormGUI $a_form)
saveCustomSettings(\ilPropertyFormGUI $a_form)
checkWeeklySchedule(\DateTimeImmutable $last_run, \DateTimeImmutable $now)
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...
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
Builds a Color from either hex- or rgb values.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))