Need to check for blob_fields when returning search results too.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 12 Dec 2010 03:26:15 +0000 (22:26 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 12 Dec 2010 03:26:15 +0000 (22:26 -0500)
Fixes activesync not being able to display contact photos sent from server.

turba/lib/Driver.php
turba/lib/Driver/Facebook.php
turba/lib/Driver/Favourites.php
turba/lib/Driver/Group.php
turba/lib/Driver/Imsp.php
turba/lib/Driver/Kolab.php
turba/lib/Driver/Ldap.php
turba/lib/Driver/Prefs.php
turba/lib/Driver/Share.php
turba/lib/Driver/Sql.php
turba/lib/Driver/Vbook.php

index 0c9c345..67486d8 100644 (file)
@@ -528,7 +528,7 @@ class Turba_Driver implements Countable
         }
 
         /* Retrieve the search results from the driver. */
-        $objects = $this->_search($fields, $return_fields);
+        $objects = $this->_search($fields, $return_fields, $this->toDriverKeys($this->getBlobs()));
 
         return $this->_toTurbaObjects($objects, $sort_order);
     }
@@ -2686,7 +2686,7 @@ class Turba_Driver implements Countable
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
         throw new Turba_Exception(_("Searching is not available."));
     }
@@ -2702,7 +2702,7 @@ class Turba_Driver implements Countable
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _read($key, $ids, $owner, $fields)
+    protected function _read($key, $ids, $owner, $fields, $blobFields = array())
     {
         throw new Turba_Exception(_("Reading contacts is not available."));
     }
index d6f1f61..6e2af82 100644 (file)
@@ -57,7 +57,7 @@ class Turba_Driver_Facebook extends Turba_Driver
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
         $results = $this->_getAddressBook($fields);
 
index 6a8f47c..2468cf1 100644 (file)
@@ -46,7 +46,7 @@ class Turba_Driver_Favourites extends Turba_Driver
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
         $results = array();
 
index ff6d091..fb8021b 100644 (file)
@@ -60,7 +60,7 @@ class Turba_Driver_Group extends Turba_Driver
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
         $results = array();
 
index f1d1b4a..ad8bfaf 100644 (file)
@@ -118,7 +118,7 @@ class Turba_Driver_Imsp extends Turba_Driver
      *
      * @return array  Hash containing the search results.
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
         $query = $results = array();
 
index f58bf2f..9acc76f 100644 (file)
@@ -61,7 +61,7 @@ class Turba_Driver_Kolab extends Turba_Driver
      *
      * @return               Hash containing the search results.
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
         return $this->_wrapper->_search($criteria, $fields);
     }
index 600f817..8b9d7e6 100644 (file)
@@ -147,7 +147,7 @@ class Turba_Driver_Ldap extends Turba_Driver
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
         /* Build the LDAP filter. */
         $filter = '';
index 2879c8f..670999a 100644 (file)
@@ -24,7 +24,7 @@ class Turba_Driver_Prefs extends Turba_Driver
      *
      * @return array  Hash containing the search results.
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
         return array_values($this->_getAddressBook());
     }
index bf3f8d3..4bba412 100644 (file)
@@ -104,9 +104,9 @@ class Turba_Driver_Share extends Turba_Driver
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
-        return $this->_driver->_search($criteria, $fields);
+        return $this->_driver->_search($criteria, $fields, $blobFields);
     }
 
     /**
index ee3ea66..0ee20e6 100644 (file)
@@ -91,6 +91,7 @@ class Turba_Driver_Sql extends Turba_Driver
      *
      * @param array $criteria      Array containing the search criteria.
      * @param array $fields        List of fields to return.
+     * @param array $blobFields    
      * @param array $appendWhere   An additional where clause to append.
      *                             Array should contain 'sql' and 'params'
      *                             params are used as bind parameters.
@@ -98,7 +99,7 @@ class Turba_Driver_Sql extends Turba_Driver
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields, $appendWhere = array())
+    protected function _search($criteria, $fields, $blobFields = array(), $appendWhere = array())
     {
         /* Build the WHERE clause. */
         $where = '';
@@ -151,12 +152,23 @@ class Turba_Driver_Sql extends Turba_Driver
                 throw new Turba_Exception($row);
             }
 
-            $row = $this->_convertFromDriver($row);
-
             $entry = array();
             for ($i = 0; $i < $iMax; $i++) {
                 $field = $fields[$i];
-                $entry[$field] = $row[$i];
+                if (isset($blobFields[$field])) {
+                    switch ($this->_db->dbsyntax) {
+                    case 'pgsql':
+                    case 'mssql':
+                        $entry[$field] = pack('H' . strlen($row[$i]), $row[$i]);
+                        break;
+
+                    default:
+                        $entry[$field] = $row[$i];
+                        break;
+                    }
+                } else {
+                    $entry[$field] = $this->_convertFromDriver($row[$i]);
+                }
             }
             $results[] = $entry;
         }
@@ -750,7 +762,7 @@ class Turba_Driver_Sql extends Turba_Driver
             }
         }
 
-        return $this->_toTurbaObjects($this->_search($criteria, $fields, $where));
+        return $this->_toTurbaObjects($this->_search($criteria, $fields, array(), $where));
     }
 
 }
index 437e6ad..5b679a2 100644 (file)
@@ -68,14 +68,14 @@ class Turba_Driver_Vbook extends Turba_Driver
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields)
+    protected function _search($criteria, $fields, $blobFields = array())
     {
         /* Add the passed in search criteria to the vbook criteria
          * (which need to be mapped from turba fields to
          * driver-specific fields). */
         $criteria['AND'][] = $this->makeSearch($this->searchCriteria, 'AND', array());
 
-        return $this->_driver->_search($criteria, $fields);
+        return $this->_driver->_search($criteria, $fields, $blobFields);
     }
 
     /**