Completed
Push — ezp-30616 ( 9239a0...7bf8e8 )
by
unknown
57:53 queued 37:56
created

LocationService::loadLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * LocationService class.
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\SignalSlot;
10
11
use eZ\Publish\API\Repository\LocationService as LocationServiceInterface;
12
use eZ\Publish\API\Repository\Values\Content\Location;
13
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
14
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
15
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct;
16
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
17
use eZ\Publish\Core\SignalSlot\Signal\LocationService\CopySubtreeSignal;
18
use eZ\Publish\Core\SignalSlot\Signal\LocationService\CreateLocationSignal;
19
use eZ\Publish\Core\SignalSlot\Signal\LocationService\UpdateLocationSignal;
20
use eZ\Publish\Core\SignalSlot\Signal\LocationService\SwapLocationSignal;
21
use eZ\Publish\Core\SignalSlot\Signal\LocationService\HideLocationSignal;
22
use eZ\Publish\Core\SignalSlot\Signal\LocationService\UnhideLocationSignal;
23
use eZ\Publish\Core\SignalSlot\Signal\LocationService\MoveSubtreeSignal;
24
use eZ\Publish\Core\SignalSlot\Signal\LocationService\DeleteLocationSignal;
25
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
26
27
/**
28
 * LocationService class.
29
 */
30
class LocationService implements LocationServiceInterface
31
{
32
    /**
33
     * Aggregated service.
34
     *
35
     * @var \eZ\Publish\API\Repository\LocationService
36
     */
37
    protected $service;
38
39
    /**
40
     * SignalDispatcher.
41
     *
42
     * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher
43
     */
44
    protected $signalDispatcher;
45
46
    /**
47
     * Constructor.
48
     *
49
     * Construct service object from aggregated service and signal
50
     * dispatcher
51
     *
52
     * @param \eZ\Publish\API\Repository\LocationService $service
53
     * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher
54
     */
55
    public function __construct(LocationServiceInterface $service, SignalDispatcher $signalDispatcher)
56
    {
57
        $this->service = $service;
58
        $this->signalDispatcher = $signalDispatcher;
59
    }
60
61
    /**
62
     * Copies the subtree starting from $subtree as a new subtree of $targetLocation.
63
     *
64
     * Only the items on which the user has read access are copied.
65
     *
66
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed copy the subtree to the given parent location
67
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user does not have read access to the whole source subtree
68
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the target location is a sub location of the given location
69
     *
70
     * @param \eZ\Publish\API\Repository\Values\Content\Location $subtree - the subtree denoted by the location to copy
71
     * @param \eZ\Publish\API\Repository\Values\Content\Location $targetParentLocation - the target parent location for the copy operation
72
     *
73
     * @return \eZ\Publish\API\Repository\Values\Content\Location The newly created location of the copied subtree
74
     */
75
    public function copySubtree(Location $subtree, Location $targetParentLocation)
76
    {
77
        $returnValue = $this->service->copySubtree($subtree, $targetParentLocation);
78
        $this->signalDispatcher->emit(
79
            new CopySubtreeSignal(
80
                array(
81
                    'subtreeId' => $subtree->id,
82
                    'targetParentLocationId' => $targetParentLocation->id,
83
                    'targetNewSubtreeId' => $returnValue->id,
84
                )
85
            )
86
        );
87
88
        return $returnValue;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function loadLocation($locationId, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null)
95
    {
96
        return $this->service->loadLocation($locationId, $prioritizedLanguages, $useAlwaysAvailable);
0 ignored issues
show
Bug introduced by
It seems like $prioritizedLanguages defined by parameter $prioritizedLanguages on line 94 can also be of type array; however, eZ\Publish\API\Repositor...Service::loadLocation() does only seem to accept null|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function loadLocationList(array $locationIds, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null): iterable
103
    {
104
        return $this->service->loadLocationList($locationIds, $prioritizedLanguages, $useAlwaysAvailable);
0 ignored issues
show
Bug introduced by
It seems like $prioritizedLanguages defined by parameter $prioritizedLanguages on line 102 can also be of type array; however, eZ\Publish\API\Repositor...ice::loadLocationList() does only seem to accept null|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function loadLocationByRemoteId($remoteId, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null)
111
    {
112
        return $this->service->loadLocationByRemoteId($remoteId, $prioritizedLanguages, $useAlwaysAvailable);
0 ignored issues
show
Bug introduced by
It seems like $prioritizedLanguages defined by parameter $prioritizedLanguages on line 110 can also be of type array; however, eZ\Publish\API\Repositor...oadLocationByRemoteId() does only seem to accept null|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function loadLocations(ContentInfo $contentInfo, Location $rootLocation = null, array $prioritizedLanguages = null)
119
    {
120
        return $this->service->loadLocations($contentInfo, $rootLocation, $prioritizedLanguages);
0 ignored issues
show
Bug introduced by
It seems like $prioritizedLanguages defined by parameter $prioritizedLanguages on line 118 can also be of type array; however, eZ\Publish\API\Repositor...ervice::loadLocations() does only seem to accept null|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    public function loadLocationChildren(Location $location, $offset = 0, $limit = 25, array $prioritizedLanguages = null)
127
    {
128
        return $this->service->loadLocationChildren($location, $offset, $limit, $prioritizedLanguages);
0 ignored issues
show
Bug introduced by
It seems like $prioritizedLanguages defined by parameter $prioritizedLanguages on line 126 can also be of type array; however, eZ\Publish\API\Repositor...:loadLocationChildren() does only seem to accept null|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function loadParentLocationsForDraftContent(VersionInfo $versionInfo, array $prioritizedLanguages = null)
135
    {
136
        return $this->service->loadParentLocationsForDraftContent($versionInfo, $prioritizedLanguages);
0 ignored issues
show
Bug introduced by
It seems like $prioritizedLanguages defined by parameter $prioritizedLanguages on line 134 can also be of type array; however, eZ\Publish\API\Repositor...ationsForDraftContent() does only seem to accept null|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
137
    }
138
139
    /**
140
     * Returns the number of children which are readable by the current user of a location object.
141
     *
142
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
143
     *
144
     * @return int
145
     */
146
    public function getLocationChildCount(Location $location)
147
    {
148
        return $this->service->getLocationChildCount($location);
149
    }
150
151
    /**
152
     * Creates the new $location in the content repository for the given content.
153
     *
154
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create this location
155
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the content is already below the specified parent
156
     *                                        or the parent is a sub location of the location of the content
157
     *                                        or if set the remoteId exists already
158
     *
159
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
160
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct
161
     *
162
     * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created Location
163
     */
164
    public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct)
165
    {
166
        $returnValue = $this->service->createLocation($contentInfo, $locationCreateStruct);
167
        $this->signalDispatcher->emit(
168
            new CreateLocationSignal(
169
                array(
170
                    'contentId' => $contentInfo->id,
171
                    'locationId' => $returnValue->id,
172
                    'parentLocationId' => $returnValue->parentLocationId,
173
                )
174
            )
175
        );
176
177
        return $returnValue;
178
    }
179
180
    /**
181
     * Updates $location in the content repository.
182
     *
183
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
184
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
185
     *
186
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
187
     * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
188
     *
189
     * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
190
     */
191
    public function updateLocation(Location $location, LocationUpdateStruct $locationUpdateStruct)
192
    {
193
        $returnValue = $this->service->updateLocation($location, $locationUpdateStruct);
194
        $this->signalDispatcher->emit(
195
            new UpdateLocationSignal(
196
                array(
197
                    'contentId' => $location->contentId,
198
                    'locationId' => $location->id,
199
                    'parentLocationId' => $location->parentLocationId,
200
                )
201
            )
202
        );
203
204
        return $returnValue;
205
    }
206
207
    /**
208
     * Swaps the contents held by $location1 and $location2.
209
     *
210
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to swap content
211
     *
212
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location1
213
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location2
214
     */
215
    public function swapLocation(Location $location1, Location $location2)
216
    {
217
        $returnValue = $this->service->swapLocation($location1, $location2);
218
        $this->signalDispatcher->emit(
219
            new SwapLocationSignal(
220
                array(
221
                    'location1Id' => $location1->id,
222
                    'content1Id' => $location1->contentId,
223
                    'parentLocation1Id' => $location1->parentLocationId,
224
                    'location2Id' => $location2->id,
225
                    'content2Id' => $location2->contentId,
226
                    'parentLocation2Id' => $location2->parentLocationId,
227
                )
228
            )
229
        );
230
231
        return $returnValue;
232
    }
233
234
    /**
235
     * Hides the $location and marks invisible all descendants of $location.
236
     *
237
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to hide this location
238
     *
239
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
240
     *
241
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
242
     */
243 View Code Duplication
    public function hideLocation(Location $location)
244
    {
245
        $returnValue = $this->service->hideLocation($location);
246
        $this->signalDispatcher->emit(
247
            new HideLocationSignal(
248
                array(
249
                    'locationId' => $location->id,
250
                    'contentId' => $location->contentId,
251
                    'currentVersionNo' => $returnValue->getContentInfo()->currentVersionNo,
252
                    'parentLocationId' => $returnValue->parentLocationId,
253
                )
254
            )
255
        );
256
257
        return $returnValue;
258
    }
259
260
    /**
261
     * Unhides the $location.
262
     *
263
     * This method and marks visible all descendants of $locations
264
     * until a hidden location is found.
265
     *
266
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to unhide this location
267
     *
268
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
269
     *
270
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
271
     */
272 View Code Duplication
    public function unhideLocation(Location $location)
273
    {
274
        $returnValue = $this->service->unhideLocation($location);
275
        $this->signalDispatcher->emit(
276
            new UnhideLocationSignal(
277
                array(
278
                    'locationId' => $location->id,
279
                    'contentId' => $location->contentId,
280
                    'currentVersionNo' => $returnValue->getContentInfo()->currentVersionNo,
281
                    'parentLocationId' => $returnValue->parentLocationId,
282
                )
283
            )
284
        );
285
286
        return $returnValue;
287
    }
288
289
    /**
290
     * Moves the subtree to $newParentLocation.
291
     *
292
     * If a user has the permission to move the location to a target location
293
     * he can do it regardless of an existing descendant on which the user has no permission.
294
     *
295
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to move this location to the target
296
     *
297
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
298
     * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation
299
     */
300
    public function moveSubtree(Location $location, Location $newParentLocation)
301
    {
302
        $returnValue = $this->service->moveSubtree($location, $newParentLocation);
303
        $this->signalDispatcher->emit(
304
            new MoveSubtreeSignal(
305
                array(
306
                    'locationId' => $location->id,
307
                    'newParentLocationId' => $newParentLocation->id,
308
                    'oldParentLocationId' => $location->parentLocationId,
309
                )
310
            )
311
        );
312
313
        return $returnValue;
314
    }
315
316
    /**
317
     * Deletes $location and all its descendants.
318
     *
319
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant
320
     *
321
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
322
     */
323 View Code Duplication
    public function deleteLocation(Location $location)
324
    {
325
        $this->service->deleteLocation($location);
326
        $this->signalDispatcher->emit(
327
            new DeleteLocationSignal(
328
                array(
329
                    'contentId' => $location->contentId,
330
                    'locationId' => $location->id,
331
                    'parentLocationId' => $location->parentLocationId,
332
                )
333
            )
334
        );
335
    }
336
337
    /**
338
     * Instantiates a new location create class.
339
     *
340
     * @param mixed $parentLocationId the parent under which the new location should be created
341
     * @param eZ\Publish\API\Repository\Values\ContentType\ContentType|null $contentType
342
     *
343
     * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
344
     */
345
    public function newLocationCreateStruct($parentLocationId, ContentType $contentType = null)
346
    {
347
        return $this->service->newLocationCreateStruct($parentLocationId, $contentType);
348
    }
349
350
    /**
351
     * Instantiates a new location update class.
352
     *
353
     * @return \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct
354
     */
355
    public function newLocationUpdateStruct()
356
    {
357
        return $this->service->newLocationUpdateStruct();
358
    }
359
360
    /**
361
     * Get the total number of all existing Locations. Can be combined with loadAllLocations.
362
     *
363
     * @see loadAllLocations
364
     *
365
     * @return int Total number of Locations
366
     */
367
    public function getAllLocationsCount(): int
368
    {
369
        return $this->service->getAllLocationsCount();
370
    }
371
372
    /**
373
     * Bulk-load all existing Locations, constrained by $limit and $offset to paginate results.
374
     *
375
     * @param int $limit
376
     * @param int $offset
377
     *
378
     * @return \eZ\Publish\API\Repository\Values\Content\Location[]
379
     */
380
    public function loadAllLocations(int $offset = 0, int $limit = 25): array
381
    {
382
        return $this->service->loadAllLocations($offset, $limit);
383
    }
384
}
385