[icinga-checkins] icinga.org: icingaweb2/feature/announce-banner-11198: Collect all announcements provided by hooks and persist them

git at icinga.org git at icinga.org
Thu Nov 3 11:56:06 CET 2016


Module: icingaweb2
Branch: feature/announce-banner-11198
Commit: 6489dbfd45424e004ed20c38ba40d0e648a4ed53
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=6489dbfd45424e004ed20c38ba40d0e648a4ed53

Author: Alexander A. Klimov <alexander.klimov at icinga.com>
Date:   Thu Nov  3 11:31:55 2016 +0100

Collect all announcements provided by hooks and persist them

refs #11198

---

 library/Icinga/Application/Web.php |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php
index c199881..c1de56f 100644
--- a/library/Icinga/Application/Web.php
+++ b/library/Icinga/Application/Web.php
@@ -6,9 +6,11 @@ namespace Icinga\Application;
 require_once __DIR__ . '/EmbeddedWeb.php';
 
 use DateTime;
+use Icinga\Application\Hook\AnnouncementHook;
 use Icinga\Data\Filter\Filter;
 use Icinga\Data\Filter\FilterAnd;
 use Icinga\Repository\AnnouncementIniRepository;
+use Icinga\Web\Announcement;
 use Zend_Controller_Action_HelperBroker;
 use Zend_Controller_Front;
 use Zend_Controller_Router_Route;
@@ -101,6 +103,7 @@ class Web extends EmbeddedWeb
             ->setupTimezone()
             ->setupLogger()
             ->setupInternationalization()
+            ->collectAnnouncements()
             ->showAnnouncements();
     }
 
@@ -588,4 +591,33 @@ class Web extends EmbeddedWeb
 
         return $this;
     }
+
+    /**
+     * Collect all new announcements provided by hooks and persist them
+     *
+     * @return $this
+     */
+    protected function collectAnnouncements()
+    {
+        $announcements = array();
+        foreach (Hook::all('Announcement') as $hook) {
+            /** @var AnnouncementHook $hook */
+            foreach ($hook->getAnnouncements() as $announcement) {
+                $announcements[] = $announcement;
+            }
+        }
+
+        $repo = new AnnouncementIniRepository();
+        foreach ($announcements as $announcement) {
+            /** @var Announcement $announcement */
+            $repo->insert('announcement', array(
+                'author'    => $announcement->getAuthor(),
+                'message'   => $announcement->getMessage(),
+                'start'     => $announcement->getStart(),
+                'end'       => $announcement->getEnd()
+            ));
+        }
+
+        return $this;
+    }
 }



More information about the icinga-checkins mailing list