[icinga-checkins] icinga.org: icingaweb2/feature/announce-banner-11198: Show announcements in ModuleActionController::prepareInit()

git at icinga.org git at icinga.org
Fri Nov 4 15:36:00 CET 2016


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

Author: Alexander A. Klimov <alexander.klimov at icinga.com>
Date:   Fri Nov  4 15:29:41 2016 +0100

Show announcements in ModuleActionController::prepareInit()

refs #11198

---

 library/Icinga/Application/Web.php                 |   30 +-----------------
 .../Web/Controller/ModuleActionController.php      |   32 ++++++++++++++++++++
 2 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php
index 78fc47f..e99c02f 100644
--- a/library/Icinga/Application/Web.php
+++ b/library/Icinga/Application/Web.php
@@ -7,7 +7,6 @@ require_once __DIR__ . '/EmbeddedWeb.php';
 
 use DateTime;
 use Icinga\Data\Filter\Filter;
-use Icinga\Data\Filter\FilterAnd;
 use Icinga\Repository\AnnouncementIniRepository;
 use Zend_Controller_Action_HelperBroker;
 use Zend_Controller_Front;
@@ -101,8 +100,7 @@ class Web extends EmbeddedWeb
             ->setupTimezone()
             ->setupLogger()
             ->setupInternationalization()
-            ->cleanUpAnnouncements()
-            ->showAnnouncements();
+            ->cleanUpAnnouncements();
     }
 
     /**
@@ -565,32 +563,6 @@ class Web extends EmbeddedWeb
     }
 
     /**
-     * Show the user all announcements as notifications
-     *
-     * @return $this
-     */
-    protected function showAnnouncements()
-    {
-        if (! Icinga::app()->getRequest()->isXmlHttpRequest()) {
-            $repo = new AnnouncementIniRepository();
-            $now = new DateTime();
-            $query = $repo
-                ->select(array('message'))
-                ->applyFilter(new FilterAnd(array(
-                    Filter::expression('start', '<=', $now),
-                    Filter::expression('end', '>=', $now)
-                )))
-                ->order('start');
-
-            foreach ($query->fetchColumn() as $message) {
-                Notification::info($message);
-            }
-        }
-
-        return $this;
-    }
-
-    /**
      * Delete all expired announcements
      *
      * @return $this
diff --git a/library/Icinga/Web/Controller/ModuleActionController.php b/library/Icinga/Web/Controller/ModuleActionController.php
index 2cb5f62..3fb7db5 100644
--- a/library/Icinga/Web/Controller/ModuleActionController.php
+++ b/library/Icinga/Web/Controller/ModuleActionController.php
@@ -3,10 +3,15 @@
 
 namespace Icinga\Web\Controller;
 
+use DateTime;
 use Icinga\Application\Config;
 use Icinga\Application\Icinga;
 use Icinga\Application\Modules\Manager;
 use Icinga\Application\Modules\Module;
+use Icinga\Data\Filter\Filter;
+use Icinga\Data\Filter\FilterAnd;
+use Icinga\Repository\AnnouncementIniRepository;
+use Icinga\Web\Notification;
 
 /**
  * Base class for module action controllers
@@ -30,6 +35,33 @@ class ModuleActionController extends ActionController
             && $this->getFrontController()->getDefaultModule() !== $this->getModuleName()) {
             $this->assertPermission(Manager::MODULE_PERMISSION_NS . $this->getModuleName());
         }
+        $this->showAnnouncements();
+    }
+
+    /**
+     * Show the user all announcements as notifications
+     *
+     * @return $this
+     */
+    protected function showAnnouncements()
+    {
+        if (! Icinga::app()->getRequest()->isXmlHttpRequest()) {
+            $repo = new AnnouncementIniRepository();
+            $now = new DateTime();
+            $query = $repo
+                ->select(array('message'))
+                ->applyFilter(new FilterAnd(array(
+                    Filter::expression('start', '<=', $now),
+                    Filter::expression('end', '>=', $now)
+                )))
+                ->order('start');
+
+            foreach ($query->fetchColumn() as $message) {
+                Notification::info($message);
+            }
+        }
+
+        return $this;
     }
 
     /**



More information about the icinga-checkins mailing list