[icinga-checkins] icinga.org: icinga-web/mhein/testing: * Added IcingaDoctrine_Query (readded ), finished DataStoreModel

git at icinga.org git at icinga.org
Sat Jun 25 08:46:06 CEST 2011


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

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Tue Jun 14 10:09:06 2011 +0200

* Added IcingaDoctrine_Query (readded), finished DataStoreModel

---

 .../lib/database/IcingaDoctrine_Query.class.php    |   26 ++++++++++++--
 .../models/Store/IcingaApiDataStoreModel.class.php |    2 +-
 .../Modifiers/StoreFilterModifierModel.class.php   |   37 +++++++++----------
 app/modules/Api/validate/test.php                  |   14 +++++++
 tests/phpunit/suites.xml                           |    6 ++--
 .../api/apiprovider/IcingaApiDatastoreTest.php     |    2 +-
 6 files changed, 60 insertions(+), 27 deletions(-)

diff --git a/app/modules/Api/lib/database/IcingaDoctrine_Query.class.php b/app/modules/Api/lib/database/IcingaDoctrine_Query.class.php
index 803d102..803580e 100644
--- a/app/modules/Api/lib/database/IcingaDoctrine_Query.class.php
+++ b/app/modules/Api/lib/database/IcingaDoctrine_Query.class.php
@@ -1,13 +1,33 @@
 <?php
-/*class IcingaDoctrine_Query extends Doctrine_Query {
+class IcingaDoctrine_Query extends Doctrine_Query {
     public static function create($conn = NULL, $class = NULL) {
          
         return new IcingaDoctrine_Query($conn);
     }
-
+/*
     public function execute($attr,$hyd) {
         ApiDataRequestBaseModel::applySecurityPrincipals($this);
         return parent::execute($attr,$hyd);
     }
-}*/
+**/
+    public function toGroup()   {
+        $where = $this->_dqlParts['where'];
+        if (count($where) > 0) {
+          array_splice($where, count($where) - 1, 0, '(');
+          $this->_dqlParts['where'] = $where;
+        }
+ 
+        return $this;
+    }
+ 
+    public function endGroup()  {
+        $where = $this->_dqlParts['where'];
+        if (count($where) > 0) {
+          $where[] = ')';
+          $this->_dqlParts['where'] = $where;
+        }  
+ 
+        return $this;
+    }
+}
 ?>
diff --git a/app/modules/Api/models/Store/IcingaApiDataStoreModel.class.php b/app/modules/Api/models/Store/IcingaApiDataStoreModel.class.php
index c1b8fa1..e2c313d 100644
--- a/app/modules/Api/models/Store/IcingaApiDataStoreModel.class.php
+++ b/app/modules/Api/models/Store/IcingaApiDataStoreModel.class.php
@@ -67,7 +67,7 @@ class Api_Store_IcingaApiDataStoreModel extends AbstractDataStoreModel {
         $DBALMetaManager = AgaviContext::getInstance()->getModel("DBALMetaManager","Api");
         $DBALMetaManager->switchIcingaDatabase($this->connectionName); 
         
-        return Doctrine_Query::create();
+        return IcingaDoctrine_Query::create();
     }
     /**
     * Delegates unknown method calls to the modifiers and thereby extends the
diff --git a/app/modules/Api/models/Store/Modifiers/StoreFilterModifierModel.class.php b/app/modules/Api/models/Store/Modifiers/StoreFilterModifierModel.class.php
index a47e4c6..d121c86 100644
--- a/app/modules/Api/models/Store/Modifiers/StoreFilterModifierModel.class.php
+++ b/app/modules/Api/models/Store/Modifiers/StoreFilterModifierModel.class.php
@@ -61,15 +61,19 @@ class ApiStoreFilter extends GenericStoreFilter {
         }
     }  
 
-    public function __toDQL() {
+    public function __toDQL(IcingaDoctrine_Query $q,$dqlOnly) {
         $dql = $this->field." ".$this->operator;
         $v = $this->formatValues();
         if(is_array($v)) 
-            $dql .= "(".implode(",",$v).")";
+            $dql .= " (".implode(",",$v).")";
         else { 
             $dql .= " ".$v;
         }
-        return $dql;
+        if($dqlOnly)
+            return $dql;
+        else 
+            $q->where($dql);
+        return;
     } 
 } 
 
@@ -78,15 +82,20 @@ class ApiStoreFilterGroup extends GenericStoreFilterGroup {
         return GenericStoreFilterGroup::parse($filter,$field,"ApiStoreFilterGroup");
     }
     
-    public function __toDQL() {
+    public function __toDQL(IcingaDoctrine_Query $q) { 
         $dql = " (";
         $first = true;
         foreach($this->getSubFilters() as $filter) {
-            $dql .= (($first) ? ' ' : ' '.$this->getType())." ".$filter->__toDQL();
+            $filterDQL = $filter->__toDQL($q,true);
+            if($filterDQL)
+                $dql .= (($first) ? ' ' : ' '.$this->getType())." ".$filterDQL;
             $first = false;
         }
         $dql .= ") ";
-        return $dql;
+        if($this->getType() == 'OR')
+            $q->orWhere($dql);
+        else 
+            $q->andWhere($dql);
     }
 }
 
@@ -104,22 +113,12 @@ class Api_Store_Modifiers_StoreFilterModifierModel extends DataStoreFilterModifi
         $this->modifyImpl($o);
     }
 
-    protected function modifyImpl(Doctrine_Query &$o) { 
+    protected function modifyImpl(IcingaDoctrine_Query &$o) { 
         $f = $this->filter;
         if($f) {
-            $dql = $f->__toDQL();
-            $this->fixAlias($dql,$o);
-            $o->addWhere($dql);
-        }
+            $f->__toDQL($o); 
+        } 
     }
     
-    private function fixAlias(&$dql, Doctrine_Query &$o) {
-        $matches = array();
-        preg_match_all("/(\w+)\.\w+/",$dql,$matches);
-        try {
-            print_r(array($matches,$o->getComponentAlias('h')));
-        } catch(Exception $e) {
-        }
-    }
         
 }  
diff --git a/app/modules/Api/validate/test.php b/app/modules/Api/validate/test.php
new file mode 100644
index 0000000..7b93975
--- /dev/null
+++ b/app/modules/Api/validate/test.php
@@ -0,0 +1,14 @@
+<?php
+
+$DOM = new DomDocument();
+$DOM->load("ApiSearch.xml");
+
+$xpath = new DOMXPath($DOM);
+$xpath->registerNamespace("default","http://agavi.org/agavi/config/parts/validators/1.0");
+$xpath->registerNamespace("ae","http://agavi.org/agavi/config/global/envelope/1.0");
+foreach($xpath->query("//default:validators") as $node)  {
+	echo $node->nodeName."\n";
+	echo $node->getAttribute("method");
+}
+
+?>
diff --git a/tests/phpunit/suites.xml b/tests/phpunit/suites.xml
index 43605e1..0b074d0 100755
--- a/tests/phpunit/suites.xml
+++ b/tests/phpunit/suites.xml
@@ -29,12 +29,12 @@
 			<file>tests/configDatabase/icingaRoleOperations.php</file>
 			<file>tests/configDatabase/persistenceView.php</file>
 		</testsuite>
+-->
 
 
 
 
-
-		<!--	
+			
 		Commented is developement testing for 1.4. 
 		<testsuite name="API">
 			<file>tests/api/ConsoleInterfaceTest.php</file>
@@ -43,7 +43,7 @@
 			<directory>tests/api/hostgroups</directory>	
 			<directory>tests/api/servicegroups</directory>
 			<directory>tests/api/misc</directory>
-		</testsuite>-->
+		</testsuite>
 	
         <testsuite name="ApiProvider">
             <file>tests/api/apiprovider/FilterTest.php</file>
diff --git a/tests/phpunit/tests/api/apiprovider/IcingaApiDatastoreTest.php b/tests/phpunit/tests/api/apiprovider/IcingaApiDatastoreTest.php
index 419abdb..c403d0f 100644
--- a/tests/phpunit/tests/api/apiprovider/IcingaApiDatastoreTest.php
+++ b/tests/phpunit/tests/api/apiprovider/IcingaApiDatastoreTest.php
@@ -183,7 +183,7 @@ class IcingaApiDatastoreTest extends PHPUnit_Framework_TestCase
                         ),array(
                             "field" => "h.display_name",
                             "operator"=>"IN",
-                            "value" => array("c2-proxy","c2-mail-1")
+                            "value" => array("c2-db1")
                         )
                     )
                 )





More information about the icinga-checkins mailing list