Completed
Push — tolerant_search_service ( 768e04...a664cf )
by André
13:22
created

Repository::setBackgroundIndexer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
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
namespace eZ\Publish\Core\Repository;
10
11
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
12
use eZ\Publish\API\Repository\Values\ValueObject;
13
use eZ\Publish\API\Repository\Values\User\User;
14
use eZ\Publish\API\Repository\Values\User\UserReference as APIUserReference;
15
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue;
16
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;
17
use eZ\Publish\Core\Repository\Values\User\UserReference;
18
use eZ\Publish\Core\Search\Common\BackgroundIndexer;
19
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler;
20
use eZ\Publish\SPI\Search\Handler as SearchHandler;
21
use Exception;
22
use RuntimeException;
23
24
/**
25
 * Repository class.
26
 */
27
class Repository implements RepositoryInterface
28
{
29
    /**
30
     * Repository Handler object.
31
     *
32
     * @var \eZ\Publish\SPI\Persistence\Handler
33
     */
34
    protected $persistenceHandler;
35
36
    /**
37
     * Instance of main Search Handler.
38
     *
39
     * @var \eZ\Publish\SPI\Search\Handler
40
     */
41
    protected $searchHandler;
42
43
    /**
44
     * @deprecated since 6.6, to be removed. Current user handling is moved to PermissionResolver.
45
     *
46
     * Currently logged in user object if already loaded.
47
     *
48
     * @var \eZ\Publish\API\Repository\Values\User\User|null
49
     */
50
    protected $currentUser;
51
52
    /**
53
     * @deprecated since 6.6, to be removed. Current user handling is moved to PermissionResolver.
54
     *
55
     * Currently logged in user reference for permission purposes.
56
     *
57
     * @var \eZ\Publish\API\Repository\Values\User\UserReference
58
     */
59
    protected $currentUserRef;
60
61
    /**
62
     * Instance of content service.
63
     *
64
     * @var \eZ\Publish\API\Repository\ContentService
65
     */
66
    protected $contentService;
67
68
    /**
69
     * Instance of section service.
70
     *
71
     * @var \eZ\Publish\API\Repository\SectionService
72
     */
73
    protected $sectionService;
74
75
    /**
76
     * Instance of role service.
77
     *
78
     * @var \eZ\Publish\API\Repository\RoleService
79
     */
80
    protected $roleService;
81
82
    /**
83
     * Instance of search service.
84
     *
85
     * @var \eZ\Publish\API\Repository\SearchService
86
     */
87
    protected $searchService;
88
89
    /**
90
     * Instance of user service.
91
     *
92
     * @var \eZ\Publish\API\Repository\UserService
93
     */
94
    protected $userService;
95
96
    /**
97
     * Instance of language service.
98
     *
99
     * @var \eZ\Publish\API\Repository\LanguageService
100
     */
101
    protected $languageService;
102
103
    /**
104
     * Instance of location service.
105
     *
106
     * @var \eZ\Publish\API\Repository\LocationService
107
     */
108
    protected $locationService;
109
110
    /**
111
     * Instance of Trash service.
112
     *
113
     * @var \eZ\Publish\API\Repository\TrashService
114
     */
115
    protected $trashService;
116
117
    /**
118
     * Instance of content type service.
119
     *
120
     * @var \eZ\Publish\API\Repository\ContentTypeService
121
     */
122
    protected $contentTypeService;
123
124
    /**
125
     * Instance of object state service.
126
     *
127
     * @var \eZ\Publish\API\Repository\ObjectStateService
128
     */
129
    protected $objectStateService;
130
131
    /**
132
     * Instance of field type service.
133
     *
134
     * @var \eZ\Publish\API\Repository\FieldTypeService
135
     */
136
    protected $fieldTypeService;
137
138
    /**
139
     * Instance of FieldTypeRegistry.
140
     *
141
     * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry
142
     */
143
    private $fieldTypeRegistry;
144
145
    /**
146
     * Instance of NameableFieldTypeRegistry.
147
     *
148
     * @var \eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry
149
     */
150
    private $nameableFieldTypeRegistry;
151
152
    /**
153
     * Instance of name schema resolver service.
154
     *
155
     * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService
156
     */
157
    protected $nameSchemaService;
158
159
    /**
160
     * Instance of relation processor service.
161
     *
162
     * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor
163
     */
164
    protected $relationProcessor;
165
166
    /**
167
     * Instance of URL alias service.
168
     *
169
     * @var \eZ\Publish\Core\Repository\URLAliasService
170
     */
171
    protected $urlAliasService;
172
173
    /**
174
     * Instance of URL wildcard service.
175
     *
176
     * @var \eZ\Publish\Core\Repository\URLWildcardService
177
     */
178
    protected $urlWildcardService;
179
180
    /**
181
     * Instance of permission service.
182
     *
183
     * @var \eZ\Publish\Core\Repository\Permission\PermissionResolver
184
     */
185
    protected $permissionResolver;
186
187
    /**
188
     * Service settings, first level key is service name.
189
     *
190
     * @var array
191
     */
192
    protected $serviceSettings;
193
194
    /**
195
     * Instance of role service.
196
     *
197
     * @var \eZ\Publish\Core\Repository\Helper\LimitationService
198
     */
199
    protected $limitationService;
200
201
    /**
202
     * @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper
203
     */
204
    protected $roleDomainMapper;
205
206
    /**
207
     * Instance of domain mapper.
208
     *
209
     * @var \eZ\Publish\Core\Repository\Helper\DomainMapper
210
     */
211
    protected $domainMapper;
212
213
    /**
214
     * Instance of content type domain mapper.
215
     *
216
     * @var \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
217
     */
218
    protected $contentTypeDomainMapper;
219
220
    /**
221
     * Instance of permissions criterion handler.
222
     *
223
     * @var \eZ\Publish\Core\Repository\PermissionsCriterionHandler
224
     */
225
    protected $permissionsCriterionHandler;
226
227
    /**
228
     * @var \eZ\Publish\Core\Search\Common\BackgroundIndexer|null
229
     */
230
    protected $backgroundIndexer;
231
232
    /**
233
     * Array of arrays of commit events indexed by the transaction count.
234
     *
235
     * @var array
236
     */
237
    protected $commitEventsQueue = array();
238
239
    /**
240
     * @var int
241
     */
242
    protected $transactionDepth = 0;
243
244
    /**
245
     * @var int
246
     */
247
    private $transactionCount = 0;
248
249
    /**
250
     * Constructor.
251
     *
252
     * Construct repository object with provided storage engine
253
     *
254
     * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler
255
     * @param \eZ\Publish\SPI\Search\Handler $searchHandler
256
     * @param array $serviceSettings
257
     * @param \eZ\Publish\API\Repository\Values\User\UserReference|null $user
258
     */
259
    public function __construct(
260
        PersistenceHandler $persistenceHandler,
261
        SearchHandler $searchHandler,
262
        array $serviceSettings = array(),
263
        APIUserReference $user = null
264
    ) {
265
        $this->persistenceHandler = $persistenceHandler;
266
        $this->searchHandler = $searchHandler;
267
        $this->serviceSettings = $serviceSettings + array(
268
            'content' => array(),
269
            'contentType' => array(),
270
            'location' => array(),
271
            'section' => array(),
272
            'role' => array(),
273
            'user' => array(
274
                'anonymousUserID' => 10,
275
            ),
276
            'language' => array(),
277
            'trash' => array(),
278
            'io' => array(),
279
            'objectState' => array(),
280
            'search' => array(),
281
            'fieldType' => array(),
282
            'nameableFieldTypes' => array(),
283
            'urlAlias' => array(),
284
            'urlWildcard' => array(),
285
            'nameSchema' => array(),
286
            'languages' => array(),
287
        );
288
289
        if (!empty($this->serviceSettings['languages'])) {
290
            $this->serviceSettings['language']['languages'] = $this->serviceSettings['languages'];
291
        }
292
293
        if ($user instanceof User) {
294
            $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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
295
            $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.6, to be removed. Current user handling is moved to PermissionResolver. 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
        } elseif ($user instanceof APIUserReference) {
297
            $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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
298
        } else {
299
            $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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
300
        }
301
    }
302
303
    /**
304
     * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
305
     *
306
     * Get current user.
307
     *
308
     * Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}
309
     *
310
     * @return \eZ\Publish\API\Repository\Values\User\User
311
     */
312
    public function getCurrentUser()
313
    {
314
        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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
315
            $this->currentUser = $this->getUserService()->loadUser(
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. 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...
316
                $this->getPermissionResolver()->getCurrentUserReference()->getUserId()
317
            );
318
        }
319
320
        return $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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
321
    }
322
323
    /**
324
     * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
325
     *
326
     * Get current user reference.
327
     *
328
     * @since 5.4.5
329
     * @return \eZ\Publish\API\Repository\Values\User\UserReference
330
     */
331
    public function getCurrentUserReference()
332
    {
333
        return $this->getPermissionResolver()->getCurrentUserReference();
334
    }
335
336
    /**
337
     * @deprecated since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead.
338
     *
339
     * Sets the current user to the given $user.
340
     *
341
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
342
     *
343
     * @throws InvalidArgumentValue If UserReference does not contain a id
344
     */
345
    public function setCurrentUser(APIUserReference $user)
346
    {
347
        $id = $user->getUserId();
348
        if (!$id) {
349
            throw new InvalidArgumentValue('$user->getUserId()', $id);
350
        }
351
352
        if ($user instanceof User) {
353
            $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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
354
            $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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
355
        } else {
356
            $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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
357
            $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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
358
        }
359
360
        return $this->getPermissionResolver()->setCurrentUserReference($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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
361
    }
362
363
    /**
364
     * Allows API execution to be performed with full access sand-boxed.
365
     *
366
     * The closure sandbox will do a catch all on exceptions and rethrow after
367
     * re-setting the sudo flag.
368
     *
369
     * Example use:
370
     *     $location = $repository->sudo(
371
     *         function ( Repository $repo ) use ( $locationId )
372
     *         {
373
     *             return $repo->getLocationService()->loadLocation( $locationId )
374
     *         }
375
     *     );
376
     *
377
     *
378
     * @param \Closure $callback
379
     * @param \eZ\Publish\API\Repository\Repository $outerRepository
380
     *
381
     * @throws \RuntimeException Thrown on recursive sudo() use.
382
     * @throws \Exception Re throws exceptions thrown inside $callback
383
     *
384
     * @return mixed
385
     */
386
    public function sudo(\Closure $callback, RepositoryInterface $outerRepository = null)
387
    {
388
        return $this->getPermissionResolver()->sudo(
389
            $callback,
390
            $outerRepository !== null ? $outerRepository : $this
391
        );
392
    }
393
394
    /**
395
     * @deprecated since 6.6, to be removed. Use PermissionResolver::hasAccess() instead.
396
     *
397
     * Check if user has access to a given module / function.
398
     *
399
     * Low level function, use canUser instead if you have objects to check against.
400
     *
401
     * @param string $module
402
     * @param string $function
403
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
404
     *
405
     * @return bool|array Bool if user has full or no access, array if limitations if not
406
     */
407
    public function hasAccess($module, $function, APIUserReference $user = null)
408
    {
409
        return $this->getPermissionResolver()->hasAccess($module, $function, $user);
410
    }
411
412
    /**
413
     * @deprecated since 6.6, to be removed. Use PermissionResolver::canUser() instead.
414
     *
415
     * Check if user has access to a given action on a given value object.
416
     *
417
     * Indicates if the current user is allowed to perform an action given by the function on the given
418
     * objects.
419
     *
420
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If any of the arguments are invalid
421
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If value of the LimitationValue is unsupported
422
     *
423
     * @param string $module The module, aka controller identifier to check permissions on
424
     * @param string $function The function, aka the controller action to check permissions on
425
     * @param \eZ\Publish\API\Repository\Values\ValueObject $object The object to check if the user has access to
426
     * @param mixed $targets The location, parent or "assignment" value object, or an array of the same
427
     *
428
     * @return bool
429
     */
430
    public function canUser($module, $function, ValueObject $object, $targets = null)
431
    {
432
        if ($targets instanceof ValueObject) {
433
            $targets = array($targets);
434
        } elseif ($targets === null) {
435
            $targets = [];
436
        } elseif (!is_array($targets)) {
437
            throw new InvalidArgumentType(
438
                '$targets',
439
                'null|\\eZ\\Publish\\API\\Repository\\Values\\ValueObject|\\eZ\\Publish\\API\\Repository\\Values\\ValueObject[]',
440
                $targets
441
            );
442
        }
443
444
        return $this->getPermissionResolver()->canUser($module, $function, $object, $targets);
445
    }
446
447
    /**
448
     * Get Content Service.
449
     *
450
     * Get service object to perform operations on Content objects and it's aggregate members.
451
     *
452
     * @return \eZ\Publish\API\Repository\ContentService
453
     */
454 View Code Duplication
    public function getContentService()
455
    {
456
        if ($this->contentService !== null) {
457
            return $this->contentService;
458
        }
459
460
        $this->contentService = new ContentService(
461
            $this,
462
            $this->persistenceHandler,
463
            $this->getDomainMapper(),
464
            $this->getRelationProcessor(),
465
            $this->getNameSchemaService(),
466
            $this->getFieldTypeRegistry(),
467
            $this->serviceSettings['content']
468
        );
469
470
        return $this->contentService;
471
    }
472
473
    /**
474
     * Get Content Language Service.
475
     *
476
     * Get service object to perform operations on Content language objects
477
     *
478
     * @return \eZ\Publish\API\Repository\LanguageService
479
     */
480
    public function getContentLanguageService()
481
    {
482
        if ($this->languageService !== null) {
483
            return $this->languageService;
484
        }
485
486
        $this->languageService = new LanguageService(
487
            $this,
488
            $this->persistenceHandler->contentLanguageHandler(),
489
            $this->serviceSettings['language']
490
        );
491
492
        return $this->languageService;
493
    }
494
495
    /**
496
     * Get Content Type Service.
497
     *
498
     * Get service object to perform operations on Content Type objects and it's aggregate members.
499
     * ( Group, Field & FieldCategory )
500
     *
501
     * @return \eZ\Publish\API\Repository\ContentTypeService
502
     */
503 View Code Duplication
    public function getContentTypeService()
504
    {
505
        if ($this->contentTypeService !== null) {
506
            return $this->contentTypeService;
507
        }
508
509
        $this->contentTypeService = new ContentTypeService(
510
            $this,
511
            $this->persistenceHandler->contentTypeHandler(),
512
            $this->getDomainMapper(),
513
            $this->getContentTypeDomainMapper(),
514
            $this->getFieldTypeRegistry(),
515
            $this->serviceSettings['contentType']
516
        );
517
518
        return $this->contentTypeService;
519
    }
520
521
    /**
522
     * Get Content Location Service.
523
     *
524
     * Get service object to perform operations on Location objects and subtrees
525
     *
526
     * @return \eZ\Publish\API\Repository\LocationService
527
     */
528
    public function getLocationService()
529
    {
530
        if ($this->locationService !== null) {
531
            return $this->locationService;
532
        }
533
534
        $this->locationService = new LocationService(
535
            $this,
536
            $this->persistenceHandler,
537
            $this->getDomainMapper(),
538
            $this->getNameSchemaService(),
539
            $this->getPermissionsCriterionHandler(),
540
            $this->serviceSettings['location']
541
        );
542
543
        return $this->locationService;
544
    }
545
546
    /**
547
     * Get Content Trash service.
548
     *
549
     * Trash service allows to perform operations related to location trash
550
     * (trash/untrash, load/list from trash...)
551
     *
552
     * @return \eZ\Publish\API\Repository\TrashService
553
     */
554
    public function getTrashService()
555
    {
556
        if ($this->trashService !== null) {
557
            return $this->trashService;
558
        }
559
560
        $this->trashService = new TrashService(
561
            $this,
562
            $this->persistenceHandler,
563
            $this->getNameSchemaService(),
564
            $this->serviceSettings['trash']
565
        );
566
567
        return $this->trashService;
568
    }
569
570
    /**
571
     * Get Content Section Service.
572
     *
573
     * Get Section service that lets you manipulate section objects
574
     *
575
     * @return \eZ\Publish\API\Repository\SectionService
576
     */
577
    public function getSectionService()
578
    {
579
        if ($this->sectionService !== null) {
580
            return $this->sectionService;
581
        }
582
583
        $this->sectionService = new SectionService(
584
            $this,
585
            $this->persistenceHandler->sectionHandler(),
586
            $this->serviceSettings['section']
587
        );
588
589
        return $this->sectionService;
590
    }
591
592
    /**
593
     * Get User Service.
594
     *
595
     * Get service object to perform operations on Users and UserGroup
596
     *
597
     * @return \eZ\Publish\API\Repository\UserService
598
     */
599
    public function getUserService()
600
    {
601
        if ($this->userService !== null) {
602
            return $this->userService;
603
        }
604
605
        $this->userService = new UserService(
606
            $this,
607
            $this->persistenceHandler->userHandler(),
608
            $this->serviceSettings['user']
609
        );
610
611
        return $this->userService;
612
    }
613
614
    /**
615
     * Get URLAliasService.
616
     *
617
     * @return \eZ\Publish\API\Repository\URLAliasService
618
     */
619
    public function getURLAliasService()
620
    {
621
        if ($this->urlAliasService !== null) {
622
            return $this->urlAliasService;
623
        }
624
625
        $this->urlAliasService = new URLAliasService(
626
            $this,
627
            $this->persistenceHandler->urlAliasHandler(),
628
            $this->serviceSettings['urlAlias']
629
        );
630
631
        return $this->urlAliasService;
632
    }
633
634
    /**
635
     * Get URLWildcardService.
636
     *
637
     * @return \eZ\Publish\API\Repository\URLWildcardService
638
     */
639
    public function getURLWildcardService()
640
    {
641
        if ($this->urlWildcardService !== null) {
642
            return $this->urlWildcardService;
643
        }
644
645
        $this->urlWildcardService = new URLWildcardService(
646
            $this,
647
            $this->persistenceHandler->urlWildcardHandler(),
648
            $this->serviceSettings['urlWildcard']
649
        );
650
651
        return $this->urlWildcardService;
652
    }
653
654
    /**
655
     * Get ObjectStateService.
656
     *
657
     * @return \eZ\Publish\API\Repository\ObjectStateService
658
     */
659
    public function getObjectStateService()
660
    {
661
        if ($this->objectStateService !== null) {
662
            return $this->objectStateService;
663
        }
664
665
        $this->objectStateService = new ObjectStateService(
666
            $this,
667
            $this->persistenceHandler->objectStateHandler(),
668
            $this->serviceSettings['objectState']
669
        );
670
671
        return $this->objectStateService;
672
    }
673
674
    /**
675
     * Get RoleService.
676
     *
677
     * @return \eZ\Publish\API\Repository\RoleService
678
     */
679
    public function getRoleService()
680
    {
681
        if ($this->roleService !== null) {
682
            return $this->roleService;
683
        }
684
685
        $this->roleService = new RoleService(
686
            $this,
687
            $this->persistenceHandler->userHandler(),
688
            $this->getLimitationService(),
689
            $this->getRoleDomainMapper(),
690
            $this->serviceSettings['role']
691
        );
692
693
        return $this->roleService;
694
    }
695
696
    /**
697
     * Get LimitationService.
698
     *
699
     * @return \eZ\Publish\Core\Repository\Helper\LimitationService
700
     */
701
    protected function getLimitationService()
702
    {
703
        if ($this->limitationService !== null) {
704
            return $this->limitationService;
705
        }
706
707
        $this->limitationService = new Helper\LimitationService($this->serviceSettings['role']);
708
709
        return $this->limitationService;
710
    }
711
712
    /**
713
     * Get RoleDomainMapper.
714
     *
715
     * @return \eZ\Publish\Core\Repository\Helper\RoleDomainMapper
716
     */
717
    protected function getRoleDomainMapper()
718
    {
719
        if ($this->roleDomainMapper !== null) {
720
            return $this->roleDomainMapper;
721
        }
722
723
        $this->roleDomainMapper = new Helper\RoleDomainMapper($this->getLimitationService());
724
725
        return $this->roleDomainMapper;
726
    }
727
728
    /**
729
     * Get SearchService.
730
     *
731
     * @return \eZ\Publish\API\Repository\SearchService
732
     */
733
    public function getSearchService()
734
    {
735
        if ($this->searchService !== null) {
736
            return $this->searchService;
737
        }
738
739
        $this->searchService = new SearchService(
740
            $this,
741
            $this->searchHandler,
742
            $this->getDomainMapper(),
743
            $this->getPermissionsCriterionHandler(),
744
            $this->backgroundIndexer ?: new BackgroundIndexer\NullIndexer(),
745
            $this->serviceSettings['search']
746
        );
747
748
        return $this->searchService;
749
    }
750
751
    /**
752
     * Get FieldTypeService.
753
     *
754
     * @return \eZ\Publish\API\Repository\FieldTypeService
755
     */
756
    public function getFieldTypeService()
757
    {
758
        if ($this->fieldTypeService !== null) {
759
            return $this->fieldTypeService;
760
        }
761
762
        $this->fieldTypeService = new FieldTypeService($this->getFieldTypeRegistry());
763
764
        return $this->fieldTypeService;
765
    }
766
767
    /**
768
     * Get PermissionResolver.
769
     *
770
     * @return \eZ\Publish\API\Repository\PermissionResolver
771
     */
772
    public function getPermissionResolver()
773
    {
774
        if ($this->permissionResolver === null) {
775
            $this->permissionResolver = new Permission\PermissionResolver(
776
                $this->getRoleDomainMapper(),
777
                $this->getLimitationService(),
778
                $this->persistenceHandler->userHandler(),
779
                $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.6, to be removed. Current user handling is moved to PermissionResolver. 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...
780
            );
781
        }
782
783
        return $this->permissionResolver;
784
    }
785
786
    /**
787
     * @return Helper\FieldTypeRegistry
788
     */
789
    protected function getFieldTypeRegistry()
790
    {
791
        if ($this->fieldTypeRegistry !== null) {
792
            return $this->fieldTypeRegistry;
793
        }
794
795
        $this->fieldTypeRegistry = new Helper\FieldTypeRegistry($this->serviceSettings['fieldType']);
796
797
        return $this->fieldTypeRegistry;
798
    }
799
800
    /**
801
     * @return Helper\NameableFieldTypeRegistry
802
     */
803
    protected function getNameableFieldTypeRegistry()
804
    {
805
        if ($this->nameableFieldTypeRegistry !== null) {
806
            return $this->nameableFieldTypeRegistry;
807
        }
808
809
        $this->nameableFieldTypeRegistry = new Helper\NameableFieldTypeRegistry($this->serviceSettings['nameableFieldTypes']);
810
811
        return $this->nameableFieldTypeRegistry;
812
    }
813
814
    /**
815
     * Get NameSchemaResolverService.
816
     *
817
     *
818
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
819
     *
820
     * @internal
821
     * @private
822
     *
823
     * @return \eZ\Publish\Core\Repository\Helper\NameSchemaService
824
     */
825
    public function getNameSchemaService()
826
    {
827
        if ($this->nameSchemaService !== null) {
828
            return $this->nameSchemaService;
829
        }
830
831
        $this->nameSchemaService = new Helper\NameSchemaService(
832
            $this->persistenceHandler->contentTypeHandler(),
833
            $this->getContentTypeDomainMapper(),
834
            $this->getNameableFieldTypeRegistry(),
835
            $this->serviceSettings['nameSchema']
836
        );
837
838
        return $this->nameSchemaService;
839
    }
840
841
    /**
842
     * Get RelationProcessor.
843
     *
844
     *
845
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
846
     *
847
     * @return \eZ\Publish\Core\Repository\Helper\RelationProcessor
848
     */
849
    protected function getRelationProcessor()
850
    {
851
        if ($this->relationProcessor !== null) {
852
            return $this->relationProcessor;
853
        }
854
855
        $this->relationProcessor = new Helper\RelationProcessor($this->persistenceHandler);
856
857
        return $this->relationProcessor;
858
    }
859
860
    /**
861
     * Get Content Domain Mapper.
862
     *
863
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
864
     *
865
     * @return \eZ\Publish\Core\Repository\Helper\DomainMapper
866
     */
867
    protected function getDomainMapper()
868
    {
869
        if ($this->domainMapper !== null) {
870
            return $this->domainMapper;
871
        }
872
873
        $this->domainMapper = new Helper\DomainMapper(
874
            $this->persistenceHandler->contentHandler(),
875
            $this->persistenceHandler->locationHandler(),
876
            $this->persistenceHandler->contentTypeHandler(),
877
            $this->persistenceHandler->contentLanguageHandler(),
878
            $this->getFieldTypeRegistry()
879
        );
880
881
        return $this->domainMapper;
882
    }
883
884
    /**
885
     * Get ContentType Domain Mapper.
886
     *
887
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
888
     *
889
     * @return \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
890
     */
891
    protected function getContentTypeDomainMapper()
892
    {
893
        if ($this->contentTypeDomainMapper !== null) {
894
            return $this->contentTypeDomainMapper;
895
        }
896
897
        $this->contentTypeDomainMapper = new Helper\ContentTypeDomainMapper(
898
            $this->persistenceHandler->contentLanguageHandler(),
899
            $this->getFieldTypeRegistry()
900
        );
901
902
        return $this->contentTypeDomainMapper;
903
    }
904
905
    /**
906
     * Get PermissionsCriterionHandler.
907
     *
908
     *
909
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
910
     *
911
     * @return \eZ\Publish\Core\Repository\PermissionsCriterionHandler
912
     */
913
    protected function getPermissionsCriterionHandler()
914
    {
915
        if ($this->permissionsCriterionHandler === null) {
916
            $this->permissionsCriterionHandler = new PermissionsCriterionHandler(
917
                $this->getPermissionResolver(),
918
                $this->getLimitationService()
919
            );
920
        }
921
922
        return $this->permissionsCriterionHandler;
923
    }
924
925
    /**
926
     * Begin transaction.
927
     *
928
     * Begins an transaction, make sure you'll call commit or rollback when done,
929
     * otherwise work will be lost.
930
     */
931
    public function beginTransaction()
932
    {
933
        $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...
934
935
        ++$this->transactionDepth;
936
        $this->commitEventsQueue[++$this->transactionCount] = array();
937
    }
938
939
    /**
940
     * Commit transaction.
941
     *
942
     * Commit transaction, or throw exceptions if no transactions has been started.
943
     *
944
     * @throws RuntimeException If no transaction has been started
945
     */
946
    public function commit()
947
    {
948
        try {
949
            $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...
950
951
            --$this->transactionDepth;
952
953
            if ($this->transactionDepth === 0) {
954
                $queueCountDown = count($this->commitEventsQueue);
955
                foreach ($this->commitEventsQueue as $eventsQueue) {
956
                    --$queueCountDown;
957
                    if (empty($eventsQueue)) {
958
                        continue;
959
                    }
960
961
                    $eventCountDown = count($eventsQueue);
962
                    foreach ($eventsQueue as $event) {
963
                        --$eventCountDown;
964
                        // event expects a boolean param, if true it means it is last event (for commit use)
965
                        $event($queueCountDown === 0 && $eventCountDown === 0);
966
                    }
967
                }
968
969
                $this->commitEventsQueue = array();
970
            }
971
        } catch (Exception $e) {
972
            throw new RuntimeException($e->getMessage(), 0, $e);
973
        }
974
    }
975
976
    /**
977
     * Rollback transaction.
978
     *
979
     * Rollback transaction, or throw exceptions if no transactions has been started.
980
     *
981
     * @throws RuntimeException If no transaction has been started
982
     */
983
    public function rollback()
984
    {
985
        try {
986
            $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...
987
988
            --$this->transactionDepth;
989
            unset($this->commitEventsQueue[$this->transactionCount]);
990
        } catch (Exception $e) {
991
            throw new RuntimeException($e->getMessage(), 0, $e);
992
        }
993
    }
994
995
    /**
996
     * Enqueue an event to be triggered at commit or directly if no transaction has started.
997
     *
998
     * @param callable $event
999
     */
1000
    public function commitEvent($event)
1001
    {
1002
        if ($this->transactionDepth !== 0) {
1003
            $this->commitEventsQueue[$this->transactionCount][] = $event;
1004
        } else {
1005
            // event expects a boolean param, if true it means it is last event (for commit use)
1006
            $event(true);
1007
        }
1008
    }
1009
1010
    /**
1011
     * Only for internal use.
1012
     *
1013
     * Creates a \DateTime object for $timestamp in the current time zone
1014
     *
1015
     * @param int $timestamp
1016
     *
1017
     * @return \DateTime
1018
     */
1019 View Code Duplication
    public function createDateTime($timestamp = null)
1020
    {
1021
        $dateTime = new \DateTime();
1022
        if ($timestamp !== null) {
1023
            $dateTime->setTimestamp($timestamp);
1024
        }
1025
1026
        return $dateTime;
1027
    }
1028
1029
    public function setBackgroundIndexer(BackgroundIndexer $backgroundIndexer)
1030
    {
1031
        $this->backgroundIndexer = $backgroundIndexer;
1032
    }
1033
}
1034