[icinga-checkins] icinga.org: icinga-web/next: SELECT DISTINCT on CLOBs breaks Oracle support

git at icinga.org git at icinga.org
Mon Apr 15 15:15:49 CEST 2013


Module: icinga-web
Branch: next
Commit: b19582188121cd229570017e3a40094932f3f1cc
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=b19582188121cd229570017e3a40094932f3f1cc

Author: Marius Hein <marius.hein at netways.de>
Date:   Mon Apr 15 13:52:21 2013 +0200

SELECT DISTINCT on CLOBs breaks Oracle support

Add php style distinct system

refs #3965

---

 app/modules/Api/actions/ApiSearchAction.class.php  |   11 ++++-
 .../models/Result/DistinctOutputModel.class.php    |   46 ++++++++++++++++++++
 .../views/System/ViewProcSuccessView.class.php     |    8 +++
 3 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/app/modules/Api/actions/ApiSearchAction.class.php b/app/modules/Api/actions/ApiSearchAction.class.php
index 08502a6..ebdbdb8 100644
--- a/app/modules/Api/actions/ApiSearchAction.class.php
+++ b/app/modules/Api/actions/ApiSearchAction.class.php
@@ -130,14 +130,21 @@ class Api_ApiSearchAction extends IcingaApiBaseAction {
         
         // Rewrite output, e.g. plugin_output
         // see #2598
-        
+
+        /** @var $rewrite Api_Result_OutputRewriteModel **/
         $rewrite = $this->getContext()->getModel('Result.OutputRewrite', 'Api', array(
                 'target' => $target,
                 'optional' => $rd->getParameter('enableRewrite', false)
         ));
 
         $res = $rewrite->rewrite($res);
-        
+
+        // Distinct rows
+        // see #3965
+
+        /** @var $distinct Api_Result_DistinctOutputModel **/
+        $distinct = $this->getContext()->getModel('Result.DistinctOutput', 'Api');
+        $res = $distinct->distinctRows($res);
 
         $rd->setParameter("searchResult", $res);
 
diff --git a/app/modules/Api/models/Result/DistinctOutputModel.class.php b/app/modules/Api/models/Result/DistinctOutputModel.class.php
new file mode 100644
index 0000000..8556670
--- /dev/null
+++ b/app/modules/Api/models/Result/DistinctOutputModel.class.php
@@ -0,0 +1,46 @@
+<?php
+// {{{ICINGA_LICENSE_CODE}}}
+// -----------------------------------------------------------------------------
+// This file is part of icinga-web.
+// 
+// Copyright (c) 2009-2013 Icinga Developer Team.
+// All rights reserved.
+// 
+// icinga-web is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// 
+// icinga-web is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with icinga-web.  If not, see <http://www.gnu.org/licenses/>.
+// -----------------------------------------------------------------------------
+// {{{ICINGA_LICENSE_CODE}}}
+
+
+/**
+ * Model which make icinga api result rows distinct
+ * @package Icinga_Api
+ * @author mhein
+ * @since 1.9.0
+ */
+class Api_Result_DistinctOutputModel extends IcingaApiBaseModel
+{
+    /**
+     * Make array multidimensional unique
+     *
+     * Using AppKitArrayUtil and reset key identifier
+     *
+     * @param array $rows
+     * @return array
+     */
+    public function distinctRows(array $rows)
+    {
+        $out = AppKitArrayUtil::uniqueMultidimensional($rows);
+        return array_values($out); // Reset row identifiers
+    }
+}
\ No newline at end of file
diff --git a/app/modules/Cronks/views/System/ViewProcSuccessView.class.php b/app/modules/Cronks/views/System/ViewProcSuccessView.class.php
index 618829f..0beeb6a 100644
--- a/app/modules/Cronks/views/System/ViewProcSuccessView.class.php
+++ b/app/modules/Cronks/views/System/ViewProcSuccessView.class.php
@@ -139,6 +139,14 @@ class Cronks_System_ViewProcSuccessView extends CronksBaseView {
             $worker->buildAll();
 
             $data = $worker->fetchDataArray();
+
+            // Distinct rows
+            // see #3965
+
+            /** @var $distinct Api_Result_DistinctOutputModel **/
+            $distinct = $this->getContext()->getModel('Result.DistinctOutput', 'Api');
+            $data = $distinct->distinctRows($data);
+
             $worker->countResults();
             
             $jsonResult->hasFieldBulk(array_fill_keys($template->getFieldKeys(), ""));





More information about the icinga-checkins mailing list