Merge branch '2013.10' into 2014.11
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 4 Jan 2016 14:48:40 +0000 (15:48 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 4 Jan 2016 14:48:40 +0000 (15:48 +0100)
1  2 
tine20/Tinebase/User.php

diff --combined tine20/Tinebase/User.php
@@@ -239,7 -239,7 +239,7 @@@ class Tinebase_Use
          }
          
          if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ 
 -            . ' Created user backend of type ' . $backendType);
 +            . ' Created user backend of type ' . get_class($result));
          
          return $result;
      }
              $currentUser->accountEmailAddress       = $user->accountEmailAddress;
              $currentUser->accountHomeDirectory      = $user->accountHomeDirectory;
              $currentUser->accountLoginShell         = $user->accountLoginShell;
+             $currentUser->accountStatus             = isset($user->accountStatus)
+                 ? $user->accountStatus
+                 : Tinebase_Model_User::ACCOUNT_STATUS_ENABLED;
              if (! empty($user->visibility) && $currentUser->visibility !== $user->visibility) {
                  $currentUser->visibility            = $user->visibility;
                  if (empty($currentUser->contact_id) && $currentUser->visibility == Tinebase_Model_FullUser::VISIBILITY_DISPLAYED) {
                      self::createContactForSyncedUser($currentUser);
                  }
              }
 -        
 +            
 +            Tinebase_Timemachine_ModificationLog::setRecordMetaData($currentUser, 'update');
              $syncedUser = $userBackend->updateUserInSqlBackend($currentUser);
              if (! empty($user->container_id)) {
                  $syncedUser->container_id = $user->container_id;
              if ($user->visibility !== Tinebase_Model_FullUser::VISIBILITY_HIDDEN) {
                  self::createContactForSyncedUser($user);
              }
 +            Tinebase_Timemachine_ModificationLog::setRecordMetaData($user, 'create');
              $syncedUser = $userBackend->addUserInSqlBackend($user);
              $userBackend->addPluginUser($syncedUser, $user);
          }
          
          self::syncContactData($syncedUser, $options);
          
 -        // sync group memberships
          Tinebase_Group::syncMemberships($syncedUser);
 -        
 +
          return $syncedUser;
      }
 -    
 +
      /**
 -     * import contactdata(phone, address, fax, birthday. photo)
 +     * import contact data(phone, address, fax, birthday. photo)
       * 
       * @param Tinebase_Model_FullUser $syncedUser
       * @param array $options
              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 ($contact->container_id !== null) {
 +                    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__
          } catch (Addressbook_Exception_NotFound $aenf) {
              self::createContactForSyncedUser($syncedUser);
              $syncedUser = Tinebase_User::getInstance()->updateUserInSqlBackend($syncedUser);
 +
          } catch (Tinebase_Exception_NotFound $tenf) {
              if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
                  . ' Contact information seems to be missing in sync backend');
              self::_syncDeletedUsers($users);
          }
          
 -        // @todo this should be improved: only the cache of synced users + group memberships should be cleaned
 -        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ 
 -            . ' Finished synchronizing users. Clearing cache after user sync ...');
 -        Tinebase_Core::getCache()->clean();
 +        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
 +            . ' Finished synchronizing users.');
      }
  
      /**
                  return;
              }
  
-             // at first, we expire the user
+             // at first, we expire+deactivate the user
              $now = Tinebase_DateTime::now();
-             if (! $user->accountExpires) {
+             if (! $user->accountExpires || $user->accountStatus !== Tinebase_Model_User::ACCOUNT_STATUS_DISABLED) {
                  if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
-                     . ' Set expiry date of ' . $user->accountLoginName . ' to ' . $now);
+                     . ' Disable user and set expiry date of ' . $user->accountLoginName . ' to ' . $now);
                  $user->accountExpires = $now;
+                 $user->accountStatus = Tinebase_Model_User::ACCOUNT_STATUS_DISABLED;
                  Tinebase_User::getInstance()->updateUserInSqlBackend($user);
              } else {
                  if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
  
          $user = new Tinebase_Model_FullUser(array(
              'accountLoginName'      => $adminLoginName,
-             'accountStatus'         => 'enabled',
+             'accountStatus'         => Tinebase_Model_User::ACCOUNT_STATUS_ENABLED,
              'accountPrimaryGroup'   => $userGroup->getId(),
              'accountLastName'       => $adminLastName,
              'accountDisplayName'    => $adminLastName . ', ' . $adminFirstName,
          // update or create user in local sql backend
          try {
              $userBackend->getUserByProperty('accountLoginName', $adminLoginName);
 +            Tinebase_Timemachine_ModificationLog::setRecordMetaData($user, 'update');
              $user = $userBackend->updateUserInSqlBackend($user);
          } catch (Tinebase_Exception_NotFound $ten) {
              // call addUser here to make sure, sql user plugins (email, ...) are triggered
 +            Tinebase_Timemachine_ModificationLog::setRecordMetaData($user, 'create');
              $user = $userBackend->addUser($user);
          }
          
          // set the password for the account
 -        Tinebase_User::getInstance()->setPassword($user, $adminPassword);
 +        // empty password triggers password change dialogue during first login
 +        if (!empty($adminPassword)) {
 +            Tinebase_User::getInstance()->setPassword($user, $adminPassword);
 +        }
  
          // add the admin account to all groups
          Tinebase_Group::getInstance()->addGroupMember($adminGroup, $user);