0011260: LDAP sync: contact image is not updated
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 24 Aug 2015 13:39:31 +0000 (15:39 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 27 Aug 2015 12:23:23 +0000 (14:23 +0200)
* fixed sync for contacts that had no image before

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

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

index b6174ae..77fd4f2 100644 (file)
@@ -163,8 +163,6 @@ class Tinebase_User
      */
     public static function getInstance() 
     {
-        $backendType = self::getConfiguredBackend();
-        
         if (self::$_instance === NULL) {
             $backendType = self::getConfiguredBackend();
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .' accounts backend: ' . $backendType);
@@ -436,8 +434,6 @@ class Tinebase_User
     {
         if ($username instanceof Tinebase_Model_FullUser) {
             $username = $username->accountLoginName;
-        } else {
-            $username = $username;
         }
         
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . "  sync user data for: " . $username);
@@ -462,8 +458,8 @@ class Tinebase_User
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' 
             . print_r($user->toArray(), TRUE));
         
-        $group = self::getPrimaryGroupForUser($user);
-        
+        self::getPrimaryGroupForUser($user);
+
         try {
             $currentUser = $userBackend->getUserByProperty('accountId', $user, 'Tinebase_Model_FullUser');
         
@@ -536,26 +532,31 @@ class Tinebase_User
         }
         
         $addressbook = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
-        
+
         try {
             $contact = $addressbook->getByUserId($syncedUser->getId());
             $originalContact = clone $contact;
-            
+
             Tinebase_User::getInstance()->updateContactFromSyncBackend($syncedUser, $contact);
             $contact = self::_user2Contact($syncedUser, $contact);
-            
-            // TODO allow to diff jpegphoto, too
+
+            if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__
+                . print_r($syncedUser->toArray(), true)
+                . ' new: ' . print_r($contact->toArray(), true)
+                . ' orig:' . print_r($originalContact->toArray(), true));
+
+            // TODO allow to diff jpegphoto, too / maybe this should only be done when called via CLI/cronjob
             $diff = $contact->diff($originalContact, array('jpegphoto'));
-            if (! $diff->isEmpty()) {
+            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);
-                
+
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
                     . ' Updating contact data for user ' . $syncedUser->accountLoginName);
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
                     . ' Diff: ' . print_r($diff->toArray(), true));
-                
+
                 $addressbook->update($contact);
             } else {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
@@ -592,7 +593,7 @@ class Tinebase_User
                     throw new Tinebase_Exception('Primary group ' . $user->accountPrimaryGroup . ' not found in sync backend.');
                 }
                 try {
-                    $sqlGgroup = $groupBackend->getGroupByName($group->name);
+                    $groupBackend->getGroupByName($group->name);
                     throw new Tinebase_Exception('Group already exists but it has a different ID: ' . $group->name);
         
                 } catch (Tinebase_Exception_Record_NotDefined $tern) {