|
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\Indexer; |
|
16
|
|
|
use eZ\Publish\SPI\Search\Indexer\ContentIndexer; |
|
17
|
|
|
use eZ\Publish\SPI\Search\Indexer\FullTextIndexer; |
|
18
|
|
|
use eZ\Publish\SPI\Search\Indexer\LocationIndexer; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* A Search Engine slot handling CreateUserSignal. |
|
22
|
|
|
*/ |
|
23
|
|
View Code Duplication |
class CreateUser extends Slot |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Receive the given $signal and react on it. |
|
27
|
|
|
* |
|
28
|
|
|
* @param \eZ\Publish\Core\SignalSlot\Signal $signal |
|
29
|
|
|
*/ |
|
30
|
|
|
public function receive(Signal $signal) |
|
31
|
|
|
{ |
|
32
|
|
|
if (!$signal instanceof Signal\UserService\CreateUserSignal) { |
|
33
|
|
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if (!$this->searchHandler instanceof Indexer) { |
|
37
|
|
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$userContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo( |
|
41
|
|
|
$signal->userId |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
if ($this->searchHandler instanceof ContentIndexer || $this->searchHandler instanceof FullTextIndexer) { |
|
45
|
|
|
$this->searchHandler->indexContent( |
|
46
|
|
|
$this->persistenceHandler->contentHandler()->load( |
|
47
|
|
|
$userContentInfo->id, |
|
48
|
|
|
$userContentInfo->currentVersionNo |
|
49
|
|
|
) |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if ($this->searchHandler instanceof LocationIndexer) { |
|
54
|
|
|
$locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent( |
|
55
|
|
|
$userContentInfo->id |
|
56
|
|
|
); |
|
57
|
|
|
foreach ($locations as $location) { |
|
58
|
|
|
$this->searchHandler->indexLocation($location); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
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.