ILIAS  release_8 Revision v8.24
class.ilCalendarCronRemoteReader.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 private const DEFAULT_SYNC_HOURS = 1;
24
27
29
30 public function __construct()
31 {
32 global $DIC;
33
34 $this->lng = $DIC->language();
35 $this->logger = $DIC->logger()->cal();
36 $this->calendar_settings = ilCalendarSettings::_getInstance();
37 }
38
39 public function getId(): string
40 {
41 return 'cal_remote_reader';
42 }
43
44 public function getTitle(): string
45 {
46 $this->lng->loadLanguageModule('dateplaner');
47 return $this->lng->txt('cal_cronjob_remote_title');
48 }
49
50 public function getDescription(): string
51 {
52 $this->lng->loadLanguageModule('dateplaner');
53 return $this->lng->txt('cal_cronjob_remote_description');
54 }
55
56 public function hasAutoActivation(): bool
57 {
58 return false;
59 }
60
61 public function hasFlexibleSchedule(): bool
62 {
63 return true;
64 }
65
66 public function addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active): void
67 {
68 switch ($a_form_id) {
70 $a_fields['cal_webcal_sync'] = $a_is_active ?
71 $this->lng->txt('enabled') :
72 $this->lng->txt('disabled');
73 break;
74 }
75 }
76
77 public function hasCustomSettings(): bool
78 {
79 return true;
80 }
81
82 public function getDefaultScheduleType(): int
83 {
85 }
86
87 public function getDefaultScheduleValue(): ?int
88 {
89 if ($this->calendar_settings === null) {
91 }
92 return $this->calendar_settings->getWebCalSyncHours();
93 }
94
95 public function run(): ilCronJobResult
96 {
98
99 $counter = 0;
100 foreach (ilCalendarCategories::lookupRemoteCalendars() as $remoteCalendar) {
102
103 $reader = new ilCalendarRemoteReader($remoteCalendar->getRemoteUrl());
104 $reader->setUser($remoteCalendar->getRemoteUser());
105 $reader->setPass($remoteCalendar->getRemotePass());
106 try {
107 $reader->read();
108 $reader->import($remoteCalendar);
109 } catch (Exception $e) {
110 $this->logger->warning('Remote Calendar: ' . $remoteCalendar->getCategoryID());
111 $this->logger->warning('Reading remote calendar failed with message: ' . $e->getMessage());
112 }
113 $remoteCalendar->setRemoteSyncLastExecution(new ilDateTime(time(), IL_CAL_UNIX));
114 $remoteCalendar->update();
116 ++$counter;
117 }
118 $result = new ilCronJobResult();
119 $result->setStatus($status);
120 return $result;
121 }
122
123
124}
const IL_CAL_UNIX
addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active)
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Stores all calendar relevant settings.
const SCHEDULE_TYPE_IN_HOURS
@depracated This will be replaced with an ENUM in ILIAS 9
@classDescription Date and time handling
language handling
Component logger with individual log levels by component id.
global $DIC
Definition: feed.php:28