0012198: improve contact photo ldap sync
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 12 Sep 2016 11:53:31 +0000 (13:53 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 12 Sep 2016 17:17:26 +0000 (19:17 +0200)
https://forge.tine20.org/view.php?id=12198

Change-Id: If678d4c5c4b0ebcb23b07a98df0c34babe455112
Reviewed-on: http://gerrit.tine20.com/customers/3562
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Addressbook/Model/Contact.php
tine20/Tinebase/User.php

index 79a88f7..9786590 100644 (file)
@@ -286,7 +286,8 @@ class Addressbook_Model_Contact extends Tinebase_Record_Abstract
      * @param array $_data
      * @return array $_data
      */
-    protected function _resolveAutoValues(array $_data) {
+    protected function _resolveAutoValues(array $_data)
+    {
         if (! (isset($_data['org_name']) || array_key_exists('org_name', $_data))) {
             $_data['org_name'] = '';
         }
index cc37581..29db96d 100644 (file)
@@ -552,9 +552,22 @@ class Tinebase_User
                 . ' new contact: ' . print_r($contact->toArray(), true)
                 . ' orig contact:' . print_r($originalContact->toArray(), true));
 
-            $syncPhoto = isset($options['syncContactPhoto']) && $options['syncContactPhoto'];
-            $diff = $contact->diff($originalContact, $syncPhoto ? array() : array('jpegphoto'));
-            if (! $diff->isEmpty() || ($originalContact->jpegphoto == 0 && ! empty($contact->jpegphoto))) {
+            if (isset($options['syncContactPhoto']) && $options['syncContactPhoto']) {
+                $syncPhoto = true;
+                if ($originalContact->jpegphoto == 1) {
+                    // TODO use generic function with ignoreAcl ...
+                    //$originalContact->jpegphoto = Tinebase_Controller::getInstance()->getImage('Addressbook', $originalContact->getId())->getBlob();
+                    $adb = new Addressbook_Backend_Sql();
+                    $originalContact->jpegphoto = $adb->getImage($originalContact->getId());
+                }
+                if ($contact->jpegphoto == 1) {
+                    if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
+                        . ' Removing/unset current jpegphoto');
+                    $contact->jpegphoto = false;
+                }
+            }
+            $diff = $contact->diff($originalContact, $syncPhoto ? array('n_fn') : array('jpegphoto', 'n_fn'));
+            if (! $diff->isEmpty() || ($originalContact->jpegphoto === 0 && ! empty($contact->jpegphoto)) ) {
                 // add modlog info
                 Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'update');
                 Tinebase_Container::getInstance()->increaseContentSequence($contact->container_id);
@@ -700,6 +713,11 @@ class Tinebase_User
                     $contact->{$contactKey} = $user->{$userKey};
             }
         }
+
+        if ($contact->n_fn !== $user->accountFullName) {
+            // use accountFullName overwrites contact n_fn
+            $contact->n_fn = $user->accountFullName;
+        }
         
         return $contact;
     }