19declare(strict_types=1);
48 if (strpos(
$id,
'pl__') === 0) {
53 foreach ($this->componentRepository->getPlugins() as $pl) {
54 if ($pl->getName() !== $pl_name || !$pl->isActive()) {
58 $plugin = $this->componentFactory->getPlugin($pl->getId());
64 $job =
$plugin->getCronJobInstance($job_id);
68 if ($jobs_data === []) {
74 }
catch (OutOfBoundsException
$e) {
81 if ($jobs_data !== [] && $jobs_data[0][
'job_id'] ===
$id) {
83 $jobs_data[0][
'job_id'],
84 $jobs_data[0][
'component'],
85 $jobs_data[0][
'class']
90 $this->
logger->info(
'CRON - job ' . $id .
' seems invalid or is inactive');
99 bool $isCreationContext =
false
101 if (class_exists($a_class)) {
102 if ($isCreationContext) {
103 $refl =
new ReflectionClass($a_class);
104 $job = $refl->newInstanceWithoutConstructor();
106 $job =
new $a_class();
127 if (
$id && !is_array(
$id)) {
131 $query =
"SELECT * FROM cron_job";
134 $where[] = $this->db->in(
'job_id',
$id,
false,
'text');
136 $where[] =
'class != ' . $this->db->quote(self::TYPE_PLUGINS,
'text');
138 if (!$withInactiveJobsIncluded) {
139 $where[] =
'job_status = ' . $this->db->quote(1,
'integer');
142 $query .=
' WHERE ' . implode(
' AND ', $where);
145 $query .=
' ORDER BY job_id';
148 while ($row = $this->db->fetchAssoc(
$res)) {
161 if (!$this->db->tableExists(
'cron_job')) {
165 $job = $this->getJobInstance($a_id, $a_component, $a_class,
true);
167 $this->createDefaultEntry($job, $a_component, $a_class, $a_path);
171 public function unregisterJob(
string $a_component, array $a_xml_job_ids): void
173 if (!$this->db->tableExists(
'cron_job')) {
178 $query =
'SELECT job_id FROM cron_job WHERE component = ' . $this->db->quote($a_component,
'text');
180 while ($row = $this->db->fetchAssoc(
$res)) {
181 $jobs[] = $row[
'job_id'];
185 if ($a_xml_job_ids !== []) {
186 foreach ($jobs as $job_id) {
187 if (!in_array($job_id, $a_xml_job_ids,
true)) {
188 $this->db->manipulate(
189 'DELETE FROM cron_job' .
190 ' WHERE component = ' . $this->db->quote($a_component,
'text') .
191 ' AND job_id = ' . $this->db->quote($job_id,
'text')
196 $this->db->manipulate(
'DELETE FROM cron_job WHERE component = ' . $this->db->quote($a_component,
'text'));
207 $query =
"SELECT job_id, schedule_type, component, class, path FROM cron_job" .
208 " WHERE job_id = " . $this->db->quote($job->
getId(),
"text");
210 $row = $this->db->fetchAssoc(
$res);
211 $job_id = $row[
'job_id'] ??
null;
212 $job_exists = ($job_id === $job->
getId());
213 $schedule_type = $row[
"schedule_type"] ??
null;
217 $row[
'component'] !== $component ||
218 $row[
'class'] !== $class ||
219 $row[
'path'] !==
$path
222 $this->db->manipulateF(
223 'UPDATE cron_job SET component = %s, class = %s, path = %s WHERE job_id = %s',
224 [
'text',
'text',
'text',
'text'],
231 $query =
'INSERT INTO cron_job (job_id, component, class, path)' .
232 ' VALUES (' . $this->db->quote($job->
getId(),
'text') .
', ' .
233 $this->db->quote($component,
'text') .
', ' .
234 $this->db->quote($class,
'text') .
', ' .
235 $this->db->quote(
$path,
'text') .
')';
236 $this->db->manipulate(
$query);
238 $this->
logger->info(
'Cron XML - Job ' . $job->
getId() .
' in class ' . $class .
' added.');
241 $this->updateJobSchedule(
248 $this->activateJob($job,
new DateTimeImmutable(
'@' . time()));
256 $this->updateJobSchedule(
263 $this->updateJobSchedule($job,
null,
null);
274 foreach ($this->componentRepository->getPlugins() as $pl) {
275 if (!$pl->isActive()) {
279 $plugin = $this->componentFactory->getPlugin($pl->getId());
285 foreach (
$plugin->getCronJobInstances() as $job) {
286 $jobs_data = $this->getCronJobData($job->getId());
287 $job_data = $jobs_data[0] ??
null;
288 if (!is_array($job_data) || $job_data === []) {
290 $this->createDefaultEntry($job,
$plugin->getPluginName(), self::TYPE_PLUGINS,
'');
293 $jobs_data = $this->getCronJobData($job->getId());
294 $job_data = $jobs_data[0];
297 if (!$withOnlyActive || (
int) $job_data[
'job_status'] === 1) {
298 $res[$job->getId()] = [$job, $job_data];
308 $this->db->manipulate(
'UPDATE cron_job' .
309 ' SET running_ts = ' . $this->db->quote(0,
'integer') .
310 ' , alive_ts = ' . $this->db->quote(0,
'integer') .
311 ' , job_result_ts = ' . $this->db->quote(0,
'integer') .
312 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text'));
317 DateTimeImmutable $when,
320 bool $wasManualExecution =
false
322 $user_id = $wasManualExecution ? $actor->
getId() : 0;
324 $query =
'UPDATE cron_job SET ' .
325 ' job_result_status = ' . $this->db->quote($result->
getStatus(),
'integer') .
326 ' , job_result_user_id = ' . $this->db->quote($user_id,
'integer') .
327 ' , job_result_code = ' . $this->db->quote($result->
getCode(),
'text') .
328 ' , job_result_message = ' . $this->db->quote($result->
getMessage(),
'text') .
329 ' , job_result_type = ' . $this->db->quote((
int) $wasManualExecution,
'integer') .
330 ' , job_result_ts = ' . $this->db->quote($when->getTimestamp(),
'integer') .
331 ' , job_result_dur = ' . $this->db->quote($result->
getDuration() * 1000,
'integer') .
332 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text');
333 $this->db->manipulate(
$query);
338 $this->db->manipulate(
'UPDATE cron_job SET' .
339 ' running_ts = ' . $this->db->quote($runningTimestamp,
'integer') .
340 ' , alive_ts = ' . $this->db->quote($aliveTimestamp,
'integer') .
341 ' WHERE job_id = ' . $this->db->quote($jobId,
'text'));
347 $scheduleType ===
null ||
350 $query =
'UPDATE cron_job SET ' .
351 ' schedule_type = ' . $this->db->quote($scheduleType,
'integer') .
352 ' , schedule_value = ' . $this->db->quote($scheduleValue,
'integer') .
353 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text');
354 $this->db->manipulate(
$query);
360 DateTimeImmutable $when,
362 bool $wasManuallyExecuted =
false
365 if ($wasManuallyExecuted && $actor instanceof
ilObjUser) {
366 $usrId = $actor->
getId();
369 $query =
'UPDATE cron_job SET ' .
370 ' job_status = ' . $this->db->quote(1,
'integer') .
371 ' , job_status_user_id = ' . $this->db->quote($usrId,
'integer') .
372 ' , job_status_type = ' . $this->db->quote($wasManuallyExecuted,
'integer') .
373 ' , job_status_ts = ' . $this->db->quote($when->getTimestamp(),
'integer') .
374 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text');
375 $this->db->manipulate(
$query);
380 DateTimeImmutable $when,
382 bool $wasManuallyExecuted =
false
384 $usrId = $wasManuallyExecuted ? $actor->
getId() : 0;
386 $query =
'UPDATE cron_job SET ' .
387 ' job_status = ' . $this->db->quote(0,
'integer') .
388 ' , job_result_status = ' . $this->db->quote(
null,
'text') .
389 ' , job_result_message = ' . $this->db->quote(
null,
'text') .
390 ' , job_result_type = ' . $this->db->quote(
null,
'text') .
391 ' , job_result_code = ' . $this->db->quote(
null,
'text') .
392 ' , job_status_user_id = ' . $this->db->quote($usrId,
'integer') .
393 ' , job_status_type = ' . $this->db->quote($wasManuallyExecuted,
'integer') .
394 ' , job_status_ts = ' . $this->db->quote($when->getTimestamp(),
'integer') .
395 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text');
396 $this->db->manipulate(
$query);
403 foreach ($this->getCronJobData() as $item) {
404 $job = $this->getJobInstance(
414 foreach ($this->getPluginJobs() as $item) {
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
unregisterJob(string $a_component, array $a_xml_job_ids)
getJobInstanceById(string $id)
getJobInstance(string $a_id, string $a_component, string $a_class, bool $isCreationContext=false)
getCronJobData($id=null, bool $withInactiveJobsIncluded=true)
Get cron job configuration/execution data.
activateJob(ilCronJob $job, DateTimeImmutable $when, ?ilObjUser $actor=null, bool $wasManuallyExecuted=false)
updateJobResult(ilCronJob $job, DateTimeImmutable $when, ilObjUser $actor, ilCronJobResult $result, bool $wasManualExecution=false)
registerJob(string $a_component, string $a_id, string $a_class, ?string $a_path)
updateRunInformation(string $jobId, int $runningTimestamp, int $aliveTimestamp)
updateJobSchedule(ilCronJob $job, ?int $scheduleType, ?int $scheduleValue)
deactivateJob(ilCronJob $job, DateTimeImmutable $when, ilObjUser $actor, bool $wasManuallyExecuted=false)
__construct(ilDBInterface $db, ilSetting $setting, ilLogger $logger, ilComponentRepository $componentRepository, ilComponentFactory $componentFactory)
ilComponentFactory $componentFactory
createDefaultEntry(ilCronJob $job, string $component, string $class, ?string $path)
ilComponentRepository $componentRepository
getPluginJobs(bool $withOnlyActive=false)
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...
getDefaultScheduleValue()
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
getValidScheduleTypes()
Returns a collection of all valid schedule types for a specific job.
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Readable part of repository interface to ilComponentDataDB.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts