/** * update user * * @param Tinebase_Model_FullUser $_user the user * @param string $_password the new password * @param string $_passwordRepeat the new password again * * @return Tinebase_Model_FullUser */ public function update(Tinebase_Model_FullUser $_user, $_password, $_passwordRepeat) { $this->checkRight('MANAGE_ACCOUNTS'); $oldUser = $this->_userBackend->getUserByProperty('accountId', $_user, 'Tinebase_Model_FullUser'); try { $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb()); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $_user->contact_id = $oldUser->contact_id; $contact = $this->createOrUpdateContact($_user); $_user->contact_id = $contact->getId(); } $user = $this->_userBackend->updateUser($_user); // make sure primary groups is in the list of groupmemberships $groups = array_unique(array_merge(array($user->accountPrimaryGroup), (array) $_user->groups)); Admin_Controller_Group::getInstance()->setGroupMemberships($user, $groups); Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); } catch (Exception $e) { Tinebase_TransactionManager::getInstance()->rollBack(); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString()); } throw $e; } // fire needed events $event = new Admin_Event_UpdateAccount(); $event->account = $user; Tinebase_Event::fireEvent($event); if (!empty($_password) && !empty($_passwordRepeat)) { $this->setAccountPassword($_user, $_password, $_passwordRepeat); } return $user; }
/** * update user * * @param Tinebase_Model_FullUser $_user the user * @param string $_password the new password * @param string $_passwordRepeat the new password again * * @return Tinebase_Model_FullUser */ public function update(Tinebase_Model_FullUser $_user, $_password, $_passwordRepeat) { $this->checkRight('MANAGE_ACCOUNTS'); $oldUser = $this->_userBackend->getUserByProperty('accountId', $_user, 'Tinebase_Model_FullUser'); if ($oldUser->accountLoginName !== $_user->accountLoginName) { $this->_checkLoginNameExistance($_user); } $this->_checkLoginNameLength($_user); $this->_checkPrimaryGroupExistance($_user); if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Update user ' . $_user->accountLoginName); } try { $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb()); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $_user->contact_id = $oldUser->contact_id; $contact = $this->createOrUpdateContact($_user); $_user->contact_id = $contact->getId(); } Tinebase_Timemachine_ModificationLog::setRecordMetaData($_user, 'update', $oldUser); $user = $this->_userBackend->updateUser($_user); // make sure primary groups is in the list of groupmemberships $groups = array_unique(array_merge(array($user->accountPrimaryGroup), (array) $_user->groups)); Admin_Controller_Group::getInstance()->setGroupMemberships($user, $groups); Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); } catch (Exception $e) { Tinebase_TransactionManager::getInstance()->rollBack(); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e); if ($e instanceof Zend_Db_Statement_Exception && preg_match('/Lock wait timeout exceeded/', $e->getMessage())) { throw new Tinebase_Exception_Backend_Database_LockTimeout($e->getMessage()); } throw $e; } // fire needed events $event = new Admin_Event_UpdateAccount(); $event->account = $user; $event->oldAccount = $oldUser; Tinebase_Event::fireEvent($event); if (!empty($_password) && !empty($_passwordRepeat)) { $this->setAccountPassword($_user, $_password, $_passwordRepeat, FALSE); } return $user; }