Ejemplo n.º 1
0
 /**
  * Saves changes made to the identity.
  * 
  * @api
  * 
  * @param CIdentity &$oIdentity Identity object containing data to be saved.
  * 
  * @return bool
  */
 public function updateIdentity(CIdentity &$oIdentity)
 {
     $bResult = false;
     try {
         if ($oIdentity->isValid()) {
             $bUseOnlyHookUpdate = false;
             CApi::Plugin()->RunHook('api-update-identity', array(&$oIdentity, &$bUseOnlyHookUpdate));
             if ($bUseOnlyHookUpdate) {
             } else {
                 if ($oIdentity->Virtual) {
                     $oAccount = $this->getAccountById($oIdentity->IdAccount);
                     if ($oAccount && $oIdentity->IdUser === $oAccount->IdUser) {
                         $oAccount->FriendlyName = $oIdentity->FriendlyName;
                         $oAccount->Signature = $oIdentity->Signature;
                         $oAccount->SignatureType = $oIdentity->SignatureType;
                         $oAccount->SignatureOptions = $oIdentity->UseSignature ? EAccountSignatureOptions::AddToAll : EAccountSignatureOptions::DontAdd;
                         $bResult = $this->updateAccount($oAccount);
                     }
                 } else {
                     if ($this->oStorage->updateIdentity($oIdentity)) {
                         if ($oIdentity->Default) {
                             $this->oStorage->updateIdentitiesDefaults($oIdentity->IdIdentity, $oIdentity->IdAccount);
                         }
                     } else {
                         $this->moveStorageExceptionToManager();
                         throw new CApiManagerException(Errs::UserManager_IdentityUpdateFailed);
                     }
                 }
             }
         }
         $bResult = true;
     } catch (CApiBaseException $oException) {
         $bResult = false;
         $this->setLastException($oException);
     }
     return $bResult;
 }