Skip to content

Commit

Permalink
AKM-36: Unexpected fs operations for invalid products (#78)
Browse files Browse the repository at this point in the history
* AKM-36: Unexpected fs operations for invalid products
  • Loading branch information
dxops authored Nov 1, 2022
1 parent 29e75c5 commit 70b7e8f
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 241 deletions.
2 changes: 2 additions & 0 deletions Command/CleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
));

$output->writeln('<info>Fields changes cleanup complete</info>');

return 0;
}

private function deleteRecords(): int
Expand Down
2 changes: 1 addition & 1 deletion Entity/AkeneoSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public function getTokenExpiryDateTime()
return $this->tokenExpiryDateTime;
}

public function setTokenExpiryDateTime(DateTime $tokenExpiryDateTime): self
public function setTokenExpiryDateTime(\DateTime $tokenExpiryDateTime): self
{
$this->tokenExpiryDateTime = $tokenExpiryDateTime;

Expand Down
82 changes: 59 additions & 23 deletions ImportExport/Processor/ProductVariantProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,22 @@ public function process($items)
$parentProduct = $productRepository->findOneBySku($parentSku);
if (!$parentProduct instanceof Product) {
$context->incrementErrorEntriesCount();
$errorMessages = [
$context->addError(
$this->translator->trans(
'oro.akeneo.validator.product_by_sku.not_found',
['%sku%' => $parentSku],
'validators'
),
];
$this->strategyHelper->addValidationErrors($errorMessages, $context);
'oro.akeneo.error',
[
'%error%' => $this->translator->trans(
'oro.akeneo.validator.product_by_sku.not_found',
['%sku%' => $parentSku],
'validators'
),
'%item%' => json_encode(
$context->getValue('rawItemData'),
\JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
),
]
)
);

return null;
}
Expand Down Expand Up @@ -121,15 +129,22 @@ function ($variantSku) {
$variantProduct = $productRepository->findOneBySku($variantSku);
if (!$variantProduct instanceof Product) {
$context->incrementErrorEntriesCount();

$errorMessages = [
$context->addError(
$this->translator->trans(
'oro.akeneo.validator.product_by_sku.not_found',
['%sku%' => $variantSku],
'validators'
),
];
$this->strategyHelper->addValidationErrors($errorMessages, $context);
'oro.akeneo.error',
[
'%error%' => $this->translator->trans(
'oro.akeneo.validator.product_by_sku.not_found',
['%sku%' => $variantSku],
'validators'
),
'%item%' => json_encode(
$context->getValue('rawItemData'),
\JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
),
]
)
);

continue;
}
Expand All @@ -152,7 +167,20 @@ function ($variantSku) {
$validationErrors = $this->strategyHelper->validateEntity($parentProduct);
if ($validationErrors) {
$context->incrementErrorEntriesCount();
$this->strategyHelper->addValidationErrors($validationErrors, $context);
foreach ($validationErrors as $validationError) {
$context->addError(
$this->translator->trans(
'oro.akeneo.error',
[
'%error%' => $validationError,
'%item%' => json_encode(
$context->getValue('rawItemData'),
\JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
),
]
)
);
}

$objectManager->clear();

Expand All @@ -170,14 +198,22 @@ function ($variantSku) {
$parentProduct->setStatus(Product::STATUS_DISABLED);

$context->incrementErrorEntriesCount();
$errorMessages = [
$context->addError(
$this->translator->trans(
'oro.akeneo.validator.product_variants.empty',
['%sku%' => $parentSku],
'validators'
),
];
$this->strategyHelper->addValidationErrors($errorMessages, $context);
'oro.akeneo.error',
[
'%error%' => $this->translator->trans(
'oro.akeneo.validator.product_variants.empty',
['%sku%' => $parentSku],
'validators'
),
'%item%' => json_encode(
$context->getValue('rawItemData'),
\JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
),
]
)
);
}

$context->incrementUpdateCount();
Expand Down
21 changes: 21 additions & 0 deletions ImportExport/Strategy/AttributeImportStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class AttributeImportStrategy extends EntityFieldImportStrategy
{
use StrategyValidationTrait;

/**
* @var FieldHelper
*/
Expand Down Expand Up @@ -88,4 +90,23 @@ protected function processEntity(FieldConfigModel $entity)

return $entity;
}

protected function addErrors($errors)
{
$this->context->incrementErrorEntriesCount();
foreach ((array)$errors as $validationError) {
$this->context->addError(
$this->translator->trans(
'oro.akeneo.error',
[
'%error%' => $validationError,
'%item%' => json_encode(
$this->context->getValue('rawItemData'),
\JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
),
]
)
);
}
}
}
35 changes: 0 additions & 35 deletions ImportExport/Strategy/ImportLogStrategyHelper.php

This file was deleted.

151 changes: 0 additions & 151 deletions ImportExport/Strategy/ImportStrategyHelper.php

This file was deleted.

2 changes: 2 additions & 0 deletions ImportExport/Strategy/ProductImageImportStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
class ProductImageImportStrategy extends ConfigurableAddOrReplaceStrategy implements ClosableInterface
{
use StrategyValidationTrait;

/**
* @var Product[]
*/
Expand Down
1 change: 1 addition & 0 deletions ImportExport/Strategy/ProductPriceImportStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class ProductPriceImportStrategy extends BaseStrategy
{
use AkeneoIntegrationTrait;
use StrategyValidationTrait;

/**
* {@inheritdoc}
Expand Down
1 change: 0 additions & 1 deletion ImportExport/Strategy/StrategyRelationsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ trait StrategyRelationsTrait
* @param object $entity
*
* @see \Oro\Bundle\ImportExportBundle\Strategy\Import\ImportStrategyHelper::importEntity
* @see \Oro\Bundle\AkeneoBundle\ImportExport\Strategy\ImportStrategyHelper::importEntity
* @see \Oro\Bundle\ImportExportBundle\Strategy\Import\ConfigurableAddOrReplaceStrategy::updateRelations
*/
protected function updateRelations($entity, array $itemData = null)
Expand Down
Loading

0 comments on commit 70b7e8f

Please sign in to comment.