summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo
diff options
context:
space:
mode:
authorSimon Rettberg2017-12-19 12:19:20 +0100
committerSimon Rettberg2017-12-19 12:19:20 +0100
commite19fd43bd5982d15b6dd65261035f961e4560656 (patch)
treee9cc96dd9c44f545de193d76b5e3f045e10b13fb /modules-available/locationinfo
parent[sysconfig] Fix logic by which condition the LDADPd gets (re)started (diff)
downloadslx-admin-e19fd43bd5982d15b6dd65261035f961e4560656.tar.gz
slx-admin-e19fd43bd5982d15b6dd65261035f961e4560656.tar.xz
slx-admin-e19fd43bd5982d15b6dd65261035f961e4560656.zip
[locationinfo] Reload panels when opening times are changed
Diffstat (limited to 'modules-available/locationinfo')
-rw-r--r--modules-available/locationinfo/api.inc.php26
-rw-r--r--modules-available/locationinfo/page.inc.php79
-rw-r--r--modules-available/locationinfo/templates/page-locations.html6
3 files changed, 82 insertions, 29 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index ceaf04c0..ad71de8b 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -49,15 +49,11 @@ function HandleParameters()
/**
* Get last config modification timestamp for given panel.
- * This was planned to be smart and check the involved locations,
- * even going up the location tree if the opening time schedule
- * is inherited, but this would still be incomplete by design, as
- * it wouldn't react to the linked room plan being considered
- * for changes, or added/removed PCs etc. So rather than giving
- * an incomplete "clever" design for detecting changes, we only
- * consider direct editing of the panel now. So the advice would
- * simply be "if you want the panel to reload automatically, hit
- * the edit button and click save". Might even add a shortcut
+ * This is incomplete however, as it wouldn't react to the
+ * linked room plan being edited, or added/removed PCs
+ * etc. So the advice would simply be "if you want the
+ * panel to reload automatically, hit the edit button
+ * and click save". Might even add a shortcut
* reload-button to the list of panels at some point.
*
* @param string $paneluuid panels uuid
@@ -65,13 +61,21 @@ function HandleParameters()
*/
function getLastChangeTs($paneluuid)
{
- $panel = Database::queryFirst('SELECT lastchange FROM locationinfo_panel WHERE paneluuid = :paneluuid',
+ $panel = Database::queryFirst('SELECT lastchange, locationids FROM locationinfo_panel WHERE paneluuid = :paneluuid',
compact('paneluuid'));
if ($panel === false) {
http_response_code(404);
die('Panel not found');
}
- return (int)$panel['lastchange'];
+ $lastChange = array((int)$panel['lastchange']);
+ if (!empty($panel['locationids'])) {
+ $res = Database::simpleQuery('SELECT lastchange FROM locationinfo_locationconfig
+ WHERE locationid IN (:locs)', array('locs' => explode(',', $panel['locationids'])));
+ while (($lc = $res->fetchColumn()) !== false) {
+ $lastChange[] = (int)$lc;
+ }
+ }
+ return max($lastChange);
}
/**
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index d4a2b35e..22a21951 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -129,8 +129,8 @@ class Page_LocationInfo extends Page
}
$serverlocationid = Request::post('serverlocationid', '', 'string');
- $recursive = (Request::post('recursive', '', 'string') !== '');
- if (empty($serverlocationid) && !$recursive) {
+ $changeServerRecursive = (Request::post('recursive', '', 'string') !== '');
+ if (empty($serverlocationid) && !$changeServerRecursive) {
$insertServerId = null;
$ignoreServer = 1;
} else {
@@ -170,12 +170,16 @@ class Page_LocationInfo extends Page
$mangled[] = $entry;
}
if (empty($mangled)) {
- $openingtimes = '';
+ $openingtimes = null;
} else {
$openingtimes = json_encode($mangled);
}
}
}
+ $NOW = time();
+ // Check if openingtimes changed
+ $res = Database::queryFirst('SELECT openingtime FROM locationinfo_locationconfig WHERE locationid = :locationid', compact('locationid'));
+ $otChanged = $res === false || $res['openingtime'] !== $openingtimes;
Database::exec("INSERT INTO `locationinfo_locationconfig` (locationid, serverid, serverlocationid, openingtime, lastcalendarupdate, lastchange)
VALUES (:id, :insertserverid, :serverlocationid, :openingtimes, 0, :now)
@@ -187,27 +191,66 @@ class Page_LocationInfo extends Page
'openingtimes' => $openingtimes,
'serverlocationid' => $serverlocationid,
'ignore_server' => $ignoreServer,
- 'now' => time(),
+ 'now' => $NOW,
));
- if (!$recursive)
- return true;
-
- // Recursive overwriting of serverid
- $children = Location::getRecursiveFlat($locationid);
- $array = array();
- foreach ($children as $loc) {
- $array[] = $loc['locationid'];
+ if ($otChanged) {
+ $tree = Location::getLocationsAssoc();
+ $todo = array();
+ $done = array();
+ foreach ($tree as $l) {
+ if ($l['parentlocationid'] == $locationid) {
+ $todo[] = $l['locationid'];
+ }
+ }
+ while (!empty($todo)) {
+ $loc = array_pop($todo);
+ if (in_array($loc, $done))
+ continue;
+ $done[] = $loc;
+ // See if this one inherits
+ $res = Database::queryFirst('SELECT openingtime FROM locationinfo_locationconfig WHERE locationid = :loc', compact('loc'));
+ if ($res === false) {
+ $res = Database::exec('INSERT INTO locationinfo_locationconfig (locationid, lastchange)
+ VALUES (:locationid, :now) ON DUPLICATE KEY UPDATE lastchange = :now',
+ array('locationid' => $loc, 'now' => $NOW));
+ } elseif (strlen($res['openingtime']) < 5) {
+ $res = Database::exec('UPDATE locationinfo_locationconfig SET lastchange = :now, openingtime = NULL
+ WHERE locationid = :locationid',
+ array('locationid' => $loc, 'now' => $NOW));
+ } else {
+ $res = 0;
+ }
+ if ($res > 0) {
+ // Row was updated, which means the openingtime column was empty, which means the openingtime is inherited, descend further
+ $todo = array_merge($todo, $tree[$loc]['children']);
+ foreach ($tree as $l) {
+ if ($l['parentlocationid'] == $loc) {
+ $todo[] = $l['locationid'];
+ }
+ }
+ }
+ }
}
- if (!empty($array)) {
- Database::exec("UPDATE locationinfo_locationconfig
+
+ if ($changeServerRecursive) {
+ // Recursive overwriting of serverid
+ $children = Location::getRecursiveFlat($locationid);
+ $array = array();
+ foreach ($children as $loc) {
+ $array[] = $loc['locationid'];
+ }
+ if (!empty($array)) {
+ Database::exec("UPDATE locationinfo_locationconfig
SET serverid = :serverid, lastcalendarupdate = IF(serverid <> :serverid, 0, lastcalendarupdate), lastchange = :now
WHERE locationid IN (:locations)", array(
'serverid' => $serverid,
'locations' => $array,
- 'now' => time(),
- ));
+ 'now' => $NOW,
+ ));
+ }
}
+
return true;
}
@@ -465,7 +508,7 @@ class Page_LocationInfo extends Page
$locations[$locid] += array(
'openingGlyph' => $glyph,
'backend' => $backend,
- 'lastCalendarUpdate' => $row['lastcalendarupdate'], // TODO
+ 'lastCalendarUpdate' => Util::prettyTime($row['lastcalendarupdate']), // TODO
'backendMissing' => !CourseBackend::exists($row['servertype']),
);
}
@@ -478,8 +521,8 @@ class Page_LocationInfo extends Page
$depth--;
}
while ($location['depth'] > $depth) {
+ array_push($stack, empty($location['openingGlyph']) && ($depth === -1 || empty($stack[$depth])) ? '' : 'arrow-up');
$depth++;
- array_push($stack, empty($location['openingGlyph']) ? '' : 'arrow-up');
}
if ($depth > 0 && empty($location['openingGlyph'])) {
$location['openingGlyph'] = $stack[$depth - 1];
diff --git a/modules-available/locationinfo/templates/page-locations.html b/modules-available/locationinfo/templates/page-locations.html
index de8dab7e..df760940 100644
--- a/modules-available/locationinfo/templates/page-locations.html
+++ b/modules-available/locationinfo/templates/page-locations.html
@@ -7,6 +7,7 @@
<tr>
<th>{{lang_locationName}}</th>
<th>{{lang_backend}}</th>
+ <th>{{lang_lastUpdate}}</th>
<th>{{lang_openingtimes}}</th>
</tr>
</thead>
@@ -25,6 +26,11 @@
{{backend}}
</td>
<td>
+ {{#backend}}
+ {{lastCalendarUpdate}}
+ {{/backend}}
+ </td>
+ <td>
<span class="glyphicon glyphicon-{{openingGlyph}}"></span>
</td>
</tr>