Kaynağa Gözat

#100 - Delete with content.

AntonLV 11 yıl önce
ebeveyn
işleme
f9e3ba3e8c

+ 12 - 8
modules/base/general/classes/BxBaseModGeneralGridAdministration.php

@@ -35,12 +35,6 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
 
-    	//TODO: remove this check when 'delete with content' feature will be realized in onDelete method.
-    	if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
-			$this->_echoResultJson(array('msg' => 'TODO: delete with content'));
-	    	return;
-    	}
-
         $iAffected = 0;
         $aIds = bx_get('ids');
         if(!$aIds || !is_array($aIds)) {
@@ -50,11 +44,11 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
 
         $aIdsAffected = array ();
         foreach($aIds as $iId) {
-			$aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
+			$aContentInfo = $this->_getContentInfo($iId);
 	    	if($this->_oModule->checkAllowedDelete($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
 	    		continue;
 
-        	if($this->_oModule->serviceDeleteEntity($iId) != '')
+        	if(!$this->_doDelete($iId, $aParams))
                 continue;
 
 			if(!$this->_onDelete($iId, $aParams))
@@ -132,6 +126,16 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
         return $oForm->genRow($aInputSearch);
     }
 
+	protected function _getContentInfo($iId)
+    {
+    	return $this->_oModule->_oDb->getContentInfoById($iId);
+    }
+
+	protected function _doDelete($iId, $aParams = array())
+    {
+    	return $this->_oModule->serviceDeleteEntity($iId) == '';
+    }
+
     protected function _onDelete($iId, $aParams = array())
     {
     	return true;

+ 17 - 7
modules/base/profile/classes/BxBaseModProfileGridAdministration.php

@@ -92,8 +92,13 @@ class BxBaseModProfileGridAdministration extends BxBaseModGeneralGridAdministrat
 
     protected function _enable ($mixedId, $isChecked)
     {
-    	$iAction = BX_PROFILE_ACTION_MANUAL;
     	$oProfile = $this->_getProfileObject($mixedId);
+
+    	bx_import('BxDolProfileUndefined');
+    	if($oProfile instanceof BxDolProfileUndefined)
+    		return false;
+
+		$iAction = BX_PROFILE_ACTION_MANUAL;
     	return $isChecked ? $oProfile->activate($iAction) : $oProfile->suspend($iAction);
     }
 
@@ -151,15 +156,20 @@ class BxBaseModProfileGridAdministration extends BxBaseModGeneralGridAdministrat
     	return $this->_getProfileObject($iId)->id();
     }
 
-    protected function _onDelete($iId, $aParams = array())
+	protected function _doDelete($iId, $aParams = array())
     {
-    	if(isset($aParams['with_content']) && $aParams['with_content'] === true)	{
-			//TODO: delete content after profile deletion
-		}
+    	if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
+    		$oProfile = $this->_getProfileObject($iId);
+
+    		bx_import('BxDolProfileUndefined');
+    		if($oProfile instanceof BxDolProfileUndefined)
+    			return false;
+
+	    	return $oProfile->delete($oProfile->id(), true);
+    	}
 
-		return parent::_onDelete($iId, $aParams);
+    	return parent::_doDelete($iId, $aParams);
     }
-    
 }
 
 /** @} */

+ 8 - 47
modules/boonex/accounts/classes/BxAccntGridAdministration.php

@@ -54,48 +54,6 @@ class BxAccntGridAdministration extends BxBaseModProfileGridAdministration
 		$this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_perform'])));
     }
 
-    public function performActionDelete($aParams = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	//TODO: remove this check when 'delete with content' feature will be realized in onDelete method.
-    	if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
-			$this->_echoResultJson(array('msg' => 'TODO: delete with content'));
-	    	return;
-    	}
-
-        $aIds = bx_get('ids');
-        if(!$aIds || !is_array($aIds)) {
-            $this->_echoResultJson(array());
-            exit;
-        }
-
-        bx_import('BxDolAccount');        
-
-        $iAffected = 0;
-        $aIdsAffected = array ();
-        foreach($aIds as $iId) {
-        	$oAccount = BxDolAccount::getInstance($iId);
-
-			$aAccount = $oAccount->getInfo();
-	    	if($this->_oModule->checkAllowedDelete($aAccount) !== CHECK_ACTION_RESULT_ALLOWED)
-	    		continue;
-
-        	if(!$oAccount->delete())
-                continue;
-
-			if(!$this->_onDelete($iId, $aParams))
-				continue;
-
-			$this->_oModule->checkAllowedDelete($aAccount, true);
-
-            $aIdsAffected[] = $iId;
-            $iAffected++;
-        }
-
-        $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_delete'])));
-    }
-
 	protected function _performActionEnable($isChecked)
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
@@ -148,13 +106,16 @@ class BxAccntGridAdministration extends BxBaseModProfileGridAdministration
         return false;
     }
 
-	protected function _onDelete($iId, $aParams = array())
+	protected function _getContentInfo($iId)
     {
-    	if(isset($aParams['with_content']) && $aParams['with_content'] === true)	{
-			//TODO: delete content after profile deletion
-		}
+    	bx_import('BxDolAccount');
+    	return BxDolAccount::getInstance($iId)->getInfo();
+    }
 
-		return parent::_onDelete($iId, $aParams);
+	protected function _doDelete($iId, $aParams = array())
+    {
+    	bx_import('BxDolAccount');
+    	return BxDolAccount::getInstance($iId)->delete(isset($aParams['with_content']) && $aParams['with_content'] === true);
     }
 }