avstudnitz / AvS_FastSimpleImport

Wrapper for Magento ImportExport functionality, which imports products and customers from arrays
306 stars 146 forks source link

FastSimpleImport cannot get autoincrement value of catalog_product_link #442

Closed Chimera16 closed 4 years ago

Chimera16 commented 4 years ago

Hello everyone,

I have the latest fastsimpleimport extension and use the latest Magento1 Version (1.9.4.3). I create a new installation of Magento to make sure the database isn't corrupted. After that I run an product import. I receive the error "Cannot get autoincrement value".

The issue appears in file "app\code\core\Mage\ImportExport\Model\Resource\Helper\Mysql4.php". To identify the problem I have printed the $entityStatus of the function getNextAutoincrement. This is what I received: Array ( [Name] => catalog_product_link [Engine] => InnoDB [Version] => 10 [Row_format] => Dynamic [Rows] => 0 [Avg_row_length] => 0 [Data_length] => 16384 [Max_data_length] => 0 [Index_length] => 65536 [Data_free] => 0 [Auto_increment] => [Create_time] => 2019-12-05 04:52:41 [Update_time] => [Check_time] => [Collation] => utf8_general_ci [Checksum] => [Create_options] => [Comment] => Catalog Product To Product Linkage Table )

To summarize my issue: I cannot import any product Data with FastSimpleImport, because the extension is unable to get the autoincrement value of my catalog_product_link table. I have checked the table inside MySQL, a autoincrement value is set. I have even created products with cross selling manually to get a new autoincrement value set to the table, but the problem remains...

Any help would appreciated, thanks in advance!

Chimera16 commented 4 years ago

I was able to solve my issue. The reason for this issue is, that I'm using MySQL Server 8 while Magento1 does not official support it.

To get this extension to work with MySQL Server 8 you have to change 2 things:

  1. On the MySQL server change the paramter "information_schema_stats_expiry" global to "0". I was unable to do this with the my.ini file or with commands. The solution was to set the parameter inside the MySQL Workbench.

  2. Edit the FastSimpleImport file "app\code\core\Mage\ImportExport\Model\Resource\Helper\Mysql4.php". Look for the "getNextAutoincrement" function inside it, and change the content of it like this:

    public function getNextAutoincrement($tableName)
    {
    $resource = Mage::getSingleton('core/resource');
    $readConnection = $resource->getConnection('core_read');
    $writeConnection = $resource->getConnection('core_write');
    
    $query = "SELECT AUTO_INCREMENT FROM  INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND   TABLE_NAME   = '".$resource->getTableName($tableName)."';";
    $results = $readConnection->fetchAll($query);
    
    $entityStatus['Auto_increment']=$results[0]['AUTO_INCREMENT'];
    
    if (empty($entityStatus['Auto_increment'])) {
       $query = 'SELECT count(*) AS rowcount FROM ' . $resource->getTableName($tableName);
       $results = $readConnection->fetchAll($query);
       $rowcount=$results[0]['rowcount'];
       if ($rowcount == "0") {
          $entityStatus['Auto_increment']="1";
       } else {
          Mage::throwException(Mage::helper('importexport')->__('Cannot get autoincrement value'));
       }
    }
    return $entityStatus['Auto_increment'];
    }

After you have done these steps, FastSimpleImport should work with Magento1 and MySQL Server 8.