|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the MIT license. For more information, see |
|
18
|
|
|
* <http://www.doctrine-project.org>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Doctrine\ORM\Cache\Persister\Collection; |
|
22
|
|
|
|
|
23
|
|
|
use Doctrine\ORM\Cache\CollectionCacheKey; |
|
24
|
|
|
use Doctrine\ORM\PersistentCollection; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @author Fabio B. Silva <[email protected]> |
|
28
|
|
|
* @since 2.5 |
|
29
|
|
|
*/ |
|
30
|
|
|
class NonStrictReadWriteCachedCollectionPersister extends AbstractCollectionPersister |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function afterTransactionComplete() |
|
36
|
|
|
{ |
|
37
|
|
|
if (isset($this->queuedCache['update'])) { |
|
38
|
|
|
foreach ($this->queuedCache['update'] as $item) { |
|
39
|
|
|
$this->storeCollectionCache($item['key'], $item['list']); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if (isset($this->queuedCache['delete'])) { |
|
44
|
|
|
foreach ($this->queuedCache['delete'] as $key) { |
|
45
|
|
|
$this->region->evict($key); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$this->queuedCache = array(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function afterTransactionRolledBack() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->queuedCache = array(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
2 |
|
public function delete(PersistentCollection $collection) |
|
64
|
|
|
{ |
|
65
|
2 |
|
$ownerId = $this->uow->getEntityIdentifier($collection->getOwner()); |
|
66
|
2 |
|
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association['fieldName'], $ownerId); |
|
67
|
|
|
|
|
68
|
2 |
|
$this->persister->delete($collection); |
|
69
|
|
|
|
|
70
|
2 |
|
$this->queuedCache['delete'][spl_object_hash($collection)] = $key; |
|
71
|
2 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
2 |
|
public function update(PersistentCollection $collection) |
|
77
|
|
|
{ |
|
78
|
2 |
|
$isInitialized = $collection->isInitialized(); |
|
79
|
2 |
|
$isDirty = $collection->isDirty(); |
|
80
|
|
|
|
|
81
|
2 |
|
if ( ! $isInitialized && ! $isDirty) { |
|
82
|
|
|
return; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
2 |
|
$ownerId = $this->uow->getEntityIdentifier($collection->getOwner()); |
|
86
|
2 |
|
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association['fieldName'], $ownerId); |
|
87
|
|
|
|
|
88
|
|
|
// Invalidate non initialized collections OR ordered collection |
|
89
|
2 |
|
if ($isDirty && ! $isInitialized || isset($this->association['orderBy'])) { |
|
90
|
|
|
$this->persister->update($collection); |
|
91
|
|
|
|
|
92
|
|
|
$this->queuedCache['delete'][spl_object_hash($collection)] = $key; |
|
93
|
|
|
|
|
94
|
|
|
return; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
2 |
|
$this->persister->update($collection); |
|
98
|
|
|
|
|
99
|
2 |
|
$this->queuedCache['update'][spl_object_hash($collection)] = array( |
|
100
|
2 |
|
'key' => $key, |
|
101
|
2 |
|
'list' => $collection |
|
102
|
|
|
); |
|
103
|
2 |
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|