0011968: shared calendars filter leads to sql error with pgsql
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 24 Jun 2016 09:54:18 +0000 (11:54 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 27 Jun 2016 08:05:53 +0000 (10:05 +0200)
* adds a test
* don't use space for empty sql IN value, need to use
  Zend_Db_Expr('NULL') instead

https://forge.tine20.org/view.php?id=11968

Change-Id: I1b65fb6b301711df5e073b3de057ff70cf20e04c
Reviewed-on: http://gerrit.tine20.com/customers/3272
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/JsonTests.php
tine20/Calendar/Model/CalendarFilter.php
tine20/Tinebase/Model/Filter/ForeignId.php

index 024fed6..7baf9a0 100644 (file)
@@ -336,7 +336,22 @@ class Calendar_JsonTests extends Calendar_TestCase
         $this->assertTrue(is_array($organizerfilter['value']), 'organizer should be resolved: ' . print_r($organizerfilter, TRUE));
         $this->assertEquals(Tinebase_Core::getUser()->contact_id, $organizerfilter['value']['id']);
     }
-    
+
+    /**
+     * testSearchEventsWithSharedContainerFilter
+     *
+     * @see 0011968: shared calendars filter leads to sql error with pgsql
+     */
+    public function testSearchEventsWithSharedContainerFilter()
+    {
+        $filter = $this->_getEventFilterArray();
+        $pathFilterValue = array("path" => "/shared");
+        $filter[0]['value'] = $pathFilterValue;
+        $searchResultData = $this->_uit->searchEvents($filter, array());
+
+        $this->assertEquals($pathFilterValue, $searchResultData['filter'][0]['value'], print_r($searchResultData['filter'], true));
+    }
+
     /**
      * search event with alarm
      */
index b8eb38e..f32fb39 100644 (file)
@@ -44,8 +44,8 @@ class Calendar_Model_CalendarFilter extends Tinebase_Model_Filter_Container
         
         $quotedDisplayContainerIdentifier = $_backend->getAdapter()->quoteIdentifier('attendee.displaycontainer_id');
         
-        $_select->where($this->_getQuotedFieldName($_backend) . ' IN (?)', empty($this->_containerIds) ? " " : $this->_containerIds);
-        $_select->orWhere($quotedDisplayContainerIdentifier  .  ' IN (?)', empty($this->_containerIds) ? " " : $this->_containerIds);
+        $_select->where($this->_getQuotedFieldName($_backend) . ' IN (?)', empty($this->_containerIds) ? new Zend_Db_Expr('NULL') : $this->_containerIds);
+        $_select->orWhere($quotedDisplayContainerIdentifier  .  ' IN (?)', empty($this->_containerIds) ? new Zend_Db_Expr('NULL') : $this->_containerIds);
     }
     
     /**
@@ -60,7 +60,7 @@ class Calendar_Model_CalendarFilter extends Tinebase_Model_Filter_Container
         $this->_options['ignoreAcl'] = TRUE;
         $this->_resolve();
         
-        $_select->where($this->_getQuotedFieldName($_backend) . ' IN (?)', empty($this->_containerIds) ? " " : $this->_containerIds);
+        $_select->where($this->_getQuotedFieldName($_backend) . ' IN (?)', empty($this->_containerIds) ? new Zend_Db_Expr('NULL') : $this->_containerIds);
     }
     
     /**
@@ -77,7 +77,7 @@ class Calendar_Model_CalendarFilter extends Tinebase_Model_Filter_Container
         
         $quotedDisplayContainerIdentifier = $_backend->getAdapter()->quoteIdentifier('attendee.displaycontainer_id');
         
-        $_select->where($quotedDisplayContainerIdentifier  .  ' IN (?)', empty($this->_containerIds) ? " " : $this->_containerIds);
+        $_select->where($quotedDisplayContainerIdentifier  .  ' IN (?)', empty($this->_containerIds) ? new Zend_Db_Expr('NULL') : $this->_containerIds);
     }
     
     public function setRequiredGrants(array $_grants)
index 191bde9..1bc72d0 100644 (file)
@@ -72,7 +72,7 @@ class Tinebase_Model_Filter_ForeignId extends Tinebase_Model_Filter_ForeignRecor
             $this->_foreignIds = $this->_getController()->search($this->_filterGroup, new Tinebase_Model_Pagination(), FALSE, TRUE);
         }
         
-        $_select->where($this->_getQuotedFieldName($_backend) . ' IN (?)', empty($this->_foreignIds) ? array('') : $this->_foreignIds);
+        $_select->where($this->_getQuotedFieldName($_backend) . ' IN (?)', empty($this->_foreignIds) ? new Zend_Db_Expr('NULL') : $this->_foreignIds);
     }
     
     /**