Skip to content

Commit

Permalink
Merge pull request #702 from akeneo/release/104.3.10
Browse files Browse the repository at this point in the history
Release/104.3.10
  • Loading branch information
magentix authored Aug 1, 2024
2 parents 9fa9747 + 58c2cfa commit a7c064f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 24 additions & 1 deletion Helper/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,8 +72,11 @@ class Product extends Entities
* @var ScopeConfigInterface $scopeConfig
*/
protected $scopeConfig;

protected Authenticator $authenticator;

protected FlagManager $flagManager;

/**
* Product constructor
*
Expand All @@ -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,
Expand All @@ -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);
}

/**
Expand Down
39 changes: 39 additions & 0 deletions Job/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@
<arguments>
<argument name="data" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="0" xsi:type="array">
<item name="method" xsi:type="string">resetUuid</item>
<item name="comment" xsi:type="string">Reset UUID</item>
</item>
<item name="1" xsi:type="array">
<item name="method" xsi:type="string">createTable</item>
<item name="comment" xsi:type="string">Create temporary table</item>
Expand Down

0 comments on commit a7c064f

Please sign in to comment.