Sfoglia il codice sorgente

#925 Error when account is deleted with content

Alex Trofimov 8 anni fa
parent
commit
77e4a746fc

+ 4 - 5
inc/classes/BxDolAccount.php

@@ -351,14 +351,13 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
         if (!$oAccountQuery->delete($this->_iAccountID))
             return false;
 
-        // create system event
-        bx_alert('account', 'delete', $this->_iAccountID, 0, array ('delete_with_content' => $bDeleteWithContent));
-
         // unset class instance to prevent creating the instance again
-        $this->_iAccountID = 0;
-        $sClass = get_class($this) . '_' . $this->_iAccountID;
+        $sClass = __CLASS__ . '_' . $this->_iAccountID;
         unset($GLOBALS['bxDolClasses'][$sClass]);
 
+       // create system event
+        bx_alert('account', 'delete', $this->_iAccountID, 0, array ('delete_with_content' => $bDeleteWithContent));
+        
         return true;
     }
 

+ 9 - 3
inc/classes/BxDolAccountQuery.php

@@ -81,10 +81,13 @@ class BxDolAccountQuery extends BxDolDb implements iBxDolSingleton
     /**
      * get account id by id
      */
-    public function getIdById($iId)
+    public function getIdById($iId, $bClearCache = false)
     {
-        $sSql = $this->prepare("SELECT `id` FROM `sys_accounts` WHERE `id` = ? LIMIT 1", $iId);
         $sKey = 'BxDolAccountQuery::getIdById' . $iId;
+        if ($bClearCache)
+            $this->cleanMemory($sKey);
+
+        $sSql = $this->prepare("SELECT `id` FROM `sys_accounts` WHERE `id` = ? LIMIT 1", $iId);
         $bResult = $this->fromMemory($sKey, 'getOne', $sSql);
         if (!$bResult)
             $this->cleanMemory($sKey);
@@ -233,7 +236,10 @@ class BxDolAccountQuery extends BxDolDb implements iBxDolSingleton
     public function delete($iID)
     {
         $sSql = $this->prepare("DELETE FROM `sys_accounts` WHERE `id` = ? LIMIT 1", $iID);
-        return $this->query($sSql);
+        if ($res = $this->query($sSql)) {
+            $this->getIdById($iID, true);
+        }
+        return $res;
     }
 
 	/**

+ 12 - 3
inc/classes/BxDolProfileQuery.php

@@ -158,10 +158,13 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
     /**
      * get profile id by id
      */
-    public function getIdById($iId)
+    public function getIdById($iId, $bClearCache = false)
     {
-        $sSql = $this->prepare("SELECT `id` FROM `sys_profiles` WHERE `id` = ? LIMIT 1", $iId);
         $sKey = 'BxDolProfileQuery::getIdById' . $iId;
+        if ($bClearCache)
+            $this->cleanMemory($sKey);
+        
+        $sSql = $this->prepare("SELECT `id` FROM `sys_profiles` WHERE `id` = ? LIMIT 1", $iId);
         $mixedResult = $this->fromMemory($sKey, 'getOne', $sSql);
         if (!$mixedResult)
             $this->cleanMemory($sKey);
@@ -255,8 +258,14 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
      */
     public function delete($iID)
     {
+        $aInfo = $this->getInfoById($iID);
         $sSql = $this->prepare("DELETE FROM `sys_profiles` WHERE `id` = ? LIMIT 1", $iID);
-        return $this->query($sSql);
+        if ($res = $this->query($sSql)) {
+            $this->getProfileByContentAndType($aInfo['content_id'], $aInfo['type'], true);
+            $this->getCurrentProfileByAccount($aInfo['account_id'], true);
+            $this->getIdById($iID, true);
+        }
+        return $res;
     }
 
     /**