[icinga-checkins] icinga.org: icinga-web/r1.6: * Fixed error prone order statements in subquery

git at icinga.org git at icinga.org
Fri Dec 2 14:27:15 CET 2011


Module: icinga-web
Branch: r1.6
Commit: 9925aceadaf9f88a14d9d5852be846f3dd33751b
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=9925aceadaf9f88a14d9d5852be846f3dd33751b

Author: Marius Hein <marius.hein at netways.de>
Date:   Fri Dec  2 14:21:24 2011 +0100

* Fixed error prone order statements in subquery

---

 .../data/xml/grid/icinga-host-history-template.xml |   44 +-------------------
 .../xml/grid/icinga-service-history-template.xml   |   45 +-------------------
 .../Doctrine/Adapter/Statement/IcingaOracle.php    |   41 ++++++++++++++++--
 3 files changed, 39 insertions(+), 91 deletions(-)

diff --git a/app/modules/Cronks/data/xml/grid/icinga-host-history-template.xml b/app/modules/Cronks/data/xml/grid/icinga-host-history-template.xml
index 9ade00e..e084fab 100644
--- a/app/modules/Cronks/data/xml/grid/icinga-host-history-template.xml
+++ b/app/modules/Cronks/data/xml/grid/icinga-host-history-template.xml
@@ -57,24 +57,11 @@
     -->
     <pager>
     	<parameter name="enabled">true</parameter>
-    
     	<parameter name="start">0</parameter>
     </pager>
     
     <grouping>
-    	<parameter name="enabled">true</parameter>
-    	<parameter name="field">state_group_date</parameter>
-    	
-    	<!-- GroupingView options (http://www.extjs.com/deploy/dev/docs/?class=Ext.grid.GroupingView) -->
-    	<parameter name="Ext.grid.GroupingView">
-    		<parameter name="hideGroupedColumn">true</parameter>
-    		<parameter name="startCollapsed">false</parameter>
-    	</parameter>
-    	
-    	<!-- Options for the store (http://www.extjs.com/deploy/dev/docs/?class=Ext.data.GroupingStore) -->
-    	<!-- <parameter name="Ext.data.GroupingStore">
-    		
-    	</parameter> -->
+    	<parameter name="enabled">false</parameter>
     </grouping>
     
     <!--
@@ -360,35 +347,6 @@
             
             <order>
                 <parameter name="enabled">true</parameter>
-                <parameter name="default">false</parameter>
-                <parameter name="order">DESC</parameter>
-            </order>
-        </field>
-        
-        <field name="state_group_date">
-        	<datasource>
-        		<parameter name="field">STATEHISTORY_STATE_TIME</parameter>
-        	</datasource>
-        	
-        	<display>
-                <parameter name="visible">true</parameter>
-                <parameter name="label">Groupdate</parameter>
-                
-                <parameter name="userFunc">
-                	<parameter name="model">Cronks.ColumnDisplay.Format</parameter>
-                	<parameter name="method">formatDate</parameter>
-			<parameter name="arguments">
-				<parameter name="format"><![CDATA[Y-m-d H:00:00]]></parameter>
-			</parameter>
-                </parameter>
-            </display>
-            
-            <filter>
-                <parameter name="enabled">false</parameter>
-            </filter>
-            
-            <order>
-                <parameter name="enabled">true</parameter>
                 <parameter name="default">true</parameter>
                 <parameter name="order">DESC</parameter>
             </order>
diff --git a/app/modules/Cronks/data/xml/grid/icinga-service-history-template.xml b/app/modules/Cronks/data/xml/grid/icinga-service-history-template.xml
index 1039261..badc64e 100644
--- a/app/modules/Cronks/data/xml/grid/icinga-service-history-template.xml
+++ b/app/modules/Cronks/data/xml/grid/icinga-service-history-template.xml
@@ -19,8 +19,6 @@
         <parameter name="mode">default</parameter>
         <parameter name="layout">CronkGridTemplateAjaxGridLayout</parameter> 
 
-
-        
         <parameter name="security">
         	<parameter>IcingaServicegroup</parameter>
         	<parameter>IcingaHostCustomVariablePair</parameter>
@@ -68,19 +66,7 @@
     </pager>
     
     <grouping>
-    	<parameter name="enabled">true</parameter>
-    	<parameter name="field">state_group_date</parameter>
-    	
-    	<!-- GroupingView options (http://www.extjs.com/deploy/dev/docs/?class=Ext.grid.GroupingView) -->
-    	<parameter name="Ext.grid.GroupingView">
-    		<parameter name="hideGroupedColumn">true</parameter>
-    		<parameter name="startCollapsed">false</parameter>
-    	</parameter>
-    	
-    	<!-- Options for the store (http://www.extjs.com/deploy/dev/docs/?class=Ext.data.GroupingStore) -->
-    	<!-- <parameter name="Ext.data.GroupingStore">
-    		
-    	</parameter> -->
+    	<parameter name="enabled">false</parameter>
     </grouping>
     
     <!--
@@ -448,35 +434,6 @@
             
             <order>
                 <parameter name="enabled">true</parameter>
-                <parameter name="default">false</parameter>
-                <parameter name="order">DESC</parameter>
-            </order>
-        </field>
-        
-        <field name="state_group_date">
-        	<datasource>
-        		<parameter name="field">STATEHISTORY_STATE_TIME</parameter>
-        	</datasource>
-        	
-        	<display>
-                <parameter name="visible">true</parameter>
-                <parameter name="label">Groupdate</parameter>
-                
-                <parameter name="userFunc">
-                	<parameter name="model">Cronks.ColumnDisplay.Format</parameter>
-                	<parameter name="method">formatDate</parameter>
-					<parameter name="arguments">
-						<parameter name="format"><![CDATA[Y-m-d H:00:00]]></parameter>
-					</parameter>
-                </parameter>
-            </display>
-            
-            <filter>
-                <parameter name="enabled">false</parameter>
-            </filter>
-            
-            <order>
-                <parameter name="enabled">true</parameter>
                 <parameter name="default">true</parameter>
                 <parameter name="order">DESC</parameter>
             </order>
diff --git a/lib/doctrine/lib/Doctrine/Adapter/Statement/IcingaOracle.php b/lib/doctrine/lib/Doctrine/Adapter/Statement/IcingaOracle.php
index 4c845c1..dbf485f 100644
--- a/lib/doctrine/lib/Doctrine/Adapter/Statement/IcingaOracle.php
+++ b/lib/doctrine/lib/Doctrine/Adapter/Statement/IcingaOracle.php
@@ -71,6 +71,8 @@ class Doctrine_Adapter_Statement_IcingaOracle implements Doctrine_Adapter_Statem
      */
     protected $ociErrors = array();
     
+    private $aliasMap = array();
+    
     /**
      * the constructor
      * 
@@ -91,11 +93,20 @@ class Doctrine_Adapter_Statement_IcingaOracle implements Doctrine_Adapter_Statem
         $this->parseQuery();
     }
     
-    private $aliasMap = array();
-    public function fixCrappyIcingaTables($query) { 
+    
+    
+    private function fixCrappyIcingaTables($query) {
+
+        if (!preg_match('/^\s*(SELECT|INSERT|UPDATE|DELETE)/i', $query)) {
+            return $query;
+        }
+        
+        
         $this->resolveIdFields($query); 
         $this->createAliasMap($query);
-        $this->removeInvalidAliases($query); 
+        $this->removeInvalidAliases($query);
+        $this->fixOrderFields($query);
+        
         
         // dirty icinga specific fixes  
         $query = preg_replace("/notification_timeperiod_object_id/", "notif_timeperiod_object_id",$query);
@@ -110,12 +121,34 @@ class Doctrine_Adapter_Statement_IcingaOracle implements Doctrine_Adapter_Statem
     }
 
     private function removeInvalidAliases(&$query) {
-      
         $query = preg_replace("/(ORDER BY) *([A-Za-z._0-9]+) +AS +[_A-Za-z0-9]+/i","$1 $2",$query);  
        // $query = preg_replace("/(FROM *\( *SELECT.*? *)ORDER BY .*?(\) *\w+ *WHERE.*)/","$1 $2",$query);
        
     }
     
+    /**
+     * Search for all ORDER tags and check if they selected. If not
+     * remove the error-prone statement part
+     * @param string $query
+     * @return integer Number of removed order parts
+     */
+    private function fixOrderFields(&$query) {
+        $matches = array ();
+        $re = 0;
+        
+        preg_match_all('/ORDER\s+BY\s+([\w\.]+)\s*(ASC|DESC)?/i', $query, $matches, PREG_SET_ORDER);
+        
+        foreach ($matches as $m) {
+            $re = sprintf('/SELECT\s+.*(%s).*FROM/i', preg_quote($m[1]));
+            if (!preg_match($re, $query)) {
+                $query = str_replace($m[0], '', $query);
+                $re++;
+            }
+        }
+        
+        return $re;
+    }
+    
     private function resolveIdFields(&$query) {
         
         $tableRefMapRegExpNoAlias = "/(FROM|JOIN) *(?<table>\w+) *(WHERE|INNER|JOIN|ON|ORDER|LIMIT|GROUP)/";   





More information about the icinga-checkins mailing list