Skip to content

Commit

Permalink
tweak(Tinebase/User/Ldap): do not update user if not necessary
Browse files Browse the repository at this point in the history
... add n_fileas to fields to omit
  • Loading branch information
pschuele committed Jul 4, 2024
1 parent 292870a commit 22a2ac9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
19 changes: 15 additions & 4 deletions tine20/Addressbook/Controller/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1367,9 +1367,13 @@ public function inspectUpdateUser(Tinebase_Model_FullUser $_updatedUser, Tinebas
}
}

$diff = $contact->diff($oldContact, $syncPhoto ? array('n_fn') : array('jpegphoto', 'n_fn'));
$omitFields = ['n_fn', 'n_fileas'];
if (! $syncPhoto) {
$omitFields[] = 'jpegphoto';
}
/** @var Tinebase_Model_Diff $diff */
$diff = $contact->diff($oldContact, $omitFields);
if (! $diff->isEmpty() || ($oldContact->jpegphoto === 0 && !empty($contact->jpegphoto))) {

$oldContext = $this->_requestContext;
if (!is_array($this->_requestContext)) {
$this->_requestContext = array();
Expand All @@ -1378,10 +1382,17 @@ public function inspectUpdateUser(Tinebase_Model_FullUser $_updatedUser, Tinebas
$this->_requestContext[self::CONTEXT_NO_ACCOUNT_UPDATE] = true;
}

if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(
__METHOD__ . '::' . __LINE__ . " Diff " . print_r($diff->toArray(), true));
}

$this->update($contact, false);

if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
. " updated contact " . $contact->n_given);
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
Tinebase_Core::getLogger()->info(
__METHOD__ . '::' . __LINE__ . " Updated contact " . $contact->n_fn);
}

$this->_requestContext = $oldContext;
}
Expand Down
16 changes: 11 additions & 5 deletions tine20/Tinebase/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,17 +649,19 @@ protected static function _syncDataAndUpdateUser($user, $options)
$currentUser = self::_getLdapUserController()->getUserByProperty('accountId', $user, 'Tinebase_Model_FullUser', true);

if (self::_checkAndUpdateCurrentUser($currentUser, $user, $options)) {
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
. ' Record needs an update');
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
. ' Record needs an update');
}
Tinebase_Timemachine_ModificationLog::setRecordMetaData($currentUser, 'update');
$syncedUser = self::_getLdapUserController()->updateUserInSqlBackend($currentUser);
} else {
$syncedUser = $currentUser;
}

if (! empty($user->container_id)) {
$syncedUser->container_id = $user->container_id;
}

// Addressbook is registered as plugin and will take care of the update
self::_getLdapUserController()->updatePluginUser($syncedUser, $user);

Expand Down Expand Up @@ -719,9 +721,13 @@ protected static function _checkAndUpdateCurrentUser(Tinebase_Model_FullUser $cu
continue;
}
// SYNC NON-EMPTY OPTIONAL or REQUIRED fields
else if ($currentUser->{$field} !== $user->{$field}) {
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
else if ($currentUser->{$field} !== $user->{$field}
&& (! empty($currentUser->{$field}) || ! empty($user->{$field})))
{
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
. ' Diff found in field ' . $field . ' current: ' . $currentUser->{$field} . ' new: ' . $user->{$field});
}
$currentUser->{$field} = $user->{$field};
$recordNeedsUpdate = true;
}
Expand Down

0 comments on commit 22a2ac9

Please sign in to comment.