Completed
Push — migrate-files-no-interaction ( 025687...608925 )
by
unknown
46:43 queued 18:48
created

loadParentLocationsForDraftContent()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 4
nop 1
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the LocationHandler implementation.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Cache;
10
11
use eZ\Publish\SPI\Persistence\Content\Location\Handler as LocationHandlerInterface;
12
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct;
13
use eZ\Publish\SPI\Persistence\Content\Location\UpdateStruct;
14
use eZ\Publish\SPI\Persistence\Content\Location;
15
16
/**
17
 * @see \eZ\Publish\SPI\Persistence\Content\Location\Handler
18
 */
19
class LocationHandler extends AbstractHandler implements LocationHandlerInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 View Code Duplication
    public function load($locationId)
25
    {
26
        $cache = $this->cache->getItem('location', $locationId);
27
        $location = $cache->get();
28
        if ($cache->isMiss()) {
29
            $this->logger->logCall(__METHOD__, array('location' => $locationId));
30
            $cache->set($location = $this->persistenceHandler->locationHandler()->load($locationId))->save();
31
        }
32
33
        return $location;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 View Code Duplication
    public function loadSubtreeIds($locationId)
40
    {
41
        $cache = $this->cache->getItem('location', 'subtree', $locationId);
42
        $locationIds = $cache->get();
43
44
        if ($cache->isMiss()) {
45
            $this->logger->logCall(__METHOD__, array('location' => $locationId));
46
            $cache->set(
47
                $locationIds = $this->persistenceHandler->locationHandler()->loadSubtreeIds($locationId)
48
            )->save();
49
        }
50
51
        return $locationIds;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 View Code Duplication
    public function loadLocationsByContent($contentId, $rootLocationId = null)
58
    {
59
        if ($rootLocationId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $rootLocationId of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
60
            $cache = $this->cache->getItem('content', 'locations', $contentId, 'root', $rootLocationId);
61
        } else {
62
            $cache = $this->cache->getItem('content', 'locations', $contentId);
63
        }
64
        $locationIds = $cache->get();
65
        if ($cache->isMiss()) {
66
            $this->logger->logCall(__METHOD__, array('content' => $contentId, 'root' => $rootLocationId));
67
            $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentId, $rootLocationId);
68
69
            $locationIds = array();
70
            foreach ($locations as $location) {
71
                $locationIds[] = $location->id;
72
            }
73
74
            $cache->set($locationIds)->save();
75
        } else {
76
            $locations = array();
77
            foreach ($locationIds as $locationId) {
78
                $locations[] = $this->load($locationId);
79
            }
80
        }
81
82
        return $locations;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function loadParentLocationsForDraftContent($contentId)
89
    {
90
        $cache = $this->cache->getItem('content', 'locations', $contentId, 'parentLocationsForDraftContent');
91
        $locationIds = $cache->get();
92
        if ($cache->isMiss()) {
93
            $this->logger->logCall(__METHOD__, array('content' => $contentId));
94
            $locations = $this->persistenceHandler->locationHandler()->loadParentLocationsForDraftContent($contentId);
95
96
            $locationIds = array();
97
            foreach ($locations as $location) {
98
                $locationIds[] = $location->id;
99
            }
100
101
            $cache->set($locationIds)->save();
102
        } else {
103
            $locations = array();
104
            foreach ($locationIds as $locationId) {
105
                $locations[] = $this->load($locationId);
106
            }
107
        }
108
109
        return $locations;
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function loadByRemoteId($remoteId)
116
    {
117
        $this->logger->logCall(__METHOD__, array('location' => $remoteId));
118
119
        return $this->persistenceHandler->locationHandler()->loadByRemoteId($remoteId);
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function copySubtree($sourceId, $destinationParentId)
126
    {
127
        $this->logger->logCall(__METHOD__, array('source' => $sourceId, 'destination' => $destinationParentId));
128
129
        return $this->persistenceHandler->locationHandler()->copySubtree($sourceId, $destinationParentId);
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135
    public function move($sourceId, $destinationParentId)
136
    {
137
        $this->logger->logCall(__METHOD__, array('source' => $sourceId, 'destination' => $destinationParentId));
138
        $return = $this->persistenceHandler->locationHandler()->move($sourceId, $destinationParentId);
139
140
        $this->cache->clear('location');//TIMBER! (path[Identification]String)
141
        $this->cache->clear('user', 'role', 'assignments', 'byGroup');
142
        $this->cache->clear('content');//TIMBER!
143
144
        return $return;
145
    }
146
147
    /**
148
     * {@inheritdoc}
149
     */
150
    public function markSubtreeModified($locationId, $timestamp = null)
151
    {
152
        $this->logger->logCall(__METHOD__, array('location' => $locationId, 'time' => $timestamp));
153
        $this->persistenceHandler->locationHandler()->markSubtreeModified($locationId, $timestamp);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\SPI\Persisten...::markSubtreeModified() has been deprecated with message: As of 6.8, not been used by repository since 5.x.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
154
    }
155
156
    /**
157
     * {@inheritdoc}
158
     */
159
    public function hide($locationId)
160
    {
161
        $this->logger->logCall(__METHOD__, array('location' => $locationId));
162
        $return = $this->persistenceHandler->locationHandler()->hide($locationId);
163
164
        $this->cache->clear('location');//TIMBER! (visibility)
165
166
        return $return;
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172
    public function unHide($locationId)
173
    {
174
        $this->logger->logCall(__METHOD__, array('location' => $locationId));
175
        $return = $this->persistenceHandler->locationHandler()->unHide($locationId);
176
177
        $this->cache->clear('location');//TIMBER! (visibility)
178
179
        return $return;
180
    }
181
182
    /**
183
     * {@inheritdoc}
184
     */
185
    public function swap($locationId1, $locationId2)
186
    {
187
        $this->logger->logCall(__METHOD__, array('location1' => $locationId1, 'location2' => $locationId2));
188
        $locationHandler = $this->persistenceHandler->locationHandler();
189
190
        $return = $locationHandler->swap($locationId1, $locationId2);
191
192
        $this->cache->clear('location', $locationId1);
193
        $this->cache->clear('location', $locationId2);
194
        $this->cache->clear('location', 'subtree');
195
        $this->cache->clear('content', 'locations');
196
        $this->cache->clear('user', 'role', 'assignments', 'byGroup');
197
198
        // This ensures that Content cache is updated for possible main Location change
199
        $location1 = $this->load($locationId1);
200
        $location2 = $this->load($locationId2);
201
        $this->cache->clear('content', $location1->contentId);
202
        $this->cache->clear('content', $location2->contentId);
203
        $this->cache->clear('content', 'info', $location1->contentId);
204
        $this->cache->clear('content', 'info', $location2->contentId);
205
206
        return $return;
207
    }
208
209
    /**
210
     * {@inheritdoc}
211
     */
212
    public function update(UpdateStruct $struct, $locationId)
213
    {
214
        $this->logger->logCall(__METHOD__, array('location' => $locationId, 'struct' => $struct));
215
        $this->persistenceHandler->locationHandler()->update($struct, $locationId);
216
        $this->cache->clear('location', $locationId);
217
        $this->cache->clear('location', 'subtree');
218
    }
219
220
    /**
221
     * {@inheritdoc}
222
     */
223
    public function create(CreateStruct $locationStruct)
224
    {
225
        $this->logger->logCall(__METHOD__, array('struct' => $locationStruct));
226
        $location = $this->persistenceHandler->locationHandler()->create($locationStruct);
227
228
        $this->cache->getItem('location', $location->id)->set($location)->save();
229
        $this->cache->clear('location', 'subtree');
230
        $this->cache->clear('content', 'locations', $location->contentId);
231
        $this->cache->clear('content', $location->contentId);
232
        $this->cache->clear('content', 'info', $location->contentId);
233
        $this->cache->clear('user', 'role', 'assignments', 'byGroup', $location->contentId);
234
        $this->cache->clear('user', 'role', 'assignments', 'byGroup', 'inherited', $location->contentId);
235
236
        return $location;
237
    }
238
239
    /**
240
     * {@inheritdoc}
241
     */
242
    public function removeSubtree($locationId)
243
    {
244
        $this->logger->logCall(__METHOD__, array('location' => $locationId));
245
        $return = $this->persistenceHandler->locationHandler()->removeSubtree($locationId);
246
247
        $this->cache->clear('location');//TIMBER!
248
        $this->cache->clear('content');//TIMBER!
249
        $this->cache->clear('user', 'role', 'assignments', 'byGroup');
250
251
        return $return;
252
    }
253
254
    /**
255
     * {@inheritdoc}
256
     */
257
    public function setSectionForSubtree($locationId, $sectionId)
258
    {
259
        $this->logger->logCall(__METHOD__, array('location' => $locationId, 'section' => $sectionId));
260
        $this->persistenceHandler->locationHandler()->setSectionForSubtree($locationId, $sectionId);
261
        $this->cache->clear('content');//TIMBER!
262
    }
263
264
    /**
265
     * {@inheritdoc}
266
     */
267
    public function changeMainLocation($contentId, $locationId)
268
    {
269
        $this->logger->logCall(__METHOD__, array('location' => $locationId, 'content' => $contentId));
270
        $this->persistenceHandler->locationHandler()->changeMainLocation($contentId, $locationId);
271
        $this->cache->clear('content', $contentId);
272
        $this->cache->clear('content', 'info', $contentId);
273
        $this->cache->clear('content', 'info', 'remoteId');
274
    }
275
}
276