2015-02-11 80 views
2

我有一個控制器從Mage_Adminhtml_System_StoreController擴展,下面是我改寫動作:在Magento刪除網站無法刪除存儲和商店視圖

public function deleteWebsitePostAction() 
    { 
     $multiWebEnable = Mage::getStoreConfig('web/multi_web_general/multi_web'); 
     $itemId = $this->getRequest()->getParam('item_id'); 

     if (!$model = Mage::getModel('core/website')->load($itemId)) { 
      $this->_getSession()->addError(Mage::helper('core')->__('Unable to proceed. Please, try again')); 
      $this->_redirect('*/*/'); 
      return; 
     } 
     if (!$model->isCanDelete()) { 
      $this->_getSession()->addError(Mage::helper('core')->__('This website cannot be deleted.')); 
      $this->_redirect('*/*/editWebsite', array('website_id' => $model->getId())); 
      return; 
     } 

     $this->_backupDatabase('*/*/editWebsite', array('website_id' => $itemId)); 

     try { 
      $model->delete(); 

      if ($multiWebEnable) { 
       $websiteCode = $model->getCode(); 
       $websiteDir = BP . DS . 'mpshop' . DS . $websiteCode; 
       if (is_dir($websiteDir)) { 
        $objects = scandir($websiteDir); 
        foreach ($objects as $object) { 
         if ($object != "." && $object != "..") { 
          if (filetype($websiteDir . DS . $object) == "dir") { 
           rmdir($websiteDir . DS . $object); 
          } else { 
           unlink($websiteDir . DS . $object); 
          } 
         } 
        } 
        reset($objects); 
        rmdir($websiteDir); 
       } 
      } 

      $this->_getSession()->addSuccess(Mage::helper('core')->__('The website has been deleted.')); 
      $this->_redirect('*/*/'); 
      return; 
     } catch (Mage_Core_Exception $e) { 
      $this->_getSession()->addError($e->getMessage()); 
     } catch (Exception $e) { 
      $this->_getSession()->addException($e, Mage::helper('core')->__('Unable to delete website. Please, try again later.')); 
     } 
     $this->_redirect('*/*/editWebsite', array('website_id' => $itemId)); 
    } 

我想在我的控制器註釋掉此功能,但問題還在那兒。

我對此感到困惑。我需要知道爲什麼會發生這種情況,給我一些建議...... THanks

任何幫助將不勝感激。

回答

2

好,

內心深處的研究後,我認識一個外鍵core_website表和core_storecore_store_group之間失蹤。

這裏的解決方案是下載Magento數據庫修復工具,可以在Magento主頁下載。

希望得到這個幫助。

-1

從管理>系統>緩存管理中禁用緩存 刷新緩存並再次檢查。 您也可以從緩存管理或[root]/var/cache中刪除緩存

+0

我已經做到了。 – 2015-02-11 09:58:49

0

請注意,刪除網站只能從管理面板完成,這就是獨立腳本具有此功能的原因。

(擺在根的/ var文件夾) 這將從一個獨立的文件中刪除您的網站:

require_once('app/Mage.php'); 

umask(0); 
Mage::app('admin'); 
function deleteWebsitePostAction() 
{ 
    try 
    { 
     $sWebsiteId = 'a'; 
     $oWebsite = Mage::getModel('core/website')->load($sWebsiteId); 
     if(!empty($oWebsite->getId())) 
     { 
      $oWebsite->delete(); 
     } 
    } 
    catch(Exception $oException) 
    { 
     Mage::logException($oException); 
    } 
} 
deleteWebsitePostAction(); 

爲了實現這一點在管理面板確保您提交了正確的變量來控制,在這種情況下,我選擇了名稱website_id,這樣你的表單應該有一個地方。

public function deleteWebsitePostAction() 
{ 
    try 
    { 
     $sWebsiteId = $this->getRequest()->getParam('website_id'); 
     $sWebsiteId = 'a'; 
     $oWebsite = Mage::getModel('core/website')->load($sWebsiteId); 
     if(!empty($oWebsite->getId())) 
     { 
      $oWebsite->delete(); 
     } 
     else 
     { 
      $this->_getSession()->addError('Unable to proceed. Please, try again'); 
      $this->_redirect('*/*/'); 
      return; 
     } 
    } 
    catch(Exception $oException) 
    { 
     Mage::logException($oException); 
     $this->_getSession()->addError('Unable to delete website. Please, try again'); 
    } 
} 
+0

嗯,這不是很有幫助。我使用Magento數據庫修復工具,並解決了這個問題,我無法刪除網站的唯一原因是缺少一個外鍵。順便說一句,謝謝你的幫助。 – 2015-03-17 02:34:48