Merge branch '2013.10' into 2014.11
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 18 Nov 2015 12:30:39 +0000 (13:30 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 18 Nov 2015 12:30:39 +0000 (13:30 +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;
      }
                      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.');
      }
  
      /**
              . ' About to delete ' . count($deletedInSyncBackend) . ' users in SQL backend...');
  
          foreach ($deletedInSyncBackend as $userToDelete) {
-             Tinebase_User::getInstance()->deleteUserInSqlBackend($userToDelete);
+             $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $userToDelete, 'Tinebase_Model_FullUser');
+             // at first, we expire the user
+             $now = Tinebase_DateTime::now();
+             if (! $user->accountExpires) {
+                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                     . ' Set expiry date to ' . $now);
+                 $user->accountExpires = $now;
+                 Tinebase_User::getInstance()->updateUserInSqlBackend($user);
+             } else {
+                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                     . ' User already expired ' . print_r($user->toArray(), true));
+                 // TODO make time span configurable?
+                 if ($user->accountExpires->isEarlier($now->subYear(1))) {
+                     // if he or she is already expired longer than configured expiry, we remove them!
+                     Tinebase_User::getInstance()->deleteUserInSqlBackend($userToDelete);
+                     if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true && ! empty($user->contact_id)) {
+                         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                             . ' Deleting user contact of ' . $user->accountLoginName);
+                         $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
+                         $contactsBackend->delete($user->contact_id);
+                     }
+                 } else {
+                     // keep user in expiry state
+                 }
+             }
          }
      }
  
          // 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);