Skip to content

Commit e826077

Browse files
committed
5.1 BC break fixes
1 parent fd2f4d5 commit e826077

25 files changed

+260
-314
lines changed

Async/ImportProductProcessor.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Oro\Bundle\AkeneoBundle\Async;
44

55
use Doctrine\ORM\EntityManagerInterface;
6-
use Oro\Bundle\AkeneoBundle\Tools\CacheProviderTrait;
6+
use Oro\Bundle\CacheBundle\Provider\MemoryCacheProviderAwareInterface;
7+
use Oro\Bundle\CacheBundle\Provider\MemoryCacheProviderAwareTrait;
78
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
89
use Oro\Bundle\IntegrationBundle\Authentication\Token\IntegrationTokenAwareTrait;
910
use Oro\Bundle\IntegrationBundle\Entity\Channel as Integration;
@@ -19,10 +20,10 @@
1920
use Psr\Log\LoggerInterface;
2021
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
2122

22-
class ImportProductProcessor implements MessageProcessorInterface, TopicSubscriberInterface
23+
class ImportProductProcessor implements MessageProcessorInterface, TopicSubscriberInterface, MemoryCacheProviderAwareInterface
2324
{
24-
use CacheProviderTrait;
2525
use IntegrationTokenAwareTrait;
26+
use MemoryCacheProviderAwareTrait;
2627

2728
/** @var DoctrineHelper */
2829
private $doctrineHelper;
@@ -115,7 +116,14 @@ function (JobRunner $jobRunner, Job $child) use ($integration, $body) {
115116
return false;
116117
}
117118

118-
$this->cacheProvider->save('akeneo', $fieldsChanges->getChangedFields());
119+
foreach ($fieldsChanges->getChangedFields() as $key => $changes) {
120+
$this->memoryCacheProvider->get(
121+
'akeneo_' . $key,
122+
function () use (&$changes) {
123+
return $changes;
124+
}
125+
);
126+
}
119127

120128
$status = $processor->process(
121129
$integration,

Async/Topics.php

+36-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,42 @@
22

33
namespace Oro\Bundle\AkeneoBundle\Async;
44

5-
class Topics
5+
use Oro\Component\MessageQueue\Topic\AbstractTopic;
6+
use Symfony\Component\OptionsResolver\OptionsResolver;
7+
8+
class Topics extends AbstractTopic
69
{
710
const IMPORT_PRODUCTS = 'oro.integration.akeneo.product';
11+
12+
public static function getName(): string
13+
{
14+
return self::IMPORT_PRODUCTS;
15+
}
16+
17+
public static function getDescription(): string
18+
{
19+
return 'Synchronizes Akeneo products batch.';
20+
}
21+
22+
public function configureMessageBody(OptionsResolver $resolver): void
23+
{
24+
$resolver
25+
->setDefined([
26+
'integrationId',
27+
'connector',
28+
'connector_parameters',
29+
'jobId',
30+
])
31+
->setRequired([
32+
'integrationId',
33+
'jobId',
34+
])
35+
->setDefaults([
36+
'connector_parameters' => [],
37+
])
38+
->addAllowedTypes('integrationId', ['string', 'int'])
39+
->addAllowedTypes('connector', ['null', 'string'])
40+
->addAllowedTypes('connector_parameters', 'array')
41+
->addAllowedTypes('jobId', ['string', 'int']);
42+
}
843
}

Command/CleanupCommand.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Oro\Bundle\AkeneoBundle\Command;
44

55
use Oro\Bundle\BatchBundle\ORM\Query\BufferedIdentityQueryResultIterator;
6-
use Oro\Bundle\CronBundle\Command\CronCommandInterface;
6+
use Oro\Bundle\CronBundle\Command\CronCommandActivationInterface;
7+
use Oro\Bundle\CronBundle\Command\CronCommandScheduleDefinitionInterface;
78
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
89
use Oro\Bundle\IntegrationBundle\Entity\FieldsChanges;
910
use Oro\Bundle\MessageQueueBundle\Entity\Job;
@@ -14,7 +15,9 @@
1415
/**
1516
* Clears old records from oro_integration_fields_changes table before repack.
1617
*/
17-
class CleanupCommand extends Command implements CronCommandInterface
18+
class CleanupCommand extends Command implements
19+
CronCommandScheduleDefinitionInterface,
20+
CronCommandActivationInterface
1821
{
1922
/** @var string */
2023
protected static $defaultName = 'oro:cron:akeneo:cleanup';

ImportExport/DataConverter/ProductDataConverter.php

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ private function setStatus(array &$importedRecord)
104104
{
105105
$importedRecord['status'] = empty($importedRecord['enabled']) ?
106106
Product::STATUS_DISABLED : Product::STATUS_ENABLED;
107+
108+
$importedRecord['status'] = Product::STATUS_ENABLED;
107109
}
108110

109111
private function setPrimaryUnitPrecision(array &$importedRecord): void

ImportExport/Processor/AttributeFamilyImportProcessor.php

+11-18
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Oro\Bundle\AkeneoBundle\ImportExport\Processor;
44

55
use Oro\Bundle\AkeneoBundle\Tools\AttributeFamilyCodeGenerator;
6+
use Oro\Bundle\CacheBundle\Provider\MemoryCacheProviderAwareInterface;
7+
use Oro\Bundle\CacheBundle\Provider\MemoryCacheProviderAwareTrait;
68
use Oro\Bundle\IntegrationBundle\ImportExport\Processor\StepExecutionAwareImportProcessor;
79

8-
class AttributeFamilyImportProcessor extends StepExecutionAwareImportProcessor
10+
class AttributeFamilyImportProcessor extends StepExecutionAwareImportProcessor implements
11+
MemoryCacheProviderAwareInterface
912
{
10-
use CacheProviderAwareProcessor;
11-
12-
/** @var array */
13-
private $processedAttributeFamilies = [];
13+
use MemoryCacheProviderAwareTrait;
1414

1515
/**
1616
* {@inheritdoc}
@@ -19,21 +19,14 @@ public function process($item)
1919
{
2020
if (!empty($item['code'])) {
2121
$code = AttributeFamilyCodeGenerator::generate($item['code']);
22-
$this->processedAttributeFamilies[$code] = $code;
22+
$this->memoryCacheProvider->get(
23+
'attribute_family_' . $code,
24+
function () use ($code) {
25+
return $code;
26+
}
27+
);
2328
}
2429

2530
return parent::process($item);
2631
}
27-
28-
public function initialize()
29-
{
30-
$this->cacheProvider->delete('attribute_family');
31-
$this->processedAttributeFamilies = [];
32-
}
33-
34-
public function flush()
35-
{
36-
$this->cacheProvider->save('attribute_family', $this->processedAttributeFamilies);
37-
$this->processedAttributeFamilies = null;
38-
}
3932
}

ImportExport/Processor/AttributeFamilyStatusProcessor.php

+5-17
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
namespace Oro\Bundle\AkeneoBundle\ImportExport\Processor;
44

55
use Doctrine\Persistence\ManagerRegistry;
6+
use Oro\Bundle\CacheBundle\Provider\MemoryCacheProviderAwareInterface;
7+
use Oro\Bundle\CacheBundle\Provider\MemoryCacheProviderAwareTrait;
68
use Oro\Bundle\EntityConfigBundle\Attribute\Entity\AttributeFamily;
79
use Oro\Bundle\ImportExportBundle\Processor\ProcessorInterface;
810

9-
class AttributeFamilyStatusProcessor implements ProcessorInterface
11+
class AttributeFamilyStatusProcessor implements ProcessorInterface, MemoryCacheProviderAwareInterface
1012
{
11-
use CacheProviderAwareProcessor;
12-
13-
/** @var array */
14-
private $processedAttributeFamilies = [];
13+
use MemoryCacheProviderAwareTrait;
1514

1615
/** @var ManagerRegistry */
1716
private $registry;
@@ -30,23 +29,12 @@ public function process($item)
3029
return null;
3130
}
3231

33-
if (in_array($item->getCode(), $this->processedAttributeFamilies)) {
32+
if ($this->memoryCacheProvider->get('attribute_family_' . $item->getCode())) {
3433
return null;
3534
}
3635

3736
$item->setIsEnabled(false);
3837

3938
return $item;
4039
}
41-
42-
public function initialize()
43-
{
44-
$this->processedAttributeFamilies = $this->cacheProvider->fetch('attribute_family') ?? [];
45-
}
46-
47-
public function flush()
48-
{
49-
$this->cacheProvider->delete('attribute_family');
50-
$this->processedAttributeFamilies = null;
51-
}
5240
}

ImportExport/Processor/AttributeImportProcessor.php

+31-42
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Oro\Bundle\AkeneoBundle\ImportExport\Processor;
44

5+
use Oro\Bundle\CacheBundle\Provider\MemoryCacheProviderAwareInterface;
6+
use Oro\Bundle\CacheBundle\Provider\MemoryCacheProviderAwareTrait;
57
use Oro\Bundle\EntityBundle\Helper\FieldHelper;
68
use Oro\Bundle\EntityConfigBundle\Config\ConfigManager;
79
use Oro\Bundle\EntityConfigBundle\Entity\FieldConfigModel;
@@ -11,9 +13,9 @@
1113
/**
1214
* Converts data to import format, processes entity.
1315
*/
14-
class AttributeImportProcessor extends StepExecutionAwareImportProcessor
16+
class AttributeImportProcessor extends StepExecutionAwareImportProcessor implements MemoryCacheProviderAwareInterface
1517
{
16-
use CacheProviderAwareProcessor;
18+
use MemoryCacheProviderAwareTrait;
1719

1820
/** @var string */
1921
private $entityConfigModelClassName;
@@ -24,18 +26,6 @@ class AttributeImportProcessor extends StepExecutionAwareImportProcessor
2426
/** @var FieldHelper */
2527
private $fieldHelper;
2628

27-
/** @var array */
28-
private $attributeLabels = [];
29-
30-
/** @var array */
31-
private $optionLabels = [];
32-
33-
/** @var array */
34-
private $fieldNameMapping = [];
35-
36-
/** @var array */
37-
private $fieldTypeMapping = [];
38-
3929
/**
4030
* {@inheritdoc}
4131
*/
@@ -48,18 +38,23 @@ public function process($item)
4838

4939
$object = parent::process($item);
5040
if ($object instanceof FieldConfigModel) {
51-
$this->fieldNameMapping[$object->getFieldName()] = $code;
52-
$this->fieldTypeMapping[$object->getFieldName()] = $type;
53-
$this->cacheProvider->save('attribute_fieldNameMapping', $this->fieldNameMapping);
54-
$this->cacheProvider->save('attribute_fieldTypeMapping', $this->fieldTypeMapping);
41+
$this->memoryCacheProvider->get(
42+
'attribute_fieldNameMapping_' . $object->getFieldName(),
43+
function () use ($code) {
44+
return $code;
45+
}
46+
);
47+
$this->memoryCacheProvider->get(
48+
'attribute_fieldTypeMapping_' . $object->getFieldName(),
49+
function () use ($type) {
50+
return $type;
51+
}
52+
);
5553

5654
$itemData = $this->context->getValue('itemData');
5755

5856
$this->updateAttributeLabelTranslationContext($itemData, $object->getFieldName());
59-
$this->cacheProvider->save('attribute_attributeLabels', $this->attributeLabels);
60-
6157
$this->updateOptionLabelTranslationContext($itemData, $object->getFieldName());
62-
$this->cacheProvider->save('attribute_optionLabels', $this->optionLabels);
6358
}
6459

6560
return $object;
@@ -74,7 +69,12 @@ private function updateAttributeLabelTranslationContext(array &$item, string $fi
7469
return;
7570
}
7671

77-
$this->attributeLabels[$fieldName] = $item['translatedLabels'];
72+
$this->memoryCacheProvider->get(
73+
'attribute_attributeLabels_' . $fieldName,
74+
function () use ($item) {
75+
return $item['translatedLabels'];
76+
}
77+
);
7878
}
7979

8080
/**
@@ -86,36 +86,25 @@ private function updateOptionLabelTranslationContext(array &$item, string $field
8686
return;
8787
}
8888

89+
$optionLabels = [];
90+
8991
foreach ($item['options'] as $option) {
9092
if (empty($option['translatedLabels'])) {
9193
continue;
9294
}
9395

94-
$this->optionLabels[$fieldName][] = [
96+
$optionLabels[] = [
9597
'default' => $option['defaultLabel'],
9698
'translations' => $option['translatedLabels'],
9799
];
98100
}
99-
}
100-
101-
public function initialize()
102-
{
103-
$this->attributeLabels = [];
104-
$this->optionLabels = [];
105-
$this->fieldNameMapping = [];
106-
$this->fieldTypeMapping = [];
107-
}
108101

109-
public function flush()
110-
{
111-
$this->cacheProvider->save('attribute_attributeLabels', $this->attributeLabels);
112-
$this->cacheProvider->save('attribute_optionLabels', $this->optionLabels);
113-
$this->cacheProvider->save('attribute_fieldNameMapping', $this->fieldNameMapping);
114-
$this->cacheProvider->save('attribute_fieldTypeMapping', $this->fieldTypeMapping);
115-
$this->attributeLabels = null;
116-
$this->optionLabels = null;
117-
$this->fieldNameMapping = null;
118-
$this->fieldTypeMapping = null;
102+
$this->memoryCacheProvider->get(
103+
'attribute_optionLabels_' . $fieldName,
104+
function () use ($optionLabels) {
105+
return $optionLabels;
106+
}
107+
);
119108
}
120109

121110
public function setFieldHelper(FieldHelper $fieldHelper): void

ImportExport/Processor/CacheProviderAwareProcessor.php

-16
This file was deleted.

0 commit comments

Comments
 (0)