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