鍍金池/ 問答/網(wǎng)絡(luò)安全/ Magento 首頁報(bào)錯(cuò)

Magento 首頁報(bào)錯(cuò)

  • 最近接手 Magento 項(xiàng)目以前沒接觸過,結(jié)果今天看錯(cuò)誤報(bào)告一大推相同的錯(cuò)誤:(請問這是什么原因要如何解決)求大神
a:5:{i:0;s:242:"Error in file: "/data/wwwroot/shop/app/code/local/SeventhSense/ZimmerliEmailTemplates/data/seventhsense_zimmerliemailtemplates_setup/data-install-0.1.0.0.php" - A block identifier with the same properties already exists in the selected store.";i:1;s:810:"#0 /data/wwwroot/shop/app/code/core/Mage/Core/Model/Resource/Setup.php(645): Mage::exception('Mage_Core', 'Error in file: ...')
#1 /data/wwwroot/shop/app/code/core/Mage/Core/Model/Resource/Setup.php(391): Mage_Core_Model_Resource_Setup->_modifyResourceDb('data-install', '', '0.1.0.0')
#2 /data/wwwroot/shop/app/code/core/Mage/Core/Model/Resource/Setup.php(289): Mage_Core_Model_Resource_Setup->_installData('0.1.0.0')
#3 /data/wwwroot/shop/app/code/core/Mage/Core/Model/Resource/Setup.php(269): Mage_Core_Model_Resource_Setup->applyDataUpdates()
#4 /data/wwwroot/shop/app/code/core/Mage/Core/Model/App.php(351): Mage_Core_Model_Resource_Setup::applyAllDataUpdates()
#5 /data/wwwroot/shop/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#6 /data/wwwroot/shop/index.php(107): Mage::run('', 'store')
#7 {main}";s:3:"url";s:26:"/index.php/api/soap/index/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
回答
編輯回答
薔薇花
  • 自答一波
  • 我們提取關(guān)鍵信息:A block identifier with the same properties already exists in the selected store,根據(jù)查閱信息我們查看源碼:
# app\code\core\Mage\Cms\Model\Resource\Block.php
...
protected function _beforeSave(Mage_Core_Model_Abstract $object)
{
    if (!$this->getIsUniqueBlockToStores($object)) {
        Mage::throwException(Mage::helper('cms')->__('A block identifier with the same properties already exists in the selected store.'));
    }
    ...
}
  • 上述這段代碼拋出了我們的錯(cuò)誤信息,那么接下來我們順藤摸瓜查找導(dǎo)致這段錯(cuò)誤信息的方法 getIsUniqueBlockToStores
...
public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object)
{
    if (Mage::app()->isSingleStoreMode()) {
        $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID);
    } else {
        $stores = (array)$object->getData('stores');
    }

    $select = $this->_getReadAdapter()->select()
        ->from(array('cb' => $this->getMainTable()))
        ->join(
            array('cbs' => $this->getTable('cms/block_store')),
            'cb.block_id = cbs.block_id',
            array()
        )->where('cb.identifier = ?', $object->getData('identifier'))
        ->where('cbs.store_id IN (?)', $stores);

    if ($object->getId()) {
        $select->where('cb.block_id <> ?', $object->getId());
    }

    if ($this->_getReadAdapter()->fetchRow($select)) {
        return false;
    }

    return true;
}
...
  • 從以上代碼我們可以發(fā)現(xiàn) Magento 會(huì)進(jìn)行唯一檢查,所以我們只需要根據(jù)自身項(xiàng)目的情況找出可能導(dǎo)致重復(fù)插入 cms_block 表的地方然后做重復(fù)性檢查即可,例如可以像我一樣加入以下判斷:
$Obj_DataBase = Mage::getSingleton('core/resource') -> getConnection('core_read');
$Obj_KeyWords = $Obj_DataBase -> select() -> from('cms_block', [ 'block_id' ]) -> where('identifier=?',$Str_BlockId) -> limit(1);
$Arr_KeyWords = $Obj_DataBase -> fetchAll($Obj_KeyWords);
if( count($Arr_KeyWords) == 0 )
{
    # 判斷重復(fù)性后再進(jìn)行插入
}
2017年8月19日 21:36