diff options
Diffstat (limited to 'modules-available')
-rw-r--r-- | modules-available/locationinfo/inc/coursebackend.inc.php | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php index fc03671c..6e4d77ac 100644 --- a/modules-available/locationinfo/inc/coursebackend.inc.php +++ b/modules-available/locationinfo/inc/coursebackend.inc.php @@ -196,13 +196,12 @@ abstract class CourseBackend $returnValue = []; $remoteIds = []; while ($row = $dbquery1->fetch(PDO::FETCH_ASSOC)) { - //Check if in cache if lastUpdate is null then it is interpreted as 1970 - if ($row['lastcalendarupdate'] + $this->getCacheTime() > $NOW) { - $returnValue[$row['locationid']] = json_decode($row['calendar']); - } else { + // Check if in cache - if lastUpdate is null then it is interpreted as 1970 + if ($row['lastcalendarupdate'] + $this->getCacheTime() < $NOW) { $remoteIds[$row['locationid']] = $row['serverlocationid']; } - + // Always add to return value - if updating fails, we better use the stale data than nothing + $returnValue[$row['locationid']] = json_decode($row['calendar'], true); } // No need for additional round trips to backend if (empty($remoteIds)) { @@ -234,7 +233,7 @@ abstract class CourseBackend // if, nothing bad will happen... Database::exec("UPDATE locationinfo_locationconfig SET lastcalendarupdate = :time WHERE lastcalendarupdate < :time AND serverid = :serverid AND serverlocationid IN (:slocs)", [ - 'time' => $NOW - $this->getCacheTime() / 2, + 'time' => $NOW - ($this->getCacheTime() - 60), // Protect for one minute max. 'serverid' => $this->serverId, 'slocs' => array_values($remoteIds), ]); @@ -266,15 +265,15 @@ abstract class CourseBackend 'serverid' => $this->serverId, 'serverlocationid' => $serverRoomId, 'ttable' => $value, - 'now' => $NOW + 'now' => $NOW, // Set real "lastupdate" here )); } - - unset($calendar); } + unset($calendar); // Add rooms that were requested to the final return value foreach ($remoteIds as $location => $serverRoomId) { - if (isset($backendResponse[$serverRoomId]) && in_array($location, $requestedLocationIds)) { + if (isset($backendResponse[$serverRoomId]) && is_array($backendResponse[$serverRoomId]) + && in_array($location, $requestedLocationIds)) { // Only add if we can map it back to our location id AND it was not an unsolicited coalesced refresh $returnValue[$location] = $backendResponse[$serverRoomId]; } |