Exemple #1
0
 /**
  * Deletes account from WebMail Pro database. 
  * 
  * @param CAccount $oAccount Object instance with prepopulated account properties.
  * 
  * @return bool
  */
 public function deleteAccount($iAccountId)
 {
     $bResult = false;
     if ($this->oConnection->Execute($this->oCommandCreator->getAccountInfoQuery($iAccountId))) {
         $oRow = $this->oConnection->GetNextRecord();
         if ($oRow) {
             $bIsDefaultAccount = (bool) $oRow->def_acct;
             $bIsMailingList = (bool) $oRow->mailing_list;
             $iUserId = (int) $oRow->id_user;
             $this->oConnection->FreeResult();
             if ($bIsMailingList) {
                 $bResult = $this->oConnection->Execute($this->oCommandCreator->deleteAccountQuery($iAccountId));
                 $bResult &= $this->oConnection->Execute($this->oCommandCreator->clearMailingListMembersQuery($iAccountId));
             } else {
                 $bResult = false;
                 if ($bIsDefaultAccount) {
                     $aAccountsId = $this->getAccountIdList($iUserId);
                     if (is_array($aAccountsId) && 0 < count($aAccountsId)) {
                         $bResult = true;
                         foreach ($aAccountsId as $iAccountIdItem) {
                             $bResult &= $this->_deleteAccountRequests($iAccountIdItem);
                         }
                         // Webmail
                         $bResult &= $this->oConnection->Execute($this->oCommandCreator->deleteUserQuery($iUserId));
                         $bResult &= $this->oConnection->Execute($this->oCommandCreator->deleteAUserQuery($iUserId));
                         $bResult &= $this->oConnection->Execute($this->oCommandCreator->deleteSendersQuery($iUserId));
                         $bResult &= $this->oConnection->Execute($this->oCommandCreator->deleteIdentitiesByUserIdQuery($iUserId));
                         // Calendar
                         $bResult &= $this->oConnection->Execute($this->oCommandCreator->deleteCalendarEventsQuery($iUserId));
                         $bResult &= $this->oConnection->Execute($this->oCommandCreator->deleteCalendarsQuery($iUserId));
                         $bResult &= $this->oConnection->Execute($this->oCommandCreator->deleteCalendarsDataQuery($iUserId));
                         $bResult &= $this->oConnection->Execute($this->oCommandCreator->deleteCalendarsPublicationsQuery($iUserId));
                         $bResult &= $this->oConnection->Execute($this->oCommandCreator->deleteCalendarsSharingsQuery($iUserId));
                         $this->throwDbExceptionIfExist();
                     }
                 } else {
                     $bResult = $this->_deleteAccountRequests($iAccountId);
                 }
             }
         } else {
             $this->oConnection->FreeResult();
         }
     }
     $this->throwDbExceptionIfExist();
     return (bool) $bResult;
 }