plugins/libkolab

Aleksander Machniak machniak at kolabsys.com
Mon Jun 17 15:45:40 CEST 2013


 plugins/libkolab/lib/kolab_storage_cache.php |   34 ++++++++++++++-------------
 1 file changed, 18 insertions(+), 16 deletions(-)

New commits:
commit bc4d15ab55f67ba1b7d67411b0d491ca012e8526
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Mon Jun 17 15:44:17 2013 +0200

    De-duplicate binary content when saving in database (#1749)

diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index 6d8071b..a3b6626 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -37,7 +37,11 @@ class kolab_storage_cache
     private $ready = false;
     private $max_sql_packet;
     private $max_sync_lock_time = 600;
-    private $binary_cols = array('photo','pgppublickey','pkcs7publickey');
+    private $binary_items = array(
+        'photo'          => '|<photo><uri>[^;]+;base64,([^<]+)</uri></photo>|i',
+        'pgppublickey'   => '|<key><uri>date:application/pgp-keys;base64,([^<]+)</uri></photo>|i',
+        'pkcs7publickey' => '|<key><uri>date:application/pkcs7-mime;base64,([^<]+)</uri></photo>|i',
+    );
 
 
     /**
@@ -524,7 +528,6 @@ class kolab_storage_cache
      */
     private function _serialize($object)
     {
-        $bincols  = array_flip($this->binary_cols);
         $sql_data = array('changed' => null, 'dtstart' => null, 'dtend' => null, 'xml' => '', 'tags' => '', 'words' => '');
         $objtype  = $object['_type'] ? $object['_type'] : $this->folder->type;
 
@@ -566,12 +569,13 @@ class kolab_storage_cache
         // extract object data
         $data = array();
         foreach ($object as $key => $val) {
+            // skip empty properties
             if ($val === "" || $val === null) {
-                // skip empty properties
                 continue;
             }
-            if (isset($bincols[$key])) {
-                $data[$key] = base64_encode($val);
+            // mark binary data to be extracted from xml on unserialize()
+            if (isset($this->binary_items[$key])) {
+                $data[$key] = true;
             }
             else if ($key[0] != '_') {
                 $data[$key] = $val;
@@ -597,9 +601,10 @@ class kolab_storage_cache
         $object = unserialize($sql_arr['data']);
 
         // decode binary properties
-        foreach ($this->binary_cols as $key) {
-            if (!empty($object[$key]))
-                $object[$key] = base64_decode($object[$key]);
+        foreach ($this->binary_items as $key => $regexp) {
+            if (!empty($object[$key]) && preg_match($regexp, $sql_arr['xml'], $m)) {
+                $object[$key] = base64_decode($m[1]);
+            }
         }
 
         // add meta data
@@ -708,17 +713,15 @@ class kolab_storage_cache
         if (!$sql_arr) {
             $this->db->query(
                 "INSERT INTO kolab_cache (resource, type, msguid, created, uid, data, xml)".
-                " VALUES (?, ?, 1, ?, '', '', '')",
+                " VALUES (?, ?, 1, " . $this->db->now() . ", '', '', '')",
                 $this->resource_uri,
-                'lock',
-                date('Y-m-d H:i:s')
+                'lock'
             );
         }
         else {
             $this->db->query(
-                "UPDATE kolab_cache SET msguid=1, created=? ".
-                "WHERE resource=? AND type=?",
-                date('Y-m-d H:i:s'),
+                "UPDATE kolab_cache SET msguid = 1, created = " . $this->db->now() .
+                " WHERE resource = ? AND type = ?",
                 $this->resource_uri,
                 'lock'
             );
@@ -734,8 +737,7 @@ class kolab_storage_cache
             return;
 
         $this->db->query(
-            "UPDATE kolab_cache SET msguid=0 ".
-            "WHERE resource=? AND type=?",
+            "UPDATE kolab_cache SET msguid = 0 WHERE resource = ? AND type = ?",
             $this->resource_uri,
             'lock'
         );





More information about the commits mailing list