我遇到了MySQL中行限制的问题,因为Magento安装中的属性数量很多,因此我将扩展“Mage_Catalog_Model_Resource_Product_Flat_Indexer”类的扩展组合在一起,使用以下代码将char限制重写为64。
protected function _MySQLCharLimit()
{
if (!$this->_isFlatTableExists($store)) {
$sql = "CREATE TABLE {$tableNameQuote} (n";
foreach ( $columns as $field => $fieldProp ) {
if ( $fieldProp['type'] == "varchar(255)" )
$fieldProp['type'] = "varchar(64)";
$sql .= sprintf( " %s,n",
$this->_sqlColunmDefinition( $field, $fieldProp ) );
}
foreach ($addIndexes as $indexName => $indexProp) {
$sql .= sprintf(' ADD %s,',
$this->_sqlIndexDefinition( $indexName, $indexProp ) );
}
$sql = rtrim($sql, ",");
$sql = str_replace( "varchar(255)","varchar(64)",$sql );
$this->_getWriteAdapter()->query( $sql );
}
}
我从这里得到http://www.sonassi.com/knowledge-base/magento-kb/mysql-limitations-on-the-flat-catalogue-in-magento/。
在尝试重新索引后,我注意到它将我发送到一个空白页面,当我点击回来时,“产品平面数据”索引一直停留在处理上。
我通过SSH从'shell'文件夹运行了indexer.php,它报告了这个错误:
PHP致命错误:在第296行的Mage / Catalog / Model / Product / Flat / Indexer.php中的非对象上调用成员函数reindexAll()
有没有人知道出了什么问题或者我怎么能纠正这个问题?感谢。
编辑:完整代码
<?php
class GDModules_MySQLCharLimit_Catalog_Model_Resource_Product_Flat_Indexer extends Mage_Catalog_Model_Resource_Product_Flat_Indexer
{
public function mySQLCharLimit()
{
if (!$this->_isFlatTableExists($store)) {
$sql = "CREATE TABLE {$tableNameQuote} (n";
foreach ( $columns as $field => $fieldProp ) {
if ( $fieldProp['type'] == "varchar(255)" )
$fieldProp['type'] = "varchar(64)";
$sql .= sprintf( " %s,n",
$this->_sqlColunmDefinition( $field, $fieldProp ) );
}
foreach ($addIndexes as $indexName => $indexProp) {
$sql .= sprintf(' ADD %s,',
$this->_sqlIndexDefinition( $indexName, $indexProp ) );
}
$sql = rtrim($sql, ",");
$sql = str_replace( "varchar(255)","varchar(64)",$sql );
$this->_getWriteAdapter()->query( $sql );
}
}
}
XML
<?xml version="1.0" encoding="UTF-8"?>
<!-- The root node for Magento module configuration -->
<config>
<!--
The module's node contains basic
information about each Magento module
-->
<modules>
<!--
This must exactly match the namespace and module's folder
names, with directory separators replaced by underscores
-->
<GDModules_MySQLCharLimit>
<!-- The version of our module, starting at 0.0.1 -->
<version>0.0.1</version>
</GDModules_MySQLCharLimit>
</modules>
<!-- Configure our module's behaviour in the global scope -->
<global>
<!-- Defining models -->
<models>
<catalog_resource>
<rewrite>
<product_flat_indexer>GDModules_MySQLCharLimit_Catalog_Model_Resource_Product_Flat_Indexer</product_flat_indexer>
</rewrite>
</catalog_resource>
</models>
</global>
</config>