2
2
3
3
namespace Oro \Bundle \AkeneoBundle \ImportExport \Processor ;
4
4
5
+ use Oro \Bundle \CacheBundle \Provider \MemoryCacheProviderAwareInterface ;
6
+ use Oro \Bundle \CacheBundle \Provider \MemoryCacheProviderAwareTrait ;
5
7
use Oro \Bundle \EntityBundle \Helper \FieldHelper ;
6
8
use Oro \Bundle \EntityConfigBundle \Config \ConfigManager ;
7
9
use Oro \Bundle \EntityConfigBundle \Entity \FieldConfigModel ;
11
13
/**
12
14
* Converts data to import format, processes entity.
13
15
*/
14
- class AttributeImportProcessor extends StepExecutionAwareImportProcessor
16
+ class AttributeImportProcessor extends StepExecutionAwareImportProcessor implements MemoryCacheProviderAwareInterface
15
17
{
16
- use CacheProviderAwareProcessor ;
18
+ use MemoryCacheProviderAwareTrait ;
17
19
18
20
/** @var string */
19
21
private $ entityConfigModelClassName ;
@@ -24,18 +26,6 @@ class AttributeImportProcessor extends StepExecutionAwareImportProcessor
24
26
/** @var FieldHelper */
25
27
private $ fieldHelper ;
26
28
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
-
39
29
/**
40
30
* {@inheritdoc}
41
31
*/
@@ -48,18 +38,23 @@ public function process($item)
48
38
49
39
$ object = parent ::process ($ item );
50
40
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
+ );
55
53
56
54
$ itemData = $ this ->context ->getValue ('itemData ' );
57
55
58
56
$ this ->updateAttributeLabelTranslationContext ($ itemData , $ object ->getFieldName ());
59
- $ this ->cacheProvider ->save ('attribute_attributeLabels ' , $ this ->attributeLabels );
60
-
61
57
$ this ->updateOptionLabelTranslationContext ($ itemData , $ object ->getFieldName ());
62
- $ this ->cacheProvider ->save ('attribute_optionLabels ' , $ this ->optionLabels );
63
58
}
64
59
65
60
return $ object ;
@@ -74,7 +69,12 @@ private function updateAttributeLabelTranslationContext(array &$item, string $fi
74
69
return ;
75
70
}
76
71
77
- $ this ->attributeLabels [$ fieldName ] = $ item ['translatedLabels ' ];
72
+ $ this ->memoryCacheProvider ->get (
73
+ 'attribute_attributeLabels_ ' . $ fieldName ,
74
+ function () use ($ item ) {
75
+ return $ item ['translatedLabels ' ];
76
+ }
77
+ );
78
78
}
79
79
80
80
/**
@@ -86,36 +86,25 @@ private function updateOptionLabelTranslationContext(array &$item, string $field
86
86
return ;
87
87
}
88
88
89
+ $ optionLabels = [];
90
+
89
91
foreach ($ item ['options ' ] as $ option ) {
90
92
if (empty ($ option ['translatedLabels ' ])) {
91
93
continue ;
92
94
}
93
95
94
- $ this -> optionLabels [ $ fieldName ] [] = [
96
+ $ optionLabels [] = [
95
97
'default ' => $ option ['defaultLabel ' ],
96
98
'translations ' => $ option ['translatedLabels ' ],
97
99
];
98
100
}
99
- }
100
-
101
- public function initialize ()
102
- {
103
- $ this ->attributeLabels = [];
104
- $ this ->optionLabels = [];
105
- $ this ->fieldNameMapping = [];
106
- $ this ->fieldTypeMapping = [];
107
- }
108
101
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
+ );
119
108
}
120
109
121
110
public function setFieldHelper (FieldHelper $ fieldHelper ): void
0 commit comments