[icinga-checkins] icinga.org: icingaweb2/feature/announce-banner-11198: AnnouncementIniRepository: add table for announcement acknowledgements

git at icinga.org git at icinga.org
Fri Nov 4 13:05:18 CET 2016


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

Author: Alexander A. Klimov <alexander.klimov at icinga.com>
Date:   Fri Nov  4 12:06:17 2016 +0100

AnnouncementIniRepository: add table for announcement acknowledgements

refs #11198

---

 .../Repository/AnnouncementIniRepository.php       |   50 +++++++++++++++++---
 1 file changed, 44 insertions(+), 6 deletions(-)

diff --git a/library/Icinga/Repository/AnnouncementIniRepository.php b/library/Icinga/Repository/AnnouncementIniRepository.php
index a47d95a..82bc189 100644
--- a/library/Icinga/Repository/AnnouncementIniRepository.php
+++ b/library/Icinga/Repository/AnnouncementIniRepository.php
@@ -5,6 +5,7 @@ namespace Icinga\Repository;
 
 use DateTime;
 use Icinga\Application\Config;
+use Icinga\Data\Filter\Filter;
 use Icinga\Web\Announcement;
 
 /**
@@ -15,7 +16,10 @@ class AnnouncementIniRepository extends IniRepository
     /**
      * {@inheritDoc}
      */
-    protected $queryColumns = array('announcement' => array('id', 'author', 'message', 'hash', 'start', 'end'));
+    protected $queryColumns = array(
+        'announcement'      => array('id', 'author', 'message', 'hash', 'start', 'end'),
+        'acknowledgement'   => array('id', 'user', 'announcement_hash')
+    );
 
     /**
      * {@inheritDoc}
@@ -28,15 +32,21 @@ class AnnouncementIniRepository extends IniRepository
     /**
      * {@inheritDoc}
      */
-    protected $triggers = array('announcement');
+    protected $triggers = array('announcement', 'acknowledgement');
 
     /**
      * {@inheritDoc}
      */
-    protected $configs = array('announcement' => array(
-        'name'      => 'announcements',
-        'keyColumn' => 'id'
-    ));
+    protected $configs = array(
+        'announcement' => array(
+            'name'      => 'announcements/announcements',
+            'keyColumn' => 'id'
+        ),
+        'acknowledgement' => array(
+            'name'      => 'announcements/acknowledgements',
+            'keyColumn' => 'id'
+        )
+    );
 
     /**
      * Create a DateTime from a *nix timestamp
@@ -95,6 +105,34 @@ class AnnouncementIniRepository extends IniRepository
         if ($new->message !== $old->message) {
             $announcement = new Announcement((array) $new);
             $new->hash = $announcement->getHash();
+
+            $this->delete('acknowledgement', Filter::expression('announcement_hash', '=', $old->hash));
+        }
+
+        return $new;
+    }
+
+    /**
+     * Before-delete trigger (per row)
+     *
+     * @param   object  $old    The data as currently stored
+     */
+    protected function onDeleteAnnouncement($old)
+    {
+        $this->delete('acknowledgement', Filter::expression('announcement_hash', '=', $old->hash));
+    }
+
+    /**
+     * Before-insert trigger (per row)
+     *
+     * @param   object  $new    The original data to insert
+     *
+     * @return  object          The eventually modified data to insert
+     */
+    protected function onInsertAcknowledgement($new)
+    {
+        if (! isset($new->id)) {
+            $new->id = uniqid('', true);
         }
 
         return $new;



More information about the icinga-checkins mailing list