コード例 #1
0
ファイル: Account.php プロジェクト: ThorstenSuckow/conjoon
 /**
  * Sets the is_deleted flag of the account to "0", which basically means that
  * this account is not active anymore. However, in order for older email items
  * to still work properly, folder mappings have to remain, until no
  * item for this account is found in the database. After that, the account may
  * be removed entirely.
  *
  * @param integer $accountId
  * @param integer $userId
  *
  * @return integer The number of accounts deleted.
  */
 public function deleteAccount($accountId, $userId)
 {
     $accountId = (int) $accountId;
     $userId = (int) $userId;
     if ($accountId <= 0 || $userId <= 0) {
         return 0;
     }
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Model_Folder
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Model/Folder.php';
     $folderModel = new Conjoon_Modules_Groupware_Email_Folder_Model_Folder();
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Model_FoldersAccounts
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Model/FoldersAccounts.php';
     $foldersAccounts = new Conjoon_Modules_Groupware_Email_Folder_Model_FoldersAccounts();
     $folders = $foldersAccounts->getFolderIdsForAccountId($accountId);
     // check if account is of type "root" or
     // if account is of type "root_remote"
     if ($folderModel->getRootFolderId($accountId, $userId) || $folderModel->getRootRemoteFolderId($accountId, $userId)) {
         // no folders or root - we can remove the account entirely
         $where = $this->getAdapter()->quoteInto('id = ?', $accountId, 'INTEGER');
         $deleted = $this->delete($where);
         if ($deleted) {
             for ($i = 0, $len = count($folders); $i < $len; $i++) {
                 $folderModel->deleteFolder($folders[$i], $userId, false);
             }
         }
         return $deleted;
     } else {
         // no root id. Check if there are any items still in folders
         // belonging to the account. If that is the case, DO NOT remove the
         // account from the data storage
         $res = $this->_removeInformationForAccountIf($accountId, $userId);
         if ($res) {
             return 1;
         } else {
             // update account to is_deleted = 1
             $where = $this->getAdapter()->quoteInto('id = ?', $accountId, 'INTEGER');
             return $this->update(array('is_deleted' => 1), $where);
         }
     }
 }