From bbc94feb962e1939c68f55754c09bbf5b7b29d7d Mon Sep 17 00:00:00 2001 From: Robin Guillou Date: Mon, 7 Oct 2019 10:35:35 +0200 Subject: [PATCH 1/2] option: change separator, preventing attribute confusion while replacing option code by entity_id, add legacy update --- .../Pimgento/Api/Model/Job/Product.php | 2 +- .../Pimgento/Api/Model/Resource/Entities.php | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/code/community/Pimgento/Api/Model/Job/Product.php b/app/code/community/Pimgento/Api/Model/Job/Product.php index d795359..f15e706 100644 --- a/app/code/community/Pimgento/Api/Model/Job/Product.php +++ b/app/code/community/Pimgento/Api/Model/Job/Product.php @@ -633,7 +633,7 @@ public function updateOption($task) $columnParts = explode('-', $column, 2); /** @var string $columnPrefix */ $columnPrefix = reset($columnParts); - $columnPrefix = sprintf('%s_', $columnPrefix); + $columnPrefix = sprintf('%s-', $columnPrefix); /** @var int $prefixLength */ $prefixLength = strlen($columnPrefix) + 1; /** @var string $entitiesTable */ diff --git a/app/code/community/Pimgento/Api/Model/Resource/Entities.php b/app/code/community/Pimgento/Api/Model/Resource/Entities.php index b5bbfc0..f776063 100644 --- a/app/code/community/Pimgento/Api/Model/Resource/Entities.php +++ b/app/code/community/Pimgento/Api/Model/Resource/Entities.php @@ -502,7 +502,16 @@ public function matchEntity($entityCode, $entityTableAlias, $primaryKey, $prefix /** @var string $entityCodeColumnName */ $entityCodeColumnName = sprintf('t.`%s`', $entityCode); if ($prefix !== '') { - $entityCodeColumnName = sprintf('CONCAT(t.`%s`, "_", t.`%s`)', $prefix, $entityCode); + /* Use new error-free separator */ + $entityCodeColumnName = sprintf('CONCAT(t.`%s`, "-", t.`%s`)', $prefix, $entityCode); + + /* Legacy: update columns still using former "_" separator */ + /** @var string $oldEntityCodeColumnName */ + $oldEntityCodeColumnName = sprintf('CONCAT(t.`%s`, "_", t.`%s`)', $prefix, $entityCode); + /** @var string $update */ + $update = 'UPDATE `' . $pimgentoTable . '` AS `e`, `' . $tableName . '` AS `t` SET e.code = ' . $entityCodeColumnName . ' WHERE e.code = ' . $oldEntityCodeColumnName; + + $adapter->query($update); } /* Update entity_id column from pimgento_entities table */ @@ -560,9 +569,9 @@ public function matchEntity($entityCode, $entityTableAlias, $primaryKey, $prefix /** @var string $maxCode */ $maxCode = $adapter->fetchOne( $adapter->select()->from($pimgentoTable, new Zend_Db_Expr(sprintf('MAX(`%s`)', $entitiesIdFieldName)))->where( - 'import = ?', - $import - ) + 'import = ?', + $import + ) ); /** @var string $maxEntity */ $maxEntity = $adapter->fetchOne( From d4328c732881e7b076353c123fcc82f4d60e7956 Mon Sep 17 00:00:00 2001 From: Robin Guillou Date: Mon, 7 Oct 2019 11:58:57 +0200 Subject: [PATCH 2/2] option: fix import code in legacy update where --- app/code/community/Pimgento/Api/Model/Resource/Entities.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Pimgento/Api/Model/Resource/Entities.php b/app/code/community/Pimgento/Api/Model/Resource/Entities.php index f776063..9fd147b 100644 --- a/app/code/community/Pimgento/Api/Model/Resource/Entities.php +++ b/app/code/community/Pimgento/Api/Model/Resource/Entities.php @@ -509,7 +509,7 @@ public function matchEntity($entityCode, $entityTableAlias, $primaryKey, $prefix /** @var string $oldEntityCodeColumnName */ $oldEntityCodeColumnName = sprintf('CONCAT(t.`%s`, "_", t.`%s`)', $prefix, $entityCode); /** @var string $update */ - $update = 'UPDATE `' . $pimgentoTable . '` AS `e`, `' . $tableName . '` AS `t` SET e.code = ' . $entityCodeColumnName . ' WHERE e.code = ' . $oldEntityCodeColumnName; + $update = 'UPDATE `' . $pimgentoTable . '` AS `e`, `' . $tableName . '` AS `t` SET e.code = ' . $entityCodeColumnName . ' WHERE e.code = ' . $oldEntityCodeColumnName . ' AND e.`import` = "' . $import . '"'; $adapter->query($update); }