|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
|
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\Search\Common\Slot; |
|
12
|
|
|
|
|
13
|
|
|
use eZ\Publish\Core\SignalSlot\Signal; |
|
14
|
|
|
use eZ\Publish\Core\Search\Common\Slot; |
|
15
|
|
|
use eZ\Publish\SPI\Search\Indexing; |
|
16
|
|
|
use eZ\Publish\SPI\Search\Indexing\FullTextIndexing; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* A Search Engine slot handling CreateUserGroupSignal. |
|
20
|
|
|
*/ |
|
21
|
|
View Code Duplication |
class CreateUserGroup extends Slot |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Receive the given $signal and react on it. |
|
25
|
|
|
* |
|
26
|
|
|
* @param \eZ\Publish\Core\SignalSlot\Signal $signal |
|
27
|
|
|
*/ |
|
28
|
|
|
public function receive(Signal $signal) |
|
29
|
|
|
{ |
|
30
|
|
|
if (!$signal instanceof Signal\UserService\CreateUserGroupSignal || !$this->canIndex()) { |
|
31
|
|
|
return; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$userGroupContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo( |
|
35
|
|
|
$signal->userGroupId |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
if ($this->canIndexContent()) { |
|
39
|
|
|
$this->searchHandler->indexContent( |
|
40
|
|
|
$this->persistenceHandler->contentHandler()->load( |
|
41
|
|
|
$userGroupContentInfo->id, |
|
42
|
|
|
$userGroupContentInfo->currentVersionNo |
|
43
|
|
|
) |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if ($this->canIndexLocation()) { |
|
48
|
|
|
$locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent( |
|
49
|
|
|
$userGroupContentInfo->id |
|
50
|
|
|
); |
|
51
|
|
|
foreach ($locations as $location) { |
|
52
|
|
|
$this->searchHandler->indexLocation($location); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected function canIndexContent() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->searchHandler instanceof ContentIndexing || $this->searchHandler instanceof FullTextIndexing; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.