From e1c77938dfde4a0e871c9fcfdf599ea064ae7d45 Mon Sep 17 00:00:00 2001 From: magentix Date: Thu, 1 Aug 2024 11:12:07 +0200 Subject: [PATCH 1/2] AMC-479: Reset product UUID when URL has been updated --- Helper/Import/Product.php | 25 ++++++++++++++++++++++++- Job/Product.php | 39 +++++++++++++++++++++++++++++++++++++++ etc/di.xml | 4 ++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/Helper/Import/Product.php b/Helper/Import/Product.php index 6798e4cf..e4451ef5 100755 --- a/Helper/Import/Product.php +++ b/Helper/Import/Product.php @@ -12,6 +12,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\FlagManager; use Magento\Framework\DB\Select; use Magento\Framework\Serialize\Serializer\Json; use Zend_Db_Expr as Expr; @@ -71,8 +72,11 @@ class Product extends Entities * @var ScopeConfigInterface $scopeConfig */ protected $scopeConfig; + protected Authenticator $authenticator; + protected FlagManager $flagManager; + /** * Product constructor * @@ -84,6 +88,7 @@ class Product extends Entities * @param Authenticator $authenticator * @param Json $jsonSerializer * @param ScopeConfigInterface $scopeConfig + * @param FlagManager $flagManager */ public function __construct( ResourceConnection $connection, @@ -93,13 +98,31 @@ public function __construct( ConfigHelper $configHelper, Authenticator $authenticator, Json $jsonSerializer, - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + FlagManager $flagManager ) { parent::__construct($connection, $deploymentConfig, $product, $configHelper, $authenticator); $this->jsonSerializer = $jsonSerializer; $this->productUrlPathGenerator = $productUrlPathGenerator; $this->scopeConfig = $scopeConfig; + $this->flagManager = $flagManager; + } + + public function isNeedResetUuid(): bool + { + $lastBaseUrl = (string)$this->flagManager->getFlagData('akeneo_last_import_base_url'); + + if ($this->configHelper->getAkeneoApiBaseUrl() !== $lastBaseUrl) { + return true; + } + + return false; + } + + public function setLastImportBaseUrl(string $baseUrl): void + { + $this->flagManager->saveFlag('akeneo_last_import_base_url', $baseUrl); } /** diff --git a/Job/Product.php b/Job/Product.php index deb79840..ceb068a1 100644 --- a/Job/Product.php +++ b/Job/Product.php @@ -409,6 +409,45 @@ public function __construct( } } + /** + * We need to reset the product UUID when the PIM instance URL has been updated since the last import + * + * @return void + */ + public function resetUuid(): void + { + if (!$this->entitiesHelper->isProductUuidEdition()) { + $this->jobExecutor->setMessage(__('Akeneo version does not use UUIDs'), $this->logger); + return; + } + + if (!$this->entitiesHelper->isNeedResetUuid()) { + $this->jobExecutor->setMessage(__('There is no need to reset the UUID'), $this->logger); + return; + } + + $connection = $this->entitiesHelper->getConnection(); + + $select = $connection->select() + ->from(false, ['code' => 'cpe.sku'])->joinInner( + ['cpe' => $this->entitiesHelper->getTable('catalog_product_entity')], + 'cpe.entity_id = ace.entity_id', + [] + ) + ->where('ace.import = ?', 'product'); + + $connection->query( + $connection->updateFromSelect( + $select, + ['ace' => $this->entitiesHelper->getTable('akeneo_connector_entities')] + ) + ); + + $this->entitiesHelper->setLastImportBaseUrl($this->configHelper->getAkeneoApiBaseUrl()); + + $this->jobExecutor->setMessage(__('Product UUID has been reset'), $this->logger); + } + /** * Create temporary table * diff --git a/etc/di.xml b/etc/di.xml index 98e02b47..6ee070f6 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -248,6 +248,10 @@ + + resetUuid + Reset UUID + createTable Create temporary table From 58c2cfaa88a9d9ea18ca020ed80efea10ed3bd31 Mon Sep 17 00:00:00 2001 From: magentix Date: Thu, 1 Aug 2024 11:15:13 +0200 Subject: [PATCH 2/2] Bump to 104.3.10 --- CHANGELOG.md | 3 +++ composer.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15331c97..248983ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -496,3 +496,6 @@ * Only remove products from categories managed in Akeneo * Optimize media import * Only fill completeness when we have products + +### Version 104.3.10 : +* AMC-479: Reset product UUID when URL has been updated diff --git a/composer.json b/composer.json index ada46351..30d1f4ac 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "nyholm/psr7": "^1.5" }, "type": "magento2-module", - "version": "104.3.9", + "version": "104.3.10", "license": [ "OSL-3.0", "AFL-3.0"