From 057cb55b6bee16f74624776614216a5e9bcadae3 Mon Sep 17 00:00:00 2001 From: Mathias Petermann Date: Sun, 9 Apr 2023 12:34:11 +0200 Subject: [PATCH] Add update info to serverinfo api call Signed-off-by: Mathias Petermann --- lib/SystemStatistics.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index e415895e..03778a8a 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -56,6 +56,7 @@ public function getSystemStatistics(): array { $memoryUsage = $this->os->getMemory(); return [ 'version' => $this->config->getSystemValue('version'), + 'update' => $this->getServerUpdateInfo(), 'theme' => $this->config->getSystemValue('theme', 'none'), 'enable_avatars' => $this->config->getSystemValue('enable_avatars', true) ? 'yes' : 'no', 'enable_previews' => $this->config->getSystemValue('enable_previews', true) ? 'yes' : 'no', @@ -74,6 +75,28 @@ public function getSystemStatistics(): array { ]; } + /** + * Get info about server updates and last checked timestamp + * + * @return array information about core updates + */ + protected function getServerUpdateInfo(): array { + $updateInfo = [ + 'lastupdatedat' => (int) $this->config->getAppValue('core', 'lastupdatedat'), + 'available' => false, + ]; + + $lastUpdateResult = json_decode($this->config->getAppValue('core', 'lastupdateResult'), true); + if (is_array($lastUpdateResult)) { + $updateInfo['available'] = (count($lastUpdateResult) > 0); + if (array_key_exists('version', $lastUpdateResult)) { + $updateInfo['available_version'] = $lastUpdateResult['version']; + } + } + + return $updateInfo; + } + /** * Get some info about installed apps, including available updates. *