Completed
Push — EZP-26057-permission-api ( b3fc4f )
by
unknown
25:48
created

Repository::hasAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Repository 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
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\Repository;
12
13
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
14
use eZ\Publish\API\Repository\Values\ValueObject;
15
use eZ\Publish\API\Repository\Values\User\User;
16
use eZ\Publish\API\Repository\Values\User\UserReference as APIUserReference;
17
use eZ\Publish\API\Repository\Values\User\Limitation;
18
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue;
19
use eZ\Publish\Core\Repository\Values\User\UserReference;
20
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler;
21
use eZ\Publish\SPI\Search\Handler as SearchHandler;
22
use Exception;
23
use RuntimeException;
24
25
/**
26
 * Repository class.
27
 */
28
class Repository implements RepositoryInterface
29
{
30
    /**
31
     * Repository Handler object.
32
     *
33
     * @var \eZ\Publish\SPI\Persistence\Handler
34
     */
35
    protected $persistenceHandler;
36
37
    /**
38
     * Instance of main Search Handler.
39
     *
40
     * @var \eZ\Publish\SPI\Search\Handler
41
     */
42
    protected $searchHandler;
43
44
    /**
45
     * @deprecated since 6.5, current user handling is moved to PermissionService
46
     *
47
     * Currently logged in user object if already loaded.
48
     *
49
     * @var \eZ\Publish\API\Repository\Values\User\User|null
50
     */
51
    protected $currentUser;
52
53
    /**
54
     * @deprecated since 6.5, current user handling is moved to PermissionService
55
     *
56
     * Currently logged in user reference for permission purposes.
57
     *
58
     * @var \eZ\Publish\API\Repository\Values\User\UserReference
59
     */
60
    protected $currentUserRef;
61
62
    /**
63
     * Instance of content service.
64
     *
65
     * @var \eZ\Publish\API\Repository\ContentService
66
     */
67
    protected $contentService;
68
69
    /**
70
     * Instance of section service.
71
     *
72
     * @var \eZ\Publish\API\Repository\SectionService
73
     */
74
    protected $sectionService;
75
76
    /**
77
     * Instance of role service.
78
     *
79
     * @var \eZ\Publish\API\Repository\RoleService
80
     */
81
    protected $roleService;
82
83
    /**
84
     * Instance of search service.
85
     *
86
     * @var \eZ\Publish\API\Repository\SearchService
87
     */
88
    protected $searchService;
89
90
    /**
91
     * Instance of user service.
92
     *
93
     * @var \eZ\Publish\API\Repository\UserService
94
     */
95
    protected $userService;
96
97
    /**
98
     * Instance of language service.
99
     *
100
     * @var \eZ\Publish\API\Repository\LanguageService
101
     */
102
    protected $languageService;
103
104
    /**
105
     * Instance of location service.
106
     *
107
     * @var \eZ\Publish\API\Repository\LocationService
108
     */
109
    protected $locationService;
110
111
    /**
112
     * Instance of Trash service.
113
     *
114
     * @var \eZ\Publish\API\Repository\TrashService
115
     */
116
    protected $trashService;
117
118
    /**
119
     * Instance of content type service.
120
     *
121
     * @var \eZ\Publish\API\Repository\ContentTypeService
122
     */
123
    protected $contentTypeService;
124
125
    /**
126
     * Instance of object state service.
127
     *
128
     * @var \eZ\Publish\API\Repository\ObjectStateService
129
     */
130
    protected $objectStateService;
131
132
    /**
133
     * Instance of field type service.
134
     *
135
     * @var \eZ\Publish\API\Repository\FieldTypeService
136
     */
137
    protected $fieldTypeService;
138
139
    /**
140
     * Instance of FieldTypeRegistry.
141
     *
142
     * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry
143
     */
144
    private $fieldTypeRegistry;
145
146
    /**
147
     * Instance of NameableFieldTypeRegistry.
148
     *
149
     * @var \eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry
150
     */
151
    private $nameableFieldTypeRegistry;
152
153
    /**
154
     * Instance of name schema resolver service.
155
     *
156
     * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService
157
     */
158
    protected $nameSchemaService;
159
160
    /**
161
     * Instance of relation processor service.
162
     *
163
     * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor
164
     */
165
    protected $relationProcessor;
166
167
    /**
168
     * Instance of URL alias service.
169
     *
170
     * @var \eZ\Publish\Core\Repository\URLAliasService
171
     */
172
    protected $urlAliasService;
173
174
    /**
175
     * Instance of URL wildcard service.
176
     *
177
     * @var \eZ\Publish\Core\Repository\URLWildcardService
178
     */
179
    protected $urlWildcardService;
180
181
    /**
182
     * Instance of permission service.
183
     *
184
     * @var \eZ\Publish\Core\Repository\PermissionService
185
     */
186
    protected $permissionService;
187
188
    /**
189
     * Service settings, first level key is service name.
190
     *
191
     * @var array
192
     */
193
    protected $serviceSettings;
194
195
    /**
196
     * Instance of role service.
197
     *
198
     * @var \eZ\Publish\Core\Repository\Helper\LimitationService
199
     */
200
    protected $limitationService;
201
202
    /**
203
     * @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper
204
     */
205
    protected $roleDomainMapper;
206
207
    /**
208
     * Instance of domain mapper.
209
     *
210
     * @var \eZ\Publish\Core\Repository\Helper\DomainMapper
211
     */
212
    protected $domainMapper;
213
214
    /**
215
     * Instance of content type domain mapper.
216
     *
217
     * @var \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
218
     */
219
    protected $contentTypeDomainMapper;
220
221
    /**
222
     * Instance of permissions criterion handler.
223
     *
224
     * @var \eZ\Publish\Core\Repository\PermissionsCriterionHandler
225
     */
226
    protected $permissionsCriterionHandler;
227
228
    /**
229
     * Array of arrays of commit events indexed by the transaction count.
230
     *
231
     * @var array
232
     */
233
    protected $commitEventsQueue = array();
234
235
    /**
236
     * @var int
237
     */
238
    protected $transactionDepth = 0;
239
240
    /**
241
     * @var int
242
     */
243
    private $transactionCount = 0;
244
245
    /**
246
     * Constructor.
247
     *
248
     * Construct repository object with provided storage engine
249
     *
250
     * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler
251
     * @param \eZ\Publish\SPI\Search\Handler $searchHandler
252
     * @param array $serviceSettings
253
     * @param \eZ\Publish\API\Repository\Values\User\UserReference|null $user
254
     */
255
    public function __construct(
256
        PersistenceHandler $persistenceHandler,
257
        SearchHandler $searchHandler,
258
        array $serviceSettings = array(),
259
        APIUserReference $user = null
260
    ) {
261
        $this->persistenceHandler = $persistenceHandler;
262
        $this->searchHandler = $searchHandler;
263
        $this->serviceSettings = $serviceSettings + array(
264
            'content' => array(),
265
            'contentType' => array(),
266
            'location' => array(),
267
            'section' => array(),
268
            'role' => array(),
269
            'user' => array(
270
                'anonymousUserID' => 10,
271
            ),
272
            'language' => array(),
273
            'trash' => array(),
274
            'io' => array(),
275
            'objectState' => array(),
276
            'search' => array(),
277
            'fieldType' => array(),
278
            'nameableFieldTypes' => array(),
279
            'urlAlias' => array(),
280
            'urlWildcard' => array(),
281
            'nameSchema' => array(),
282
            'languages' => array(),
283
        );
284
285
        if (!empty($this->serviceSettings['languages'])) {
286
            $this->serviceSettings['language']['languages'] = $this->serviceSettings['languages'];
287
        }
288
289
        if ($user instanceof User) {
290
            $this->currentUser = $user;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
291
            $this->currentUserRef = new UserReference($user->getUserId());
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
292
        } elseif ($user instanceof APIUserReference) {
293
            $this->currentUserRef = $user;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
294
        } else {
295
            $this->currentUserRef = new UserReference($this->serviceSettings['user']['anonymousUserID']);
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
296
        }
297
    }
298
299
    /**
300
     * @deprecated since 6.5, the method is moved to PermissionService
301
     *
302
     * Get current user.
303
     *
304
     * Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}
305
     *
306
     * @return \eZ\Publish\API\Repository\Values\User\User
307
     */
308
    public function getCurrentUser()
309
    {
310
        $currentUser = $this->getPermissionService()->getCurrentUser();
311
312
        if ($this->currentUser === null) {
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
313
            $this->currentUser = $currentUser;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
314
        }
315
316
        return $currentUser;
317
    }
318
319
    /**
320
     * @deprecated since 6.5, the method is moved to PermissionService
321
     *
322
     * Get current user reference.
323
     *
324
     * @since 5.4.5
325
     * @return \eZ\Publish\API\Repository\Values\User\UserReference
326
     */
327
    public function getCurrentUserReference()
328
    {
329
        return $this->getPermissionService()->getCurrentUserReference();
330
    }
331
332
    /**
333
     * @deprecated since 6.5, the method is moved to PermissionService
334
     *
335
     * Sets the current user to the given $user.
336
     *
337
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
338
     *
339
     * @throws InvalidArgumentValue If UserReference does not contain a id
340
     */
341 View Code Duplication
    public function setCurrentUser(APIUserReference $user)
342
    {
343
        $id = $user->getUserId();
344
        if (!$id) {
345
            throw new InvalidArgumentValue('$user->getUserId()', $id);
346
        }
347
348
        if ($user instanceof User) {
349
            $this->currentUser = $user;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
350
            $this->currentUserRef = new UserReference($id);
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
351
        } else {
352
            $this->currentUser = null;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
353
            $this->currentUserRef = $user;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
354
        }
355
356
        return $this->getPermissionService()->setCurrentUser($user);
357
    }
358
359
    /**
360
     * Allows API execution to be performed with full access sand-boxed.
361
     *
362
     * The closure sandbox will do a catch all on exceptions and rethrow after
363
     * re-setting the sudo flag.
364
     *
365
     * Example use:
366
     *     $location = $repository->sudo(
367
     *         function ( Repository $repo ) use ( $locationId )
368
     *         {
369
     *             return $repo->getLocationService()->loadLocation( $locationId )
370
     *         }
371
     *     );
372
     *
373
     *
374
     * @param \Closure $callback
375
     * @param \eZ\Publish\API\Repository\Repository $outerRepository
376
     *
377
     * @throws \RuntimeException Thrown on recursive sudo() use.
378
     * @throws \Exception Re throws exceptions thrown inside $callback
379
     *
380
     * @return mixed
381
     */
382
    public function sudo(\Closure $callback, RepositoryInterface $outerRepository = null)
383
    {
384
        return $this->getPermissionService()->sudo($callback, $outerRepository);
385
    }
386
387
    /**
388
     * @deprecated since 6.5, the method is moved to PermissionService
389
     *
390
     * Check if user has access to a given module / function.
391
     *
392
     * Low level function, use canUser instead if you have objects to check against.
393
     *
394
     * @param string $module
395
     * @param string $function
396
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
397
     *
398
     * @return bool|array Bool if user has full or no access, array if limitations if not
399
     */
400
    public function hasAccess($module, $function, APIUserReference $user = null)
401
    {
402
        return $this->getPermissionService()->hasAccess($module, $function, $user);
403
    }
404
405
    /**
406
     * @deprecated since 6.5, the method is moved to PermissionService
407
     *
408
     * Check if user has access to a given action on a given value object.
409
     *
410
     * Indicates if the current user is allowed to perform an action given by the function on the given
411
     * objects.
412
     *
413
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If any of the arguments are invalid
414
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If value of the LimitationValue is unsupported
415
     *
416
     * @param string $module The module, aka controller identifier to check permissions on
417
     * @param string $function The function, aka the controller action to check permissions on
418
     * @param \eZ\Publish\API\Repository\Values\ValueObject $object The object to check if the user has access to
419
     * @param mixed $targets The location, parent or "assignment" value object, or an array of the same
420
     *
421
     * @return bool
422
     */
423
    public function canUser($module, $function, ValueObject $object, $targets = null)
424
    {
425
        return $this->getPermissionService()->canUser($module, $function, $object, $targets);
426
    }
427
428
    /**
429
     * Get Content Service.
430
     *
431
     * Get service object to perform operations on Content objects and it's aggregate members.
432
     *
433
     * @return \eZ\Publish\API\Repository\ContentService
434
     */
435 View Code Duplication
    public function getContentService()
436
    {
437
        if ($this->contentService !== null) {
438
            return $this->contentService;
439
        }
440
441
        $this->contentService = new ContentService(
442
            $this,
443
            $this->persistenceHandler,
444
            $this->getDomainMapper(),
445
            $this->getRelationProcessor(),
446
            $this->getNameSchemaService(),
447
            $this->getFieldTypeRegistry(),
448
            $this->serviceSettings['content']
449
        );
450
451
        return $this->contentService;
452
    }
453
454
    /**
455
     * Get Content Language Service.
456
     *
457
     * Get service object to perform operations on Content language objects
458
     *
459
     * @return \eZ\Publish\API\Repository\LanguageService
460
     */
461
    public function getContentLanguageService()
462
    {
463
        if ($this->languageService !== null) {
464
            return $this->languageService;
465
        }
466
467
        $this->languageService = new LanguageService(
468
            $this,
469
            $this->persistenceHandler->contentLanguageHandler(),
470
            $this->serviceSettings['language']
471
        );
472
473
        return $this->languageService;
474
    }
475
476
    /**
477
     * Get Content Type Service.
478
     *
479
     * Get service object to perform operations on Content Type objects and it's aggregate members.
480
     * ( Group, Field & FieldCategory )
481
     *
482
     * @return \eZ\Publish\API\Repository\ContentTypeService
483
     */
484 View Code Duplication
    public function getContentTypeService()
485
    {
486
        if ($this->contentTypeService !== null) {
487
            return $this->contentTypeService;
488
        }
489
490
        $this->contentTypeService = new ContentTypeService(
491
            $this,
492
            $this->persistenceHandler->contentTypeHandler(),
493
            $this->getDomainMapper(),
494
            $this->getContentTypeDomainMapper(),
495
            $this->getFieldTypeRegistry(),
496
            $this->serviceSettings['contentType']
497
        );
498
499
        return $this->contentTypeService;
500
    }
501
502
    /**
503
     * Get Content Location Service.
504
     *
505
     * Get service object to perform operations on Location objects and subtrees
506
     *
507
     * @return \eZ\Publish\API\Repository\LocationService
508
     */
509
    public function getLocationService()
510
    {
511
        if ($this->locationService !== null) {
512
            return $this->locationService;
513
        }
514
515
        $this->locationService = new LocationService(
516
            $this,
517
            $this->persistenceHandler,
518
            $this->getDomainMapper(),
519
            $this->getNameSchemaService(),
520
            $this->getPermissionsCriterionHandler(),
521
            $this->serviceSettings['location']
522
        );
523
524
        return $this->locationService;
525
    }
526
527
    /**
528
     * Get Content Trash service.
529
     *
530
     * Trash service allows to perform operations related to location trash
531
     * (trash/untrash, load/list from trash...)
532
     *
533
     * @return \eZ\Publish\API\Repository\TrashService
534
     */
535
    public function getTrashService()
536
    {
537
        if ($this->trashService !== null) {
538
            return $this->trashService;
539
        }
540
541
        $this->trashService = new TrashService(
542
            $this,
543
            $this->persistenceHandler,
544
            $this->getNameSchemaService(),
545
            $this->serviceSettings['trash']
546
        );
547
548
        return $this->trashService;
549
    }
550
551
    /**
552
     * Get Content Section Service.
553
     *
554
     * Get Section service that lets you manipulate section objects
555
     *
556
     * @return \eZ\Publish\API\Repository\SectionService
557
     */
558
    public function getSectionService()
559
    {
560
        if ($this->sectionService !== null) {
561
            return $this->sectionService;
562
        }
563
564
        $this->sectionService = new SectionService(
565
            $this,
566
            $this->persistenceHandler->sectionHandler(),
567
            $this->serviceSettings['section']
568
        );
569
570
        return $this->sectionService;
571
    }
572
573
    /**
574
     * Get User Service.
575
     *
576
     * Get service object to perform operations on Users and UserGroup
577
     *
578
     * @return \eZ\Publish\API\Repository\UserService
579
     */
580
    public function getUserService()
581
    {
582
        if ($this->userService !== null) {
583
            return $this->userService;
584
        }
585
586
        $this->userService = new UserService(
587
            $this,
588
            $this->persistenceHandler->userHandler(),
589
            $this->serviceSettings['user']
590
        );
591
592
        return $this->userService;
593
    }
594
595
    /**
596
     * Get URLAliasService.
597
     *
598
     * @return \eZ\Publish\API\Repository\URLAliasService
599
     */
600
    public function getURLAliasService()
601
    {
602
        if ($this->urlAliasService !== null) {
603
            return $this->urlAliasService;
604
        }
605
606
        $this->urlAliasService = new URLAliasService(
607
            $this,
608
            $this->persistenceHandler->urlAliasHandler(),
609
            $this->serviceSettings['urlAlias']
610
        );
611
612
        return $this->urlAliasService;
613
    }
614
615
    /**
616
     * Get URLWildcardService.
617
     *
618
     * @return \eZ\Publish\API\Repository\URLWildcardService
619
     */
620
    public function getURLWildcardService()
621
    {
622
        if ($this->urlWildcardService !== null) {
623
            return $this->urlWildcardService;
624
        }
625
626
        $this->urlWildcardService = new URLWildcardService(
627
            $this,
628
            $this->persistenceHandler->urlWildcardHandler(),
629
            $this->serviceSettings['urlWildcard']
630
        );
631
632
        return $this->urlWildcardService;
633
    }
634
635
    /**
636
     * Get ObjectStateService.
637
     *
638
     * @return \eZ\Publish\API\Repository\ObjectStateService
639
     */
640
    public function getObjectStateService()
641
    {
642
        if ($this->objectStateService !== null) {
643
            return $this->objectStateService;
644
        }
645
646
        $this->objectStateService = new ObjectStateService(
647
            $this,
648
            $this->persistenceHandler->objectStateHandler(),
649
            $this->serviceSettings['objectState']
650
        );
651
652
        return $this->objectStateService;
653
    }
654
655
    /**
656
     * Get RoleService.
657
     *
658
     * @return \eZ\Publish\API\Repository\RoleService
659
     */
660
    public function getRoleService()
661
    {
662
        if ($this->roleService !== null) {
663
            return $this->roleService;
664
        }
665
666
        $this->roleService = new RoleService(
667
            $this,
668
            $this->persistenceHandler->userHandler(),
669
            $this->getLimitationService(),
670
            $this->getRoleDomainMapper(),
671
            $this->serviceSettings['role']
672
        );
673
674
        return $this->roleService;
675
    }
676
677
    /**
678
     * Get LimitationService.
679
     *
680
     * @return \eZ\Publish\Core\Repository\Helper\LimitationService
681
     */
682
    protected function getLimitationService()
683
    {
684
        if ($this->limitationService !== null) {
685
            return $this->limitationService;
686
        }
687
688
        $this->limitationService = new Helper\LimitationService($this->serviceSettings['role']);
689
690
        return $this->limitationService;
691
    }
692
693
    /**
694
     * Get RoleDomainMapper.
695
     *
696
     * @return \eZ\Publish\Core\Repository\Helper\RoleDomainMapper
697
     */
698
    protected function getRoleDomainMapper()
699
    {
700
        if ($this->roleDomainMapper !== null) {
701
            return $this->roleDomainMapper;
702
        }
703
704
        $this->roleDomainMapper = new Helper\RoleDomainMapper($this->getLimitationService());
705
706
        return $this->roleDomainMapper;
707
    }
708
709
    /**
710
     * Get SearchService.
711
     *
712
     * @return \eZ\Publish\API\Repository\SearchService
713
     */
714
    public function getSearchService()
715
    {
716
        if ($this->searchService !== null) {
717
            return $this->searchService;
718
        }
719
720
        $this->searchService = new SearchService(
721
            $this,
722
            $this->searchHandler,
723
            $this->getDomainMapper(),
724
            $this->getPermissionsCriterionHandler(),
725
            $this->serviceSettings['search']
726
        );
727
728
        return $this->searchService;
729
    }
730
731
    /**
732
     * Get FieldTypeService.
733
     *
734
     * @return \eZ\Publish\API\Repository\FieldTypeService
735
     */
736
    public function getFieldTypeService()
737
    {
738
        if ($this->fieldTypeService !== null) {
739
            return $this->fieldTypeService;
740
        }
741
742
        $this->fieldTypeService = new FieldTypeService($this->getFieldTypeRegistry());
743
744
        return $this->fieldTypeService;
745
    }
746
747
    /**
748
     * Get PermissionService.
749
     *
750
     * @return \eZ\Publish\API\Repository\PermissionService
751
     */
752
    public function getPermissionService()
753
    {
754
        if ($this->permissionService === null) {
755
            $this->permissionService = new PermissionService(
756
                $this,
757
                $this->getUserService(),
758
                $this->getRoleDomainMapper(),
759
                $this->getLimitationService(),
760
                $this->persistenceHandler->userHandler(),
761
                $this->currentUserRef,
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
762
                $this->currentUser
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.5, current user handling is moved to PermissionService Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
763
            );
764
        }
765
766
        return $this->permissionService;
767
    }
768
769
    /**
770
     * @return Helper\FieldTypeRegistry
771
     */
772
    protected function getFieldTypeRegistry()
773
    {
774
        if ($this->fieldTypeRegistry !== null) {
775
            return $this->fieldTypeRegistry;
776
        }
777
778
        $this->fieldTypeRegistry = new Helper\FieldTypeRegistry($this->serviceSettings['fieldType']);
779
780
        return $this->fieldTypeRegistry;
781
    }
782
783
    /**
784
     * @return Helper\NameableFieldTypeRegistry
785
     */
786
    protected function getNameableFieldTypeRegistry()
787
    {
788
        if ($this->nameableFieldTypeRegistry !== null) {
789
            return $this->nameableFieldTypeRegistry;
790
        }
791
792
        $this->nameableFieldTypeRegistry = new Helper\NameableFieldTypeRegistry($this->serviceSettings['nameableFieldTypes']);
793
794
        return $this->nameableFieldTypeRegistry;
795
    }
796
797
    /**
798
     * Get NameSchemaResolverService.
799
     *
800
     *
801
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
802
     *
803
     * @internal
804
     * @private
805
     *
806
     * @return \eZ\Publish\Core\Repository\Helper\NameSchemaService
807
     */
808
    public function getNameSchemaService()
809
    {
810
        if ($this->nameSchemaService !== null) {
811
            return $this->nameSchemaService;
812
        }
813
814
        $this->nameSchemaService = new Helper\NameSchemaService(
815
            $this->persistenceHandler->contentTypeHandler(),
816
            $this->getContentTypeDomainMapper(),
817
            $this->getNameableFieldTypeRegistry(),
818
            $this->serviceSettings['nameSchema']
819
        );
820
821
        return $this->nameSchemaService;
822
    }
823
824
    /**
825
     * Get RelationProcessor.
826
     *
827
     *
828
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
829
     *
830
     * @return \eZ\Publish\Core\Repository\Helper\RelationProcessor
831
     */
832
    protected function getRelationProcessor()
833
    {
834
        if ($this->relationProcessor !== null) {
835
            return $this->relationProcessor;
836
        }
837
838
        $this->relationProcessor = new Helper\RelationProcessor($this->persistenceHandler);
839
840
        return $this->relationProcessor;
841
    }
842
843
    /**
844
     * Get Content Domain Mapper.
845
     *
846
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
847
     *
848
     * @return \eZ\Publish\Core\Repository\Helper\DomainMapper
849
     */
850
    protected function getDomainMapper()
851
    {
852
        if ($this->domainMapper !== null) {
853
            return $this->domainMapper;
854
        }
855
856
        $this->domainMapper = new Helper\DomainMapper(
857
            $this->persistenceHandler->contentHandler(),
858
            $this->persistenceHandler->locationHandler(),
859
            $this->persistenceHandler->contentTypeHandler(),
860
            $this->persistenceHandler->contentLanguageHandler(),
861
            $this->getFieldTypeRegistry()
862
        );
863
864
        return $this->domainMapper;
865
    }
866
867
    /**
868
     * Get ContentType Domain Mapper.
869
     *
870
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
871
     *
872
     * @return \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
873
     */
874
    protected function getContentTypeDomainMapper()
875
    {
876
        if ($this->contentTypeDomainMapper !== null) {
877
            return $this->contentTypeDomainMapper;
878
        }
879
880
        $this->contentTypeDomainMapper = new Helper\ContentTypeDomainMapper(
881
            $this->persistenceHandler->contentLanguageHandler(),
882
            $this->getFieldTypeRegistry()
883
        );
884
885
        return $this->contentTypeDomainMapper;
886
    }
887
888
    /**
889
     * Get PermissionsCriterionHandler.
890
     *
891
     *
892
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
893
     *
894
     * @return \eZ\Publish\Core\Repository\PermissionsCriterionHandler
895
     */
896
    protected function getPermissionsCriterionHandler()
897
    {
898
        if ($this->permissionsCriterionHandler === null) {
899
            $this->permissionsCriterionHandler = new PermissionsCriterionHandler(
900
                $this->getPermissionService(),
901
                $this->getLimitationService()
902
            );
903
        }
904
905
        return $this->permissionsCriterionHandler;
906
    }
907
908
    /**
909
     * Begin transaction.
910
     *
911
     * Begins an transaction, make sure you'll call commit or rollback when done,
912
     * otherwise work will be lost.
913
     */
914
    public function beginTransaction()
915
    {
916
        $this->persistenceHandler->beginTransaction();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\SPI\Persisten...ler::beginTransaction() has been deprecated with message: Since 5.3 {@use transactionHandler()->beginTransaction()}

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...
917
918
        ++$this->transactionDepth;
919
        $this->commitEventsQueue[++$this->transactionCount] = array();
920
    }
921
922
    /**
923
     * Commit transaction.
924
     *
925
     * Commit transaction, or throw exceptions if no transactions has been started.
926
     *
927
     * @throws RuntimeException If no transaction has been started
928
     */
929
    public function commit()
930
    {
931
        try {
932
            $this->persistenceHandler->commit();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\SPI\Persistence\Handler::commit() has been deprecated with message: Since 5.3 {@use transactionHandler()->commit()}

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...
933
934
            --$this->transactionDepth;
935
936
            if ($this->transactionDepth === 0) {
937
                $queueCountDown = count($this->commitEventsQueue);
938
                foreach ($this->commitEventsQueue as $eventsQueue) {
939
                    --$queueCountDown;
940
                    if (empty($eventsQueue)) {
941
                        continue;
942
                    }
943
944
                    $eventCountDown = count($eventsQueue);
945
                    foreach ($eventsQueue as $event) {
946
                        --$eventCountDown;
947
                        // event expects a boolean param, if true it means it is last event (for commit use)
948
                        $event($queueCountDown === 0 && $eventCountDown === 0);
949
                    }
950
                }
951
952
                $this->commitEventsQueue = array();
953
            }
954
        } catch (Exception $e) {
955
            throw new RuntimeException($e->getMessage(), 0, $e);
956
        }
957
    }
958
959
    /**
960
     * Rollback transaction.
961
     *
962
     * Rollback transaction, or throw exceptions if no transactions has been started.
963
     *
964
     * @throws RuntimeException If no transaction has been started
965
     */
966
    public function rollback()
967
    {
968
        try {
969
            $this->persistenceHandler->rollback();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\SPI\Persistence\Handler::rollback() has been deprecated with message: Since 5.3 {@use transactionHandler()->rollback()}

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...
970
971
            --$this->transactionDepth;
972
            unset($this->commitEventsQueue[$this->transactionCount]);
973
        } catch (Exception $e) {
974
            throw new RuntimeException($e->getMessage(), 0, $e);
975
        }
976
    }
977
978
    /**
979
     * Enqueue an event to be triggered at commit or directly if no transaction has started.
980
     *
981
     * @param Callable $event
982
     */
983
    public function commitEvent($event)
984
    {
985
        if ($this->transactionDepth !== 0) {
986
            $this->commitEventsQueue[$this->transactionCount][] = $event;
987
        } else {
988
            // event expects a boolean param, if true it means it is last event (for commit use)
989
            $event(true);
990
        }
991
    }
992
993
    /**
994
     * Only for internal use.
995
     *
996
     * Creates a \DateTime object for $timestamp in the current time zone
997
     *
998
     * @param int $timestamp
999
     *
1000
     * @return \DateTime
1001
     */
1002 View Code Duplication
    public function createDateTime($timestamp = null)
1003
    {
1004
        $dateTime = new \DateTime();
1005
        if ($timestamp !== null) {
1006
            $dateTime->setTimestamp($timestamp);
1007
        }
1008
1009
        return $dateTime;
1010
    }
1011
}
1012