diff options
| author | Simon Rettberg | 2026-01-28 15:45:21 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2026-01-28 15:45:21 +0100 |
| commit | 153b4212c2d7e8c2edff52352f3cecd6038fb97c (patch) | |
| tree | d68b6923579c5c913cc8fc0c56f14001fc55f8f7 | |
| parent | [serversetup-bwlp-ipxe] Fix: Don't clear screen between menus (diff) | |
| download | slx-admin-153b4212c2d7e8c2edff52352f3cecd6038fb97c.tar.gz slx-admin-153b4212c2d7e8c2edff52352f3cecd6038fb97c.tar.xz slx-admin-153b4212c2d7e8c2edff52352f3cecd6038fb97c.zip | |
The hack introduced in 87686da817dfd349c9f89a01065f799408e29f10 to work
around HisInOne returning incomplete data in ical files is obsolete, now
that HisInOne seems to have fixed this bug.
| -rw-r--r-- | modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php | 71 | ||||
| -rw-r--r-- | modules-available/locationinfo/inc/icalcoursebackend.inc.php | 7 |
2 files changed, 7 insertions, 71 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php index d3487f32..a559af76 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php @@ -55,79 +55,16 @@ class CourseBackend_HisInOne extends ICalCourseBackend { if (!$this->isOK()) return false; - // Unfortunately, HisInOne returns an internal server error if you pass an invalid roomId. - // So we just try a bunch and see if anything works. Even if this fails, using - // the backend should work, given the URL is actually correct. + // Older HisInOne versions returned an internal server error if you pass an invalid roomId. + // Newer ones seem to return 200 OK with an empty ical file. Nevertheless, keep this attempt + // with trying random room ids, in case the behavior changes again in the future. foreach ([60, 100, 5, 10, 11, 12, 13, 14, 15, 50, 110, 200, 210, 250, 300, 333, 500, 1000, 2000] as $roomId) { - // Use parent as we don't care about the periodId shenanigans - if (parent::downloadIcal((string)$roomId, time() + 60) !== null) + if ($this->downloadIcal((string)$roomId, time() + 60) !== null) return true; } return false; } - protected function downloadIcal(string $roomId, ?int $deadline, ?string $appendToUrl = null, ?bool $limitRange = true): ?array - { - $events = parent::downloadIcal($roomId, $deadline, null, false); - if (empty($events)) - return $events; - $periodIds = []; - $finalEvents = []; - $dtStart = strtotime('-7 days'); - $dtEnd = strtotime('+7 days'); - foreach ($events as $event) { - if (isset($event->url) && preg_match('/[&?]periodId=([0-9]+)(&|$)/', $event->url, $out)) { - // Collect periodIds from URLs to find more lectures. While the HisInOne help says that the periodId - // parameter can simply be removed, this is not true. In practice, some lectures that take place even - // on the current day or week might not be returned in the resulting ical file, unless you the proper - // current periodId. BUT WAIT THERE'S MORE: Even with the current periodId, some lectures don't get - // returned, so we start brute-forcing semi-random periodIds, while at the same time discovering - // new ones from the returned calendars. - $periodId = (int)$out[1]; - for ($i = max($periodId - 2, 1); $i <= $periodId + 2; $i++) { - $periodIds[$i] = $i; - } - } - if (strtotime($event->dtstart) > $dtEnd || strtotime($event->dtend) < $dtStart) - continue; - $finalEvents[$this->hash($event)] = $event; - } - // Now re-query with all the periodIds we found - $dupCheck = []; - while (($periodId = array_pop($periodIds)) !== null) { - if (count($dupCheck) > 35) - break; - if (isset($dupCheck[$periodId])) - continue; - if ($deadline !== null && $deadline - time() <= 1) { - error_log("Timeout exceeded (" . count($finalEvents) . " events & " . count($dupCheck) . " periodIds) for $roomId"); - break; - } - $dupCheck[$periodId] = true; - $events = parent::downloadIcal($roomId, $deadline, '&periodId=' . $periodId, $limitRange); - if (empty($events)) - continue; - foreach ($events as $event) { - if (strtotime($event->dtstart) <= $dtEnd && strtotime($event->dtend) >= $dtStart) { - $finalEvents[$this->hash($event)] = $event; - } - // Collect more periodIds - if (isset($event->url) && preg_match('/[&?]periodId=([0-9]+)(&|$)/', $event->url, $out)) { - $newPeriodId = (int)$out[1]; - for ($i = max($newPeriodId - 2, 1); $i <= $newPeriodId + 2; $i++) { - $periodIds[$i] = $i; - } - } - } - } - return array_values($finalEvents); - } - - private function hash(ICalEvent $event): string - { - return md5($event->dtstart . $event->dtend . ($event->uid ?? $event->summary)); - } - public function getCacheTime(): int { return 40 * 60; diff --git a/modules-available/locationinfo/inc/icalcoursebackend.inc.php b/modules-available/locationinfo/inc/icalcoursebackend.inc.php index c9113ec6..493d0008 100644 --- a/modules-available/locationinfo/inc/icalcoursebackend.inc.php +++ b/modules-available/locationinfo/inc/icalcoursebackend.inc.php @@ -38,17 +38,16 @@ abstract class ICalCourseBackend extends CourseBackend * * @param string $roomId The ID of the room for which iCal data is to be downloaded. * @param ?int $deadline Optional deadline timestamp for the download operation. - * @param ?string $appendToUrl Optional appendage to the URL used for the download. * * @return ?ICalEvent[] An array of iCal events if successful, or null on failure. */ - protected function downloadIcal(string $roomId, ?int $deadline, ?string $appendToUrl = null, ?bool $limitRange = true): ?array + protected function downloadIcal(string $roomId, ?int $deadline): ?array { if (!$this->isOK()) return null; try { - $ical = new ICalParser($limitRange ? ['filterDaysBefore' => 7, 'filterDaysAfter' => 7] : []); + $ical = new ICalParser(['filterDaysBefore' => 7, 'filterDaysAfter' => 7]); } catch (Exception $e) { $this->addError('Error instantiating ICalParser: ' . $e->getMessage(), true); return null; @@ -70,7 +69,7 @@ abstract class ICalCourseBackend extends CourseBackend CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYHOST => $this->verifyHostname ? 2 : 0, CURLOPT_SSL_VERIFYPEER => $this->verifyCert ? 1 : 0, - CURLOPT_URL => str_replace('%ID%', $roomId, $this->location . ($appendToUrl ?? '')), + CURLOPT_URL => str_replace('%ID%', $roomId, $this->location), CURLOPT_TIMEOUT => min(20, $timeout), CURLOPT_CONNECTTIMEOUT => 4, ]; |
