|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Actualys\Bundle\DrupalCommerceConnectorBundle\Processor; |
|
4
|
|
|
|
|
5
|
|
|
use Akeneo\Bundle\BatchBundle\Item\InvalidItemException; |
|
6
|
|
|
use Akeneo\Bundle\BatchBundle\Entity\StepExecution; |
|
7
|
|
|
use Akeneo\Bundle\BatchBundle\Item\ItemProcessorInterface; |
|
8
|
|
|
use Pim\Bundle\CatalogBundle\Model\Product; |
|
9
|
|
|
use Pim\Bundle\CatalogBundle\Manager\ProductManager; |
|
10
|
|
|
use Pim\Bundle\CatalogBundle\Manager\AssociationManager; |
|
11
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\Exception\NormalizeException; |
|
12
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\AssociationNormalizer; |
|
13
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Item\DrupalItemStep; |
|
14
|
|
|
|
|
15
|
|
|
class AssociationProcessor extends DrupalItemStep implements ItemProcessorInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var AssociationNormalizer $associationNormalizer |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $associationNormalizer; |
|
21
|
|
|
|
|
22
|
|
|
/** @var AssociationManager $associationManager */ |
|
23
|
|
|
protected $associationManager; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $globalContext = array(); |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var ProductManager $productManager |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $productManager; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param AssociationNormalizer $associationNormalizer |
|
37
|
|
|
* @param ProductManager $productManager |
|
38
|
|
|
* @param AssociationManager $associationManager |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct( |
|
41
|
|
|
AssociationNormalizer $associationNormalizer, |
|
42
|
|
|
ProductManager $productManager, |
|
43
|
|
|
AssociationManager $associationManager |
|
44
|
|
|
) { |
|
45
|
|
|
$this->associationNormalizer = $associationNormalizer; |
|
46
|
|
|
$this->productManager = $productManager; |
|
47
|
|
|
$this->associationManager = $associationManager; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param mixed $product |
|
52
|
|
|
* @return array|mixed |
|
53
|
|
|
* @throws InvalidItemException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function process($product) |
|
56
|
|
|
{ |
|
57
|
|
|
$result = []; |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
return $this->normalizeAssociation( |
|
60
|
|
|
$product, |
|
61
|
|
|
$this->globalContext |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param Product $product |
|
67
|
|
|
* @param array $context |
|
68
|
|
|
* @return array|\Symfony\Component\Serializer\Normalizer\scalar |
|
69
|
|
|
* @throws InvalidItemException |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function normalizeAssociation(Product $product, array $context) |
|
72
|
|
|
{ |
|
73
|
|
|
try { |
|
74
|
|
|
$processedItem = $this->associationNormalizer->normalize( |
|
75
|
|
|
$product, |
|
76
|
|
|
$context |
|
77
|
|
|
); |
|
78
|
|
|
} catch (NormalizeException $e) { |
|
79
|
|
|
throw new InvalidItemException($e->getMessage(), [$product]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $processedItem; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getConfigurationFields() |
|
86
|
|
|
{ |
|
87
|
|
|
return parent::getConfigurationFields(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param StepExecution $stepExecution |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setStepExecution(StepExecution $stepExecution) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->stepExecution = $stepExecution; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.