summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/inc/coursebackend
diff options
context:
space:
mode:
authorSimon Rettberg2026-01-28 15:45:21 +0100
committerSimon Rettberg2026-01-28 15:45:21 +0100
commit153b4212c2d7e8c2edff52352f3cecd6038fb97c (patch)
treed68b6923579c5c913cc8fc0c56f14001fc55f8f7 /modules-available/locationinfo/inc/coursebackend
parent[serversetup-bwlp-ipxe] Fix: Don't clear screen between menus (diff)
downloadslx-admin-master.tar.gz
slx-admin-master.tar.xz
slx-admin-master.zip
[locationinfo] Revert HisInOne calendar workaroundHEADmaster
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.
Diffstat (limited to 'modules-available/locationinfo/inc/coursebackend')
-rw-r--r--modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php71
1 files changed, 4 insertions, 67 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;