Completed
Push — tolerant_search_service ( a664cf...317d89 )
by André
11:53
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
        BackgroundIndexer $backgroundIndexer,
263
        array $serviceSettings = array(),
264
        APIUserReference $user = null
265
    ) {
266
        $this->persistenceHandler = $persistenceHandler;
267
        $this->searchHandler = $searchHandler;
268
        $this->backgroundIndexer = $backgroundIndexer;
269
        $this->serviceSettings = $serviceSettings + array(
270
            'content' => array(),
271
            'contentType' => array(),
272
            'location' => array(),
273
            'section' => array(),
274
            'role' => array(),
275
            'user' => array(
276
                'anonymousUserID' => 10,
277
            ),
278
            'language' => array(),
279
            'trash' => array(),
280
            'io' => array(),
281
            'objectState' => array(),
282
            'search' => array(),
283
            'fieldType' => array(),
284
            'nameableFieldTypes' => array(),
285
            'urlAlias' => array(),
286
            'urlWildcard' => array(),
287
            'nameSchema' => array(),
288
            'languages' => array(),
289
        );
290
291
        if (!empty($this->serviceSettings['languages'])) {
292
            $this->serviceSettings['language']['languages'] = $this->serviceSettings['languages'];
293
        }
294
295
        if ($user instanceof User) {
296
            $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...
297
            $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...
298
        } elseif ($user instanceof APIUserReference) {
299
            $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...
300
        } else {
301
            $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...
302
        }
303
    }
304
305
    /**
306
     * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
307
     *
308
     * Get current user.
309
     *
310
     * Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}
311
     *
312
     * @return \eZ\Publish\API\Repository\Values\User\User
313
     */
314
    public function getCurrentUser()
315
    {
316
        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...
317
            $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...
318
                $this->getPermissionResolver()->getCurrentUserReference()->getUserId()
319
            );
320
        }
321
322
        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...
323
    }
324
325
    /**
326
     * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
327
     *
328
     * Get current user reference.
329
     *
330
     * @since 5.4.5
331
     * @return \eZ\Publish\API\Repository\Values\User\UserReference
332
     */
333
    public function getCurrentUserReference()
334
    {
335
        return $this->getPermissionResolver()->getCurrentUserReference();
336
    }
337
338
    /**
339
     * @deprecated since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead.
340
     *
341
     * Sets the current user to the given $user.
342
     *
343
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
344
     *
345
     * @throws InvalidArgumentValue If UserReference does not contain a id
346
     */
347
    public function setCurrentUser(APIUserReference $user)
348
    {
349
        $id = $user->getUserId();
350
        if (!$id) {
351
            throw new InvalidArgumentValue('$user->getUserId()', $id);
352
        }
353
354
        if ($user instanceof User) {
355
            $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...
356
            $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...
357
        } else {
358
            $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...
359
            $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...
360
        }
361
362
        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...
363
    }
364
365
    /**
366
     * Allows API execution to be performed with full access sand-boxed.
367
     *
368
     * The closure sandbox will do a catch all on exceptions and rethrow after
369
     * re-setting the sudo flag.
370
     *
371
     * Example use:
372
     *     $location = $repository->sudo(
373
     *         function ( Repository $repo ) use ( $locationId )
374
     *         {
375
     *             return $repo->getLocationService()->loadLocation( $locationId )
376
     *         }
377
     *     );
378
     *
379
     *
380
     * @param \Closure $callback
381
     * @param \eZ\Publish\API\Repository\Repository $outerRepository
382
     *
383
     * @throws \RuntimeException Thrown on recursive sudo() use.
384
     * @throws \Exception Re throws exceptions thrown inside $callback
385
     *
386
     * @return mixed
387
     */
388
    public function sudo(\Closure $callback, RepositoryInterface $outerRepository = null)
389
    {
390
        return $this->getPermissionResolver()->sudo(
391
            $callback,
392
            $outerRepository !== null ? $outerRepository : $this
393
        );
394
    }
395
396
    /**
397
     * @deprecated since 6.6, to be removed. Use PermissionResolver::hasAccess() instead.
398
     *
399
     * Check if user has access to a given module / function.
400
     *
401
     * Low level function, use canUser instead if you have objects to check against.
402
     *
403
     * @param string $module
404
     * @param string $function
405
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
406
     *
407
     * @return bool|array Bool if user has full or no access, array if limitations if not
408
     */
409
    public function hasAccess($module, $function, APIUserReference $user = null)
410
    {
411
        return $this->getPermissionResolver()->hasAccess($module, $function, $user);
412
    }
413
414
    /**
415
     * @deprecated since 6.6, to be removed. Use PermissionResolver::canUser() instead.
416
     *
417
     * Check if user has access to a given action on a given value object.
418
     *
419
     * Indicates if the current user is allowed to perform an action given by the function on the given
420
     * objects.
421
     *
422
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If any of the arguments are invalid
423
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If value of the LimitationValue is unsupported
424
     *
425
     * @param string $module The module, aka controller identifier to check permissions on
426
     * @param string $function The function, aka the controller action to check permissions on
427
     * @param \eZ\Publish\API\Repository\Values\ValueObject $object The object to check if the user has access to
428
     * @param mixed $targets The location, parent or "assignment" value object, or an array of the same
429
     *
430
     * @return bool
431
     */
432
    public function canUser($module, $function, ValueObject $object, $targets = null)
433
    {
434
        if ($targets instanceof ValueObject) {
435
            $targets = array($targets);
436
        } elseif ($targets === null) {
437
            $targets = [];
438
        } elseif (!is_array($targets)) {
439
            throw new InvalidArgumentType(
440
                '$targets',
441
                'null|\\eZ\\Publish\\API\\Repository\\Values\\ValueObject|\\eZ\\Publish\\API\\Repository\\Values\\ValueObject[]',
442
                $targets
443
            );
444
        }
445
446
        return $this->getPermissionResolver()->canUser($module, $function, $object, $targets);
447
    }
448
449
    /**
450
     * Get Content Service.
451
     *
452
     * Get service object to perform operations on Content objects and it's aggregate members.
453
     *
454
     * @return \eZ\Publish\API\Repository\ContentService
455
     */
456 View Code Duplication
    public function getContentService()
457
    {
458
        if ($this->contentService !== null) {
459
            return $this->contentService;
460
        }
461
462
        $this->contentService = new ContentService(
463
            $this,
464
            $this->persistenceHandler,
465
            $this->getDomainMapper(),
466
            $this->getRelationProcessor(),
467
            $this->getNameSchemaService(),
468
            $this->getFieldTypeRegistry(),
469
            $this->serviceSettings['content']
470
        );
471
472
        return $this->contentService;
473
    }
474
475
    /**
476
     * Get Content Language Service.
477
     *
478
     * Get service object to perform operations on Content language objects
479
     *
480
     * @return \eZ\Publish\API\Repository\LanguageService
481
     */
482
    public function getContentLanguageService()
483
    {
484
        if ($this->languageService !== null) {
485
            return $this->languageService;
486
        }
487
488
        $this->languageService = new LanguageService(
489
            $this,
490
            $this->persistenceHandler->contentLanguageHandler(),
491
            $this->serviceSettings['language']
492
        );
493
494
        return $this->languageService;
495
    }
496
497
    /**
498
     * Get Content Type Service.
499
     *
500
     * Get service object to perform operations on Content Type objects and it's aggregate members.
501
     * ( Group, Field & FieldCategory )
502
     *
503
     * @return \eZ\Publish\API\Repository\ContentTypeService
504
     */
505 View Code Duplication
    public function getContentTypeService()
506
    {
507
        if ($this->contentTypeService !== null) {
508
            return $this->contentTypeService;
509
        }
510
511
        $this->contentTypeService = new ContentTypeService(
512
            $this,
513
            $this->persistenceHandler->contentTypeHandler(),
514
            $this->getDomainMapper(),
515
            $this->getContentTypeDomainMapper(),
516
            $this->getFieldTypeRegistry(),
517
            $this->serviceSettings['contentType']
518
        );
519
520
        return $this->contentTypeService;
521
    }
522
523
    /**
524
     * Get Content Location Service.
525
     *
526
     * Get service object to perform operations on Location objects and subtrees
527
     *
528
     * @return \eZ\Publish\API\Repository\LocationService
529
     */
530
    public function getLocationService()
531
    {
532
        if ($this->locationService !== null) {
533
            return $this->locationService;
534
        }
535
536
        $this->locationService = new LocationService(
537
            $this,
538
            $this->persistenceHandler,
539
            $this->getDomainMapper(),
540
            $this->getNameSchemaService(),
541
            $this->getPermissionsCriterionHandler(),
542
            $this->serviceSettings['location']
543
        );
544
545
        return $this->locationService;
546
    }
547
548
    /**
549
     * Get Content Trash service.
550
     *
551
     * Trash service allows to perform operations related to location trash
552
     * (trash/untrash, load/list from trash...)
553
     *
554
     * @return \eZ\Publish\API\Repository\TrashService
555
     */
556
    public function getTrashService()
557
    {
558
        if ($this->trashService !== null) {
559
            return $this->trashService;
560
        }
561
562
        $this->trashService = new TrashService(
563
            $this,
564
            $this->persistenceHandler,
565
            $this->getNameSchemaService(),
566
            $this->serviceSettings['trash']
567
        );
568
569
        return $this->trashService;
570
    }
571
572
    /**
573
     * Get Content Section Service.
574
     *
575
     * Get Section service that lets you manipulate section objects
576
     *
577
     * @return \eZ\Publish\API\Repository\SectionService
578
     */
579
    public function getSectionService()
580
    {
581
        if ($this->sectionService !== null) {
582
            return $this->sectionService;
583
        }
584
585
        $this->sectionService = new SectionService(
586
            $this,
587
            $this->persistenceHandler->sectionHandler(),
588
            $this->serviceSettings['section']
589
        );
590
591
        return $this->sectionService;
592
    }
593
594
    /**
595
     * Get User Service.
596
     *
597
     * Get service object to perform operations on Users and UserGroup
598
     *
599
     * @return \eZ\Publish\API\Repository\UserService
600
     */
601
    public function getUserService()
602
    {
603
        if ($this->userService !== null) {
604
            return $this->userService;
605
        }
606
607
        $this->userService = new UserService(
608
            $this,
609
            $this->persistenceHandler->userHandler(),
610
            $this->serviceSettings['user']
611
        );
612
613
        return $this->userService;
614
    }
615
616
    /**
617
     * Get URLAliasService.
618
     *
619
     * @return \eZ\Publish\API\Repository\URLAliasService
620
     */
621
    public function getURLAliasService()
622
    {
623
        if ($this->urlAliasService !== null) {
624
            return $this->urlAliasService;
625
        }
626
627
        $this->urlAliasService = new URLAliasService(
628
            $this,
629
            $this->persistenceHandler->urlAliasHandler(),
630
            $this->serviceSettings['urlAlias']
631
        );
632
633
        return $this->urlAliasService;
634
    }
635
636
    /**
637
     * Get URLWildcardService.
638
     *
639
     * @return \eZ\Publish\API\Repository\URLWildcardService
640
     */
641
    public function getURLWildcardService()
642
    {
643
        if ($this->urlWildcardService !== null) {
644
            return $this->urlWildcardService;
645
        }
646
647
        $this->urlWildcardService = new URLWildcardService(
648
            $this,
649
            $this->persistenceHandler->urlWildcardHandler(),
650
            $this->serviceSettings['urlWildcard']
651
        );
652
653
        return $this->urlWildcardService;
654
    }
655
656
    /**
657
     * Get ObjectStateService.
658
     *
659
     * @return \eZ\Publish\API\Repository\ObjectStateService
660
     */
661
    public function getObjectStateService()
662
    {
663
        if ($this->objectStateService !== null) {
664
            return $this->objectStateService;
665
        }
666
667
        $this->objectStateService = new ObjectStateService(
668
            $this,
669
            $this->persistenceHandler->objectStateHandler(),
670
            $this->serviceSettings['objectState']
671
        );
672
673
        return $this->objectStateService;
674
    }
675
676
    /**
677
     * Get RoleService.
678
     *
679
     * @return \eZ\Publish\API\Repository\RoleService
680
     */
681
    public function getRoleService()
682
    {
683
        if ($this->roleService !== null) {
684
            return $this->roleService;
685
        }
686
687
        $this->roleService = new RoleService(
688
            $this,
689
            $this->persistenceHandler->userHandler(),
690
            $this->getLimitationService(),
691
            $this->getRoleDomainMapper(),
692
            $this->serviceSettings['role']
693
        );
694
695
        return $this->roleService;
696
    }
697
698
    /**
699
     * Get LimitationService.
700
     *
701
     * @return \eZ\Publish\Core\Repository\Helper\LimitationService
702
     */
703
    protected function getLimitationService()
704
    {
705
        if ($this->limitationService !== null) {
706
            return $this->limitationService;
707
        }
708
709
        $this->limitationService = new Helper\LimitationService($this->serviceSettings['role']);
710
711
        return $this->limitationService;
712
    }
713
714
    /**
715
     * Get RoleDomainMapper.
716
     *
717
     * @return \eZ\Publish\Core\Repository\Helper\RoleDomainMapper
718
     */
719
    protected function getRoleDomainMapper()
720
    {
721
        if ($this->roleDomainMapper !== null) {
722
            return $this->roleDomainMapper;
723
        }
724
725
        $this->roleDomainMapper = new Helper\RoleDomainMapper($this->getLimitationService());
726
727
        return $this->roleDomainMapper;
728
    }
729
730
    /**
731
     * Get SearchService.
732
     *
733
     * @return \eZ\Publish\API\Repository\SearchService
734
     */
735
    public function getSearchService()
736
    {
737
        if ($this->searchService !== null) {
738
            return $this->searchService;
739
        }
740
741
        $this->searchService = new SearchService(
742
            $this,
743
            $this->searchHandler,
744
            $this->getDomainMapper(),
745
            $this->getPermissionsCriterionHandler(),
746
            $this->backgroundIndexer,
0 ignored issues
show
Bug introduced by
It seems like $this->backgroundIndexer can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
747
            $this->serviceSettings['search']
748
        );
749
750
        return $this->searchService;
751
    }
752
753
    /**
754
     * Get FieldTypeService.
755
     *
756
     * @return \eZ\Publish\API\Repository\FieldTypeService
757
     */
758
    public function getFieldTypeService()
759
    {
760
        if ($this->fieldTypeService !== null) {
761
            return $this->fieldTypeService;
762
        }
763
764
        $this->fieldTypeService = new FieldTypeService($this->getFieldTypeRegistry());
765
766
        return $this->fieldTypeService;
767
    }
768
769
    /**
770
     * Get PermissionResolver.
771
     *
772
     * @return \eZ\Publish\API\Repository\PermissionResolver
773
     */
774
    public function getPermissionResolver()
775
    {
776
        if ($this->permissionResolver === null) {
777
            $this->permissionResolver = new Permission\PermissionResolver(
778
                $this->getRoleDomainMapper(),
779
                $this->getLimitationService(),
780
                $this->persistenceHandler->userHandler(),
781
                $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...
782
            );
783
        }
784
785
        return $this->permissionResolver;
786
    }
787
788
    /**
789
     * @return Helper\FieldTypeRegistry
790
     */
791
    protected function getFieldTypeRegistry()
792
    {
793
        if ($this->fieldTypeRegistry !== null) {
794
            return $this->fieldTypeRegistry;
795
        }
796
797
        $this->fieldTypeRegistry = new Helper\FieldTypeRegistry($this->serviceSettings['fieldType']);
798
799
        return $this->fieldTypeRegistry;
800
    }
801
802
    /**
803
     * @return Helper\NameableFieldTypeRegistry
804
     */
805
    protected function getNameableFieldTypeRegistry()
806
    {
807
        if ($this->nameableFieldTypeRegistry !== null) {
808
            return $this->nameableFieldTypeRegistry;
809
        }
810
811
        $this->nameableFieldTypeRegistry = new Helper\NameableFieldTypeRegistry($this->serviceSettings['nameableFieldTypes']);
812
813
        return $this->nameableFieldTypeRegistry;
814
    }
815
816
    /**
817
     * Get NameSchemaResolverService.
818
     *
819
     *
820
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
821
     *
822
     * @internal
823
     * @private
824
     *
825
     * @return \eZ\Publish\Core\Repository\Helper\NameSchemaService
826
     */
827
    public function getNameSchemaService()
828
    {
829
        if ($this->nameSchemaService !== null) {
830
            return $this->nameSchemaService;
831
        }
832
833
        $this->nameSchemaService = new Helper\NameSchemaService(
834
            $this->persistenceHandler->contentTypeHandler(),
835
            $this->getContentTypeDomainMapper(),
836
            $this->getNameableFieldTypeRegistry(),
837
            $this->serviceSettings['nameSchema']
838
        );
839
840
        return $this->nameSchemaService;
841
    }
842
843
    /**
844
     * Get RelationProcessor.
845
     *
846
     *
847
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
848
     *
849
     * @return \eZ\Publish\Core\Repository\Helper\RelationProcessor
850
     */
851
    protected function getRelationProcessor()
852
    {
853
        if ($this->relationProcessor !== null) {
854
            return $this->relationProcessor;
855
        }
856
857
        $this->relationProcessor = new Helper\RelationProcessor($this->persistenceHandler);
858
859
        return $this->relationProcessor;
860
    }
861
862
    /**
863
     * Get Content Domain Mapper.
864
     *
865
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
866
     *
867
     * @return \eZ\Publish\Core\Repository\Helper\DomainMapper
868
     */
869
    protected function getDomainMapper()
870
    {
871
        if ($this->domainMapper !== null) {
872
            return $this->domainMapper;
873
        }
874
875
        $this->domainMapper = new Helper\DomainMapper(
876
            $this->persistenceHandler->contentHandler(),
877
            $this->persistenceHandler->locationHandler(),
878
            $this->persistenceHandler->contentTypeHandler(),
879
            $this->persistenceHandler->contentLanguageHandler(),
880
            $this->getFieldTypeRegistry()
881
        );
882
883
        return $this->domainMapper;
884
    }
885
886
    /**
887
     * Get ContentType Domain Mapper.
888
     *
889
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
890
     *
891
     * @return \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
892
     */
893
    protected function getContentTypeDomainMapper()
894
    {
895
        if ($this->contentTypeDomainMapper !== null) {
896
            return $this->contentTypeDomainMapper;
897
        }
898
899
        $this->contentTypeDomainMapper = new Helper\ContentTypeDomainMapper(
900
            $this->persistenceHandler->contentLanguageHandler(),
901
            $this->getFieldTypeRegistry()
902
        );
903
904
        return $this->contentTypeDomainMapper;
905
    }
906
907
    /**
908
     * Get PermissionsCriterionHandler.
909
     *
910
     *
911
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
912
     *
913
     * @return \eZ\Publish\Core\Repository\PermissionsCriterionHandler
914
     */
915
    protected function getPermissionsCriterionHandler()
916
    {
917
        if ($this->permissionsCriterionHandler === null) {
918
            $this->permissionsCriterionHandler = new PermissionsCriterionHandler(
919
                $this->getPermissionResolver(),
920
                $this->getLimitationService()
921
            );
922
        }
923
924
        return $this->permissionsCriterionHandler;
925
    }
926
927
    /**
928
     * Begin transaction.
929
     *
930
     * Begins an transaction, make sure you'll call commit or rollback when done,
931
     * otherwise work will be lost.
932
     */
933
    public function beginTransaction()
934
    {
935
        $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...
936
937
        ++$this->transactionDepth;
938
        $this->commitEventsQueue[++$this->transactionCount] = array();
939
    }
940
941
    /**
942
     * Commit transaction.
943
     *
944
     * Commit transaction, or throw exceptions if no transactions has been started.
945
     *
946
     * @throws RuntimeException If no transaction has been started
947
     */
948
    public function commit()
949
    {
950
        try {
951
            $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...
952
953
            --$this->transactionDepth;
954
955
            if ($this->transactionDepth === 0) {
956
                $queueCountDown = count($this->commitEventsQueue);
957
                foreach ($this->commitEventsQueue as $eventsQueue) {
958
                    --$queueCountDown;
959
                    if (empty($eventsQueue)) {
960
                        continue;
961
                    }
962
963
                    $eventCountDown = count($eventsQueue);
964
                    foreach ($eventsQueue as $event) {
965
                        --$eventCountDown;
966
                        // event expects a boolean param, if true it means it is last event (for commit use)
967
                        $event($queueCountDown === 0 && $eventCountDown === 0);
968
                    }
969
                }
970
971
                $this->commitEventsQueue = array();
972
            }
973
        } catch (Exception $e) {
974
            throw new RuntimeException($e->getMessage(), 0, $e);
975
        }
976
    }
977
978
    /**
979
     * Rollback transaction.
980
     *
981
     * Rollback transaction, or throw exceptions if no transactions has been started.
982
     *
983
     * @throws RuntimeException If no transaction has been started
984
     */
985
    public function rollback()
986
    {
987
        try {
988
            $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...
989
990
            --$this->transactionDepth;
991
            unset($this->commitEventsQueue[$this->transactionCount]);
992
        } catch (Exception $e) {
993
            throw new RuntimeException($e->getMessage(), 0, $e);
994
        }
995
    }
996
997
    /**
998
     * Enqueue an event to be triggered at commit or directly if no transaction has started.
999
     *
1000
     * @param callable $event
1001
     */
1002
    public function commitEvent($event)
1003
    {
1004
        if ($this->transactionDepth !== 0) {
1005
            $this->commitEventsQueue[$this->transactionCount][] = $event;
1006
        } else {
1007
            // event expects a boolean param, if true it means it is last event (for commit use)
1008
            $event(true);
1009
        }
1010
    }
1011
1012
    /**
1013
     * Only for internal use.
1014
     *
1015
     * Creates a \DateTime object for $timestamp in the current time zone
1016
     *
1017
     * @param int $timestamp
1018
     *
1019
     * @return \DateTime
1020
     */
1021 View Code Duplication
    public function createDateTime($timestamp = null)
1022
    {
1023
        $dateTime = new \DateTime();
1024
        if ($timestamp !== null) {
1025
            $dateTime->setTimestamp($timestamp);
1026
        }
1027
1028
        return $dateTime;
1029
    }
1030
}
1031