ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilCalendarCronRemoteReader.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
25  private const DEFAULT_SYNC_HOURS = 1;
26 
27  private ilLanguage $lng;
28  private ilLogger $logger;
29 
31 
32  public function __construct()
33  {
34  global $DIC;
35 
36  $this->lng = $DIC->language();
37  $this->logger = $DIC->logger()->cal();
38  $this->calendar_settings = ilCalendarSettings::_getInstance();
39  }
40 
41  public function getId(): string
42  {
43  return 'cal_remote_reader';
44  }
45 
46  public function getTitle(): string
47  {
48  $this->lng->loadLanguageModule('dateplaner');
49  return $this->lng->txt('cal_cronjob_remote_title');
50  }
51 
52  public function getDescription(): string
53  {
54  $this->lng->loadLanguageModule('dateplaner');
55  return $this->lng->txt('cal_cronjob_remote_description');
56  }
57 
58  public function hasAutoActivation(): bool
59  {
60  return false;
61  }
62 
63  public function hasFlexibleSchedule(): bool
64  {
65  return true;
66  }
67 
68  public function addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active): void
69  {
70  switch ($a_form_id) {
72  $a_fields['cal_webcal_sync'] = $a_is_active ?
73  $this->lng->txt('enabled') :
74  $this->lng->txt('disabled');
75  break;
76  }
77  }
78 
79  public function hasCustomSettings(): bool
80  {
81  return true;
82  }
83 
85  {
86  return \ILIAS\Cron\Schedule\CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES;
87  }
88 
89  public function getDefaultScheduleValue(): ?int
90  {
91  if ($this->calendar_settings === null) {
92  return self::DEFAULT_SYNC_HOURS;
93  }
94  return $this->calendar_settings->getWebCalSyncHours();
95  }
96 
97  public function run(): ilCronJobResult
98  {
100 
101  $counter = 0;
102  foreach (ilCalendarCategories::lookupRemoteCalendars() as $remoteCalendar) {
104 
105  $reader = new ilCalendarRemoteReader($remoteCalendar->getRemoteUrl());
106  $reader->setUser($remoteCalendar->getRemoteUser());
107  $reader->setPass($remoteCalendar->getRemotePass());
108  try {
109  $reader->read();
110  $reader->import($remoteCalendar);
111  } catch (Exception $e) {
112  $this->logger->warning('Remote Calendar: ' . $remoteCalendar->getCategoryID());
113  $this->logger->warning('Reading remote calendar failed with message: ' . $e->getMessage());
114  }
115  $remoteCalendar->setRemoteSyncLastExecution(new ilDateTime(time(), IL_CAL_UNIX));
116  $remoteCalendar->update();
117  $status = ilCronJobResult::STATUS_OK;
118  ++$counter;
119  }
120  $result = new ilCronJobResult();
121  $result->setStatus($status);
122  return $result;
123  }
124 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_UNIX
final const STATUS_NO_ACTION
global $DIC
Definition: shib_login.php:25
addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active)