1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainFoundation\Repository; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\ORMException; |
6
|
|
|
use Doctrine\ORM\UnexpectedResultException; |
7
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\ProductInterface; |
|
|
|
|
8
|
|
|
use Loevgaard\DandomainFoundation\Entity\Product; |
9
|
|
|
use Loevgaard\DandomainFoundation\Repository\Generated\ProductRepositoryTrait; |
|
|
|
|
10
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @method null|ProductInterface find($id) |
14
|
|
|
* @method ProductInterface[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null) |
15
|
|
|
* @method null|ProductInterface findOneBy(array $criteria) |
16
|
|
|
* @method ProductInterface[] findAll() |
17
|
|
|
*/ |
18
|
|
|
class ProductRepository extends AbstractRepository |
19
|
|
|
{ |
20
|
|
|
use ProductRepositoryTrait; |
21
|
|
|
|
22
|
|
|
public function __construct(RegistryInterface $registry) |
23
|
|
|
{ |
24
|
|
|
parent::__construct($registry, Product::class); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function findOneByExternalId(int $externalId): ?ProductInterface |
28
|
|
|
{ |
29
|
|
|
/** @var ProductInterface $obj */ |
30
|
|
|
$obj = $this->_findOneByExternalId($externalId); |
31
|
|
|
|
32
|
|
|
return $obj; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $number |
37
|
|
|
* |
38
|
|
|
* @return ProductInterface|null |
39
|
|
|
*/ |
40
|
|
|
public function findOneByNumber(string $number): ?ProductInterface |
41
|
|
|
{ |
42
|
|
|
/** @var ProductInterface $obj */ |
43
|
|
|
$obj = $this->findOneBy([ |
44
|
|
|
'number' => $number, |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
return $obj; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param array $productIds |
52
|
|
|
* |
53
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
54
|
|
|
*/ |
55
|
|
|
public function updateParentChildRelationships(array $productIds = []) |
56
|
|
|
{ |
57
|
|
|
$variantMasterIdCache = []; |
58
|
|
|
|
59
|
|
|
$innerQb = $this->createQueryBuilder('p'); |
60
|
|
|
$innerQb->where('p.isVariantMaster = 1') |
61
|
|
|
->andWhere('p.number = :number'); |
62
|
|
|
|
63
|
|
|
$qb = $this->createQueryBuilder('p'); |
64
|
|
|
$qb |
65
|
|
|
->where('p.isVariantMaster = 0') |
66
|
|
|
->andWhere('p.variantMasterId is not null') |
67
|
|
|
; |
68
|
|
|
|
69
|
|
|
if (count($productIds)) { |
70
|
|
|
$qb->andWhere($qb->expr()->in('p.id', ':productIds')); |
71
|
|
|
$qb->setParameter('productIds', $productIds); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$batchSize = 50; |
75
|
|
|
$i = 1; |
76
|
|
|
|
77
|
|
|
$iterableResult = $qb->getQuery()->iterate(); |
78
|
|
|
foreach ($iterableResult as $row) { |
79
|
|
|
/** @var ProductInterface $product */ |
80
|
|
|
$product = $row[0]; |
81
|
|
|
|
82
|
|
|
if (!isset($variantMasterIdCache[$product->getVariantMasterId()])) { |
83
|
|
|
try { |
84
|
|
|
/** @var ProductInterface $parent */ |
85
|
|
|
$parent = $innerQb->setParameter( |
86
|
|
|
'number', |
87
|
|
|
$product->getVariantMasterId() |
88
|
|
|
)->getQuery()->getSingleResult(); |
89
|
|
|
$parent = $parent->getId(); |
90
|
|
|
} catch (UnexpectedResultException $e) { |
91
|
|
|
$parent = null; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$variantMasterIdCache[$product->getVariantMasterId()] = $parent; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$ref = $variantMasterIdCache[$product->getVariantMasterId()]; |
98
|
|
|
if ($ref) { |
99
|
|
|
try { |
100
|
|
|
$ref = $this->getEntityManager()->getReference(Product::class, $ref); |
101
|
|
|
} catch (ORMException $e) { |
102
|
|
|
$ref = null; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$product->setParent($ref); |
107
|
|
|
|
108
|
|
|
if (0 === ($i % $batchSize)) { |
109
|
|
|
$this->getEntityManager()->flush(); |
110
|
|
|
$this->getEntityManager()->clear(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
++$i; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$this->getEntityManager()->flush(); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths