1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace Doctrine\ORM\Cache\Persister\Collection; |
||||
6 | |||||
7 | use Doctrine\ORM\Cache\CollectionCacheKey; |
||||
8 | use Doctrine\ORM\Mapping\ToManyAssociationMetadata; |
||||
9 | use Doctrine\ORM\PersistentCollection; |
||||
10 | |||||
11 | class NonStrictReadWriteCachedCollectionPersister extends AbstractCollectionPersister |
||||
12 | { |
||||
13 | /** |
||||
14 | * {@inheritdoc} |
||||
15 | */ |
||||
16 | 64 | public function afterTransactionComplete() |
|||
17 | { |
||||
18 | 64 | if (isset($this->queuedCache['update'])) { |
|||
19 | 45 | foreach ($this->queuedCache['update'] as $item) { |
|||
20 | 45 | $this->storeCollectionCache($item['key'], $item['list']); |
|||
21 | } |
||||
22 | } |
||||
23 | |||||
24 | 64 | if (isset($this->queuedCache['delete'])) { |
|||
25 | 16 | foreach ($this->queuedCache['delete'] as $key) { |
|||
26 | 16 | $this->region->evict($key); |
|||
27 | } |
||||
28 | } |
||||
29 | |||||
30 | 64 | $this->queuedCache = []; |
|||
31 | 64 | } |
|||
32 | |||||
33 | /** |
||||
34 | * {@inheritdoc} |
||||
35 | */ |
||||
36 | public function afterTransactionRolledBack() |
||||
37 | { |
||||
38 | $this->queuedCache = []; |
||||
39 | } |
||||
40 | |||||
41 | /** |
||||
42 | * {@inheritdoc} |
||||
43 | */ |
||||
44 | 2 | public function delete(PersistentCollection $collection) |
|||
45 | { |
||||
46 | 2 | $fieldName = $this->association->getName(); |
|||
47 | 2 | $ownerId = $this->uow->getEntityIdentifier($collection->getOwner()); |
|||
48 | 2 | $key = new CollectionCacheKey($this->sourceEntity->getRootClassName(), $fieldName, $ownerId); |
|||
49 | |||||
50 | 2 | $this->persister->delete($collection); |
|||
51 | |||||
52 | 2 | $this->queuedCache['delete'][spl_object_id($collection)] = $key; |
|||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
53 | 2 | } |
|||
54 | |||||
55 | /** |
||||
56 | * {@inheritdoc} |
||||
57 | */ |
||||
58 | 47 | public function update(PersistentCollection $collection) |
|||
59 | { |
||||
60 | 47 | $isInitialized = $collection->isInitialized(); |
|||
61 | 47 | $isDirty = $collection->isDirty(); |
|||
62 | |||||
63 | 47 | if (! $isInitialized && ! $isDirty) { |
|||
64 | return; |
||||
65 | } |
||||
66 | |||||
67 | 47 | $fieldName = $this->association->getName(); |
|||
68 | 47 | $ownerId = $this->uow->getEntityIdentifier($collection->getOwner()); |
|||
69 | 47 | $key = new CollectionCacheKey($this->sourceEntity->getRootClassName(), $fieldName, $ownerId); |
|||
70 | |||||
71 | // Invalidate non initialized collections OR ordered collection |
||||
72 | 47 | if (($isDirty && ! $isInitialized) || |
|||
73 | 47 | ($this->association instanceof ToManyAssociationMetadata && $this->association->getOrderBy())) { |
|||
74 | 16 | $this->persister->update($collection); |
|||
75 | |||||
76 | 16 | $this->queuedCache['delete'][spl_object_id($collection)] = $key; |
|||
0 ignored issues
–
show
The function
spl_object_id was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
77 | |||||
78 | 16 | return; |
|||
79 | } |
||||
80 | |||||
81 | 47 | $this->persister->update($collection); |
|||
82 | |||||
83 | 47 | $this->queuedCache['update'][spl_object_id($collection)] = [ |
|||
84 | 47 | 'key' => $key, |
|||
85 | 47 | 'list' => $collection, |
|||
86 | ]; |
||||
87 | 47 | } |
|||
88 | } |
||||
89 |