[icinga-checkins] icinga.org: icingaweb2-module-elasticsearch/host-events: EventType: Move load function from the Repository

git at icinga.org git at icinga.org
Mon Jul 4 14:56:21 CEST 2016


Module: icingaweb2-module-elasticsearch
Branch: host-events
Commit: 1fe4231636abad706dc5a2541d53a47dbfa19285
URL:    https://git.icinga.org/?p=icingaweb2-module-elasticsearch.git;a=commit;h=1fe4231636abad706dc5a2541d53a47dbfa19285

Author: Markus Frosch <lazyfrosch at icinga.org>
Date:   Fri Jul  1 16:51:28 2016 +0200

EventType: Move load function from the Repository

refs #11636

---

 application/controllers/EventsController.php       |    6 ++---
 application/controllers/HostController.php         |    5 +++--
 library/Elasticsearch/EventType.php                |   23 ++++++++++++++++++++
 .../Repository/EventTypeRepository.php             |   22 -------------------
 4 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/application/controllers/EventsController.php b/application/controllers/EventsController.php
index dd9b6d1..cd68dfb 100644
--- a/application/controllers/EventsController.php
+++ b/application/controllers/EventsController.php
@@ -5,7 +5,7 @@ namespace Icinga\Module\Elasticsearch\Controllers;
 
 use Icinga\Module\Elasticsearch\Controller;
 use Icinga\Module\Elasticsearch\Event;
-use Icinga\Module\Elasticsearch\Repository\EventTypeRepository;
+use Icinga\Module\Elasticsearch\EventType;
 
 use Icinga\Exception\IcingaException;
 
@@ -26,7 +26,7 @@ class EventsController extends Controller
         }
         $this->assertEventType($type);
 
-        $eventType = EventTypeRepository::load($type);
+        $eventType = EventType::loadByName($type);
 
         $this->view->title = $eventType->getLabel();
         $this->view->description = $eventType->getDescription();
@@ -72,7 +72,7 @@ class EventsController extends Controller
             throw new IcingaException('You need to specify the event id!');
         }
 
-        $this->view->eventType = $eventType = EventTypeRepository::load($type);
+        $this->view->eventType = $eventType = EventType::loadByName($type);
         $this->view->event = Event::fromRepository($eventType->getEventQuery(), $id);
     }
 
diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php
index 3ec2029..8a144e5 100644
--- a/application/controllers/HostController.php
+++ b/application/controllers/HostController.php
@@ -6,6 +6,7 @@ namespace Icinga\Module\Elasticsearch\Controllers;
 use Icinga\Exception\NotFoundError;
 use Icinga\Module\Elasticsearch\Controller;
 use Icinga\Module\Elasticsearch\Event;
+use Icinga\Module\Elasticsearch\EventType;
 use Icinga\Module\Elasticsearch\Repository\EventTypeRepository;
 
 use Icinga\Exception\IcingaException;
@@ -65,7 +66,7 @@ class HostController extends Controller
         if ($type !== null) {
             $this->assertEventType($type);
 
-            $this->view->eventType = $eventType = EventTypeRepository::load($type);
+            $this->view->eventType = $eventType = EventType::loadByName($type);
 
             $this->view->title = $eventType->getLabel();
             $this->view->description = $eventType->getDescription();
@@ -112,7 +113,7 @@ class HostController extends Controller
             throw new IcingaException('You need to specify the event id!');
         }
 
-        $this->view->eventType = $eventType = EventTypeRepository::load($type);
+        $this->view->eventType = $eventType = EventType::loadByName($type);
         $this->view->event = Event::fromRepository($eventType->getEventQuery(), $id);
     }
 
diff --git a/library/Elasticsearch/EventType.php b/library/Elasticsearch/EventType.php
index da295a0..2d71b99 100644
--- a/library/Elasticsearch/EventType.php
+++ b/library/Elasticsearch/EventType.php
@@ -6,6 +6,7 @@ namespace Icinga\Module\Elasticsearch;
 use Icinga\Data\Filter\Filter;
 
 use Icinga\Exception\IcingaException;
+use Icinga\Module\Elasticsearch\Repository\EventTypeRepository;
 use Icinga\Repository\RepositoryQuery;
 
 /**
@@ -55,6 +56,28 @@ class EventType
     }
 
     /**
+     * Load an EventType by its name
+     *
+     * @param   $name  string  event type name
+     *
+     * @return  EventType
+     */
+    public static function loadByName($name)
+    {
+        $repo = new EventTypeRepository();
+        $row = $repo->select()->where('name', $name)->fetchRow();
+
+        $type = new EventType($row->name);
+        $type
+            ->setLabel($row->label)
+            ->setDescription($row->description)
+            ->setFilter($row->filter)
+            ->setFields($row->fields);
+
+        return $type;
+    }
+
+    /**
      * @return string
      */
     public function getName()
diff --git a/library/Elasticsearch/Repository/EventTypeRepository.php b/library/Elasticsearch/Repository/EventTypeRepository.php
index 39e2208..57eb3fd 100644
--- a/library/Elasticsearch/Repository/EventTypeRepository.php
+++ b/library/Elasticsearch/Repository/EventTypeRepository.php
@@ -48,28 +48,6 @@ class EventTypeRepository extends IniRepository
     }
 
     /**
-     * Shorthand to fetchRow by name of event type
-     *
-     * @param   $name  string  event type name
-     *
-     * @return  EventType
-     */
-    public static function load($name)
-    {
-        $me = new static();
-        $row = $me->select()->where('name', $name)->fetchRow();
-        
-        $type = new EventType($row->name);
-        $type
-            ->setLabel($row->label)
-            ->setDescription($row->description)
-            ->setFilter($row->filter)
-            ->setFields($row->fields);
-        
-        return $type;
-    }
-
-    /**
      * Update the target with the given data and optionally limit the affected entries by using a filter
      *
      * @param   string  $target



More information about the icinga-checkins mailing list