0010974 shrink contact images for vcards
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 20 Apr 2015 15:32:24 +0000 (17:32 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 21 Apr 2015 15:10:35 +0000 (17:10 +0200)
* moves contact resizing from ActiveSync to Contact model

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

Change-Id: Ibc242e5e80e75a6a4309d13114884019387fc59b
Reviewed-on: http://gerrit.tine20.com/customers/1858
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Lars Kneschke <l.kneschke@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Addressbook/Frontend/WebDAV/ContactTest.php
tests/tine20/Addressbook/Import/VCardTest.php
tests/tine20/Addressbook/Import/files/jan.vcf [new file with mode: 0644]
tine20/ActiveSync/Controller/Contacts.php
tine20/Addressbook/Convert/Contact/VCard/Abstract.php
tine20/Addressbook/Model/Contact.php

index 4211466..17d5a8b 100644 (file)
@@ -43,6 +43,8 @@ class Addressbook_Frontend_WebDAV_ContactTest extends PHPUnit_Framework_TestCase
      */
     protected function setUp()
     {
+        $_SERVER['HTTP_USER_AGENT'] = 'FooBar User Agent';
+
         Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
         
         Addressbook_Controller_Contact::getInstance()->setGeoDataForContacts(FALSE);
@@ -75,10 +77,6 @@ class Addressbook_Frontend_WebDAV_ContactTest extends PHPUnit_Framework_TestCase
      */
     public function testCreateContact()
     {
-        if (!isset($_SERVER['HTTP_USER_AGENT'])) {
-            $_SERVER['HTTP_USER_AGENT'] = 'FooBar User Agent';
-        }
-        
         $vcardStream = fopen(dirname(__FILE__) . '/../../Import/files/sogo_connector.vcf', 'r');
         
         $id = Tinebase_Record_Abstract::generateUID();
@@ -92,7 +90,25 @@ class Addressbook_Frontend_WebDAV_ContactTest extends PHPUnit_Framework_TestCase
         
         return $contact;
     }
-    
+
+    /**
+     * test create contact with photo
+     *
+     * @return Addressbook_Frontend_WebDAV_Contact
+     */
+    public function testCreateContactWithPhoto()
+    {
+        $vcardStream = fopen(dirname(__FILE__) . '/../../Import/files/jan.vcf', 'r');
+
+        $id = Tinebase_Record_Abstract::generateUID();
+        $contact = Addressbook_Frontend_WebDAV_Contact::create($this->objects['initialContainer'], "$id.vcf", $vcardStream);
+        $record = $contact->getRecord();
+
+        $imgBlob = $record->getSmallContactImage();
+        $this->assertTrue(strlen($imgBlob) > 0);
+        $this->assertTrue(strlen($imgBlob) < Addressbook_Model_Contact::SMALL_PHOTO_SIZE);
+    }
+
     /**
      * test get vcard
      */
@@ -157,8 +173,6 @@ class Addressbook_Frontend_WebDAV_ContactTest extends PHPUnit_Framework_TestCase
      */
     public function testPutContactFromGenericClient()
     {
-        $_SERVER['HTTP_USER_AGENT'] = 'FooBar User Agent';
-        
         $contact = $this->testCreateContact();
     
         $vcardStream = fopen(dirname(__FILE__) . '/../../Import/files/mac_os_x_addressbook.vcf', 'r');
@@ -174,8 +188,6 @@ class Addressbook_Frontend_WebDAV_ContactTest extends PHPUnit_Framework_TestCase
      */
     public function testGetNameOfContact()
     {
-        $_SERVER['HTTP_USER_AGENT'] = 'FooBar User Agent';
-        
         $contact = $this->testCreateContact();
         
         $record = $contact->getRecord();
index 89bf079..dce5e9f 100644 (file)
@@ -81,13 +81,14 @@ class Addressbook_Import_VCardTest extends PHPUnit_Framework_TestCase
         
         $result = $this->_instance->importFile($this->_filename);
         $this->_contactIdsToDelete = array($result['results']->getArrayOfIds());
-        
-        $this->assertEquals(2, $result['totalcount'], 'Didn\'t import all contacts.');
-        $this->assertEquals('spass, alex', $result['results']->getFirstRecord()->n_fileas, 'file as not found');
-        $this->assertEquals('+49732121258035', $result['results']->getFirstRecord()->tel_home, 'n_fileas not found');
-        $this->assertEquals('mitbewohner', $result['results']->getFirstRecord()->note, 'note not found');
-        $this->assertEquals('Eisenhüttenstraße 723', $result['results']->getFirstRecord()->adr_one_street, 'street not found');
-        $this->assertEquals('http://www.vcard.de', $result['results']->getFirstRecord()->url, 'url not found');
+
+        $this->assertEquals(2, $result['totalcount'], 'Didn\'t import all contacts:' . print_r($result['exceptions']->toArray(), true));
+        $firstContact = $result['results']->getFirstRecord();
+        $this->assertEquals('spass, alex', $firstContact->n_fileas, 'file as not found');
+        $this->assertEquals('+49732121258035', $firstContact->tel_home, 'n_fileas not found');
+        $this->assertEquals('mitbewohner', $firstContact->note, 'note not found');
+        $this->assertEquals('Eisenhüttenstraße 723', $firstContact->adr_one_street, 'street not found');
+        $this->assertEquals('http://www.vcard.de', $firstContact->url, 'url not found');
     }
 
     /**
@@ -183,7 +184,7 @@ class Addressbook_Import_VCardTest extends PHPUnit_Framework_TestCase
      */
     public function testImportDuplicate()
     {
-        $contact = $this->testImportWithIconv();
+        $this->testImportWithIconv();
         
         // import again -> should have duplicate
         $result = $this->_instance->importFile($this->_filename);
diff --git a/tests/tine20/Addressbook/Import/files/jan.vcf b/tests/tine20/Addressbook/Import/files/jan.vcf
new file mode 100644 (file)
index 0000000..105e45d
--- /dev/null
@@ -0,0 +1,146 @@
+BEGIN:VCARD
+VERSION:3.0
+FN:jan gerber
+N:gerber;jan;;;
+EMAIL;TYPE=INTERNET:jan@web.de
+EMAIL;TYPE=INTERNET;TYPE=HOME:jan@home.org
+TEL;TYPE=CELL:0123233838592
+PHOTO;BASE64:
+  /9j/4AAQSkZJRgABAQAAAQABAAD/4QBARXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAA
+  AqACAAQAAAABAAAAlKADAAQAAAABAAAAlAAAAAD/2wBDAAIBAQIBAQICAQICAgICAwUDAwMDAwYE
+  BAMFBwYHBwcGBgYHCAsJBwgKCAYGCQ0JCgsLDAwMBwkNDg0MDgsMDAv/2wBDAQICAgMCAwUDAwUL
+  CAYICwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwv/wAAR
+  CACUAJQDASIAAhEBAxEB/8QAHwAAAQUBAQEB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J3++CMEhCefbFfsb8C/wBpfwP8Y7eKT4Z+JtI1x5QSiW9wrS468p1FezT3
+  Pj69NxbVj6O8NYjiAJ56/hXUWL9CvpXBeFNajnVQ5CuBnB6n2xXaWlxnLN8u35Tn1P8A+qu2Kdjz
+  KmmjPRNNOdOtz6xr/IUUmkHOk2p9YU/9BFFeFP4mfZ0fgj6I/Pb/AIOYf2k/Gv7LP7C3g/xH8B9d
+  u/D2tXHj6zsHurcgOYX07UnZef8AajQ/hX82nxi+KPiH4seKrjXfifq994g1e+JaW6v5DPIcnOAW
+  +6PYYooo+yRL4yjbsbe08yLh3XJJ5rmtZcy3QZzy3Wiiqh8BZJ8B0W5+OWii5VZAL2MAMM4+YV+x
+  fgiIWyTJHnbwRntwOBRRXg5qfWcM/wAQ1761SWykZxk4xXmHiG2QXDrtBBbvRRXmYc+txXwmW/hT
+  T72Mm6tYnJ9VrmtX8JadbXJ8i1iX6LRRXXN6HiwSvsanhjToYYz5cajA9PcVuqo8g57EY/OiiuSe
+  yPQwys2fIH/BRS3STS7F3GWinbb7cGvlm0/eEFupI/lRRXv5ZsfD53/GZpaPdPDMyxnA9K6/wL8R
+  Ne+GWux6r8PdX1DRdQtAZYprOZoipHsvBHsRRRXqxbueBWSZ+4P/AAQf/by+I37WXw/1WH45ana6
+  vPo5SO3uzbhbjaMD5mzg9euK/S/Q7x2dfu/dPb3FFFerQb5UePiIq+x7T4fO7QbInqbeP/0EUUUV
+  4s/iZ9DT+Beh/9k=
+END:VCARD
index 7dbf258..e692f97 100644 (file)
@@ -148,16 +148,16 @@ class ActiveSync_Controller_Contacts extends ActiveSync_Controller_Abstract impl
      */
     public function toSyncrotonModel($entry, array $options = array())
     {
-        if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(\r
+        if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(
             __METHOD__ . '::' . __LINE__ . " contact data " . print_r($entry->toArray(), TRUE));
         
         $syncrotonContact = new Syncroton_Model_Contact();
         
         foreach ($this->_mapping as $syncrotonProperty => $tine20Property) {
-            // skip empty values\r
-            if (empty($entry->$tine20Property) && $entry->$tine20Property != '0' || count($entry->$tine20Property) === 0) {\r
-                continue;\r
-            }\r
+            // skip empty values
+            if (empty($entry->$tine20Property) && $entry->$tine20Property != '0' || count($entry->$tine20Property) === 0) {
+                continue;
+            }
             
             switch($tine20Property) {
                 case 'adr_one_countryname':
@@ -186,8 +186,7 @@ class ActiveSync_Controller_Contacts extends ActiveSync_Controller_Abstract impl
                     
                 case 'jpegphoto':
                     try {
-                        $image = Tinebase_Controller::getInstance()->getImage('Addressbook', $entry->getId());
-                        $syncrotonContact->$syncrotonProperty = $image->getBlob('image/jpeg', 36000);
+                        $syncrotonContact->$syncrotonProperty = $entry->getSmallContactImage();
                     } catch (Exception $e) {
                         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Image for contact {$entry->getId()} not found or invalid");
                     }
@@ -226,27 +225,17 @@ class ActiveSync_Controller_Contacts extends ActiveSync_Controller_Abstract impl
         unset($contact->jpegphoto);
         
         foreach($this->_mapping as $fieldName => $value) {
-            if (!isset($data->$fieldName)) {\r
+            if (!isset($data->$fieldName)) {
                 $contact->$value = null;
                 
-                continue;\r
-            }\r
+                continue;
+            }
             
             switch ($value) {
                 case 'jpegphoto':
                     if(!empty($data->$fieldName)) {
                         $devicePhoto = $data->$fieldName;
-                        
-                        try {
-                            $currentPhoto = Tinebase_Controller::getInstance()->getImage('Addressbook', $contact->getId())->getBlob('image/jpeg', 36000);
-                        } catch (Exception $e) {}
-                        
-                        if (isset($currentPhoto) && $currentPhoto == $devicePhoto) {
-                            if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . " photo did not change on device -> preserving server photo");
-                        } else {
-                            if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . " using new contact photo from device (" . strlen($devicePhoto) . "KB)");
-                            $contact->jpegphoto = $devicePhoto;
-                        }
+                        $contact->setSmallContactImage($devicePhoto);
                     } else if ($entry && ! empty($entry->jpegphoto)) {
                         $contact->jpegphoto = '';
                         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ 
@@ -259,8 +248,8 @@ class ActiveSync_Controller_Contacts extends ActiveSync_Controller_Abstract impl
                     $contact->$value = new Tinebase_DateTime($data->$fieldName);
                     
                     if ($this->_device->devicetype == Syncroton_Model_Device::TYPE_IPHONE && $this->_device->getMajorVersion() < 800) {
-                        // iOS < 4 & webow < 2.1 send birthdays to the entered date, but the time the birthday got entered on the device
-                        // acutally iOS < 4 somtimes sends the bday at noon but the timezone is not clear
+                        // iOS < 4 & webos < 2.1 send birthdays to the entered date, but the time the birthday got entered on the device
+                        // actually iOS < 4 sometimes sends the bday at noon but the timezone is not clear
                         // -> we don't trust the time part and set the birthdays timezone to the timezone the user has set in tine
                         $userTimezone = Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
                         $contact->$value = new Tinebase_DateTime($contact->bday->setTime(0,0,0)->format(Tinebase_Record_Abstract::ISO8601LONG), $userTimezone);
index e3d6bff..4774e7e 100644 (file)
@@ -158,7 +158,7 @@ abstract class Addressbook_Convert_Contact_VCard_Abstract implements Tinebase_Co
                     break;
                     
                 case 'PHOTO':
-                    $data['jpegphoto'] = $property->getValue();
+                    $jpegphoto = $property->getValue();
                     break;
                     
                 case 'TEL':
@@ -214,6 +214,10 @@ abstract class Addressbook_Convert_Contact_VCard_Abstract implements Tinebase_Co
         }
         
         $contact->setFromArray($data);
+
+        if (isset($jpegphoto)) {
+            $contact->setSmallContactImage($jpegphoto);
+        }
         
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) 
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' data ' . print_r($contact->toArray(), true));
@@ -395,15 +399,14 @@ abstract class Addressbook_Convert_Contact_VCard_Abstract implements Tinebase_Co
     /**
      * add photo data to VCard
      * 
-     * @param  Tinebase_Record_Abstract  $record
+     * @param  Addressbook_Model_Contact $record
      * @param  \Sabre\VObject\Component  $card
      */
-    protected function _fromTine20ModelAddPhoto(Tinebase_Record_Abstract $record, \Sabre\VObject\Component $card)
+    protected function _fromTine20ModelAddPhoto(Addressbook_Model_Contact $record, \Sabre\VObject\Component $card)
     {
-        if (!empty($record->jpegphoto)) {Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__);
+        if (! empty($record->jpegphoto)) {Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__);
             try {
-                $image = Tinebase_Controller::getInstance()->getImage('Addressbook', $record->getId());
-                 $jpegData = $image->getBlob('image/jpeg');      
+                $jpegData = $record->getSmallContactImage();
                 $card->add('PHOTO',  $jpegData, array('TYPE' => 'JPEG', 'ENCODING' => 'b'));
             } catch (Exception $e) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) 
index 5034a05..79a88f7 100644 (file)
@@ -80,6 +80,13 @@ class Addressbook_Model_Contact extends Tinebase_Record_Abstract
      * @var string
      */
     const CONTACTTYPE_USER = 'user';
+
+    /**
+     * small contact photo size
+     *
+     * @var integer
+     */
+    const SMALL_PHOTO_SIZE = 36000;
     
     /**
      * key in $_validators/$_properties array for the filed which 
@@ -420,4 +427,42 @@ class Addressbook_Model_Contact extends Tinebase_Record_Abstract
             unset($_data['jpegphoto']);
         }
     }
+
+    /**
+     * set small contact image
+     *
+     * @param $newPhotoBlob
+     */
+    public function setSmallContactImage($newPhotoBlob)
+    {
+        if ($this->getId()) {
+            try {
+                $currentPhoto = Tinebase_Controller::getInstance()->getImage('Addressbook', $this->getId())->getBlob('image/jpeg', self::SMALL_PHOTO_SIZE);
+            } catch (Exception $e) {
+                // no current photo
+            }
+        }
+
+        if (isset($currentPhoto) && $currentPhoto == $newPhotoBlob) {
+            if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__
+                . " Photo did not change -> preserving current photo");
+        } else {
+            if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__
+                . " Setting new contact photo (" . strlen($newPhotoBlob) . "KB)");
+            $this->jpegphoto = $newPhotoBlob;
+        }
+    }
+
+    /**
+     * return small contact image for sync
+     *
+     * @return string
+     * @throws Tinebase_Exception_InvalidArgument
+     * @throws Tinebase_Exception_NotFound
+     */
+    public function getSmallContactImage()
+    {
+        $image = Tinebase_Controller::getInstance()->getImage('Addressbook', $this->getId());
+        return $image->getBlob('image/jpeg', self::SMALL_PHOTO_SIZE);
+    }
 }