From 5ec14bdb9dbd11ba7bae8bf737aa0e0dd637dc33 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 7 Nov 2017 12:50:30 +0100 Subject: [PATCH 1/3] Remove inheritdoc tags in AnnouncementIniRepository.php --- .../Web/Announcement/AnnouncementIniRepository.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/library/Icinga/Web/Announcement/AnnouncementIniRepository.php b/library/Icinga/Web/Announcement/AnnouncementIniRepository.php index c8ab5c8e8..7e01736e4 100644 --- a/library/Icinga/Web/Announcement/AnnouncementIniRepository.php +++ b/library/Icinga/Web/Announcement/AnnouncementIniRepository.php @@ -16,27 +16,15 @@ use Icinga\Web\Announcement; */ class AnnouncementIniRepository extends IniRepository { - /** - * {@inheritdoc} - */ protected $queryColumns = array('announcement' => array('id', 'author', 'message', 'hash', 'start', 'end')); - /** - * {@inheritdoc} - */ protected $triggers = array('announcement'); - /** - * {@inheritDoc} - */ protected $configs = array('announcement' => array( 'name' => 'announcements', 'keyColumn' => 'id' )); - /** - * {@inheritDoc} - */ protected $conversionRules = array('announcement' => array( 'start' => 'timestamp', 'end' => 'timestamp' From 1f5f610b0436c73b6cc56914966f5d8700eb6a5f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 7 Nov 2017 14:48:46 +0100 Subject: [PATCH 2/3] Add newlines to AnnouncementIniRepository.php --- .../Web/Announcement/AnnouncementIniRepository.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/Icinga/Web/Announcement/AnnouncementIniRepository.php b/library/Icinga/Web/Announcement/AnnouncementIniRepository.php index 7e01736e4..ab49021be 100644 --- a/library/Icinga/Web/Announcement/AnnouncementIniRepository.php +++ b/library/Icinga/Web/Announcement/AnnouncementIniRepository.php @@ -42,8 +42,10 @@ class AnnouncementIniRepository extends IniRepository if ($timestamp !== null) { $dateTime = new DateTime(); $dateTime->setTimestamp($timestamp); + return $dateTime; } + return null; } @@ -71,6 +73,7 @@ class AnnouncementIniRepository extends IniRepository if (! isset($new->id)) { $new->id = uniqid(); } + if (! isset($new->hash)) { $announcement = new Announcement($new->toArray()); $new->hash = $announcement->getHash(); @@ -105,11 +108,14 @@ class AnnouncementIniRepository extends IniRepository public function getEtag() { $file = $this->getDataSource('announcement')->getConfigFile(); + if (@is_readable($file)) { $mtime = filemtime($file); $size = filesize($file); + return hash('crc32', $mtime . $size); } + return null; } @@ -121,6 +127,7 @@ class AnnouncementIniRepository extends IniRepository public function findActive() { $now = new DateTime(); + $query = $this ->select(array('hash', 'message')) ->setFilter(new FilterAnd(array( @@ -128,6 +135,7 @@ class AnnouncementIniRepository extends IniRepository Filter::expression('end', '>=', $now) ))) ->order('start'); + return $query; } @@ -139,20 +147,25 @@ class AnnouncementIniRepository extends IniRepository public function findNextActive() { $now = new DateTime(); + $query = $this ->select(array('start', 'end')) ->setFilter(Filter::matchAny(array( Filter::expression('start', '>', $now), Filter::expression('end', '>', $now) ))); + $refresh = null; + foreach ($query as $row) { $min = min($row->start->getTimestamp(), $row->end->getTimestamp()); + if ($refresh === null) { $refresh = $min; } else { $refresh = min($refresh, $min); } } + return $refresh; } } From cd05d00b6384e3bf937156500365c3e272a49e48 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 7 Nov 2017 17:03:14 +0100 Subject: [PATCH 3/3] Sort announcements descending by start time refs #2987 --- application/controllers/AnnouncementsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/AnnouncementsController.php b/application/controllers/AnnouncementsController.php index 458b9a40a..513d8efe7 100644 --- a/application/controllers/AnnouncementsController.php +++ b/application/controllers/AnnouncementsController.php @@ -30,7 +30,7 @@ class AnnouncementsController extends Controller $repo = new AnnouncementIniRepository(); $this->view->announcements = $repo ->select(array('id', 'author', 'message', 'start', 'end')) - ->order('start'); + ->order('start', 'DESC'); } /**