-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Katarina Miočić
committed
Mar 22, 2024
1 parent
9af5bf6
commit 047fd32
Showing
36 changed files
with
1,691 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...ore/Search/Common/Messenger/MessageHandler/Search/ParentChildIndexing/AncestorIndexer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing; | ||
|
||
use Netgen\IbexaSearchExtra\Core\Search\Solr\ParentChildReindexAncestorResolver; | ||
use Ibexa\Contracts\Core\Persistence\Content\Handler as ContentHandler; | ||
use Ibexa\Contracts\Core\Persistence\Content\Location; | ||
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; | ||
use Ibexa\Contracts\Core\Search\VersatileHandler; | ||
|
||
final class AncestorIndexer | ||
{ | ||
public function __construct( | ||
private readonly VersatileHandler $searchHandler, | ||
private readonly ContentHandler $contentHandler, | ||
private readonly ParentChildReindexAncestorResolver $ancestorResolver, | ||
) {} | ||
|
||
public function indexSingle(Location $location): void | ||
{ | ||
$ancestor = $this->ancestorResolver->resolveAncestor($location); | ||
|
||
|
||
if ($ancestor === null) { | ||
return; | ||
} | ||
|
||
try { | ||
$content = $this->contentHandler->load($ancestor->contentId); | ||
} catch (NotFoundException) { | ||
return; | ||
} | ||
|
||
$this->searchHandler->indexContent($content); | ||
$this->searchHandler->indexLocation($ancestor); | ||
} | ||
|
||
/** | ||
* @param \Ibexa\Contracts\Core\Persistence\Content\Location $location | ||
*/ | ||
public function indexSingleForDeleteContent(Location $location): void | ||
{ | ||
$ancestor = $this->ancestorResolver->resolveAncestorForDeleteContent($location); | ||
|
||
if ($ancestor === null) { | ||
return; | ||
} | ||
|
||
try { | ||
$content = $this->contentHandler->load($ancestor->contentId); | ||
} catch (NotFoundException) { | ||
return; | ||
} | ||
|
||
$this->searchHandler->indexContent($content); | ||
$this->searchHandler->indexLocation($ancestor); | ||
} | ||
|
||
/** | ||
* @param \Ibexa\Contracts\Core\Persistence\Content\Location[] $locations | ||
*/ | ||
public function indexMultiple(array $locations): void | ||
{ | ||
foreach ($locations as $location) { | ||
$this->indexSingle($location); | ||
} | ||
} | ||
|
||
/*** | ||
* @param \Ibexa\Contracts\Core\Persistence\Content\Location[] $locations | ||
*/ | ||
public function indexMultipleForDeleteContent(array $locations): void | ||
{ | ||
$this->indexMultiple($locations); | ||
|
||
foreach ($locations as $location) { | ||
$this->indexSingleForDeleteContent($location); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...Common/Messenger/MessageHandler/Search/ParentChildIndexing/Content/CopyContentHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\Content; | ||
|
||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\AncestorIndexer; | ||
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as LocationHandler; | ||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\CopyContent; | ||
|
||
final class CopyContentHandler | ||
{ | ||
public function __construct( | ||
private readonly LocationHandler $locationHandler, | ||
private readonly AncestorIndexer $ancestorIndexer, | ||
) {} | ||
|
||
public function __invoke(CopyContent $message): void | ||
{ | ||
$this->ancestorIndexer->indexMultiple( | ||
$this->locationHandler->loadLocationsByContent( | ||
$message->contentId, | ||
), | ||
); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...mmon/Messenger/MessageHandler/Search/ParentChildIndexing/Content/DeleteContentHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\Content; | ||
|
||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\AncestorIndexer; | ||
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as LocationHandler; | ||
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; | ||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\DeleteContent; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\NullLogger; | ||
|
||
use function sprintf; | ||
|
||
final class DeleteContentHandler | ||
{ | ||
public function __construct( | ||
private readonly LocationHandler $locationHandler, | ||
private readonly AncestorIndexer $ancestorIndexer, | ||
private readonly LoggerInterface $logger = new NullLogger(), | ||
) {} | ||
|
||
public function __invoke(DeleteContent $message): void | ||
{ | ||
if ($message->parentLocationIds === []) { | ||
$this->logger->info( | ||
sprintf( | ||
'%s: Could not find main Location parent Location ID for deleted Content #%d, aborting', | ||
$this::class, | ||
$message->contentId, | ||
), | ||
); | ||
|
||
return; | ||
} | ||
$locations = []; | ||
foreach ($message->parentLocationIds as $locationId) { | ||
try { | ||
$locations[] = $this->locationHandler->load($locationId); | ||
} catch (NotFoundException) { | ||
$this->logger->info( | ||
sprintf( | ||
'%s: Location #%d is gone, aborting', | ||
$this::class, | ||
$locationId, | ||
), | ||
); | ||
} | ||
} | ||
$this->ancestorIndexer->indexMultipleForDeleteContent($locations); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
.../Messenger/MessageHandler/Search/ParentChildIndexing/Content/DeleteTranslationHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\Content; | ||
|
||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\AncestorIndexer; | ||
use Ibexa\Contracts\Core\Persistence\Content\ContentInfo; | ||
use Ibexa\Contracts\Core\Persistence\Content\Handler as ContentHandler; | ||
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as LocationHandler; | ||
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; | ||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\DeleteTranslation; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\NullLogger; | ||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
|
||
use function sprintf; | ||
|
||
final class DeleteTranslationHandler | ||
{ | ||
public function __construct( | ||
private readonly ContentHandler $contentHandler, | ||
private readonly LocationHandler $locationHandler, | ||
private readonly AncestorIndexer $ancestorIndexer, | ||
private readonly LoggerInterface $logger = new NullLogger(), | ||
) {} | ||
|
||
public function __invoke(DeleteTranslation $message): void | ||
{ | ||
try { | ||
$contentInfo = $this->contentHandler->loadContentInfo( | ||
$message->contentId, | ||
); | ||
} catch (NotFoundException) { | ||
$this->logger->info( | ||
sprintf( | ||
'%s: Content #%d is gone, aborting', | ||
$this::class, | ||
$message->contentId, | ||
), | ||
); | ||
|
||
return; | ||
} | ||
|
||
if ($contentInfo->status !== ContentInfo::STATUS_PUBLISHED) { | ||
return; | ||
} | ||
|
||
$this->ancestorIndexer->indexMultiple( | ||
$this->locationHandler->loadLocationsByContent( | ||
$message->contentId, | ||
), | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...Common/Messenger/MessageHandler/Search/ParentChildIndexing/Content/HideContentHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\Content; | ||
|
||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\AncestorIndexer; | ||
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as LocationHandler; | ||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\HideContent; | ||
|
||
final class HideContentHandler | ||
{ | ||
public function __construct( | ||
private readonly LocationHandler $locationHandler, | ||
private readonly AncestorIndexer $ancestorIndexer, | ||
) {} | ||
|
||
public function __invoke(HideContent $message): void | ||
{ | ||
$this->ancestorIndexer->indexMultiple( | ||
$this->locationHandler->loadLocationsByContent( | ||
$message->contentId, | ||
), | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...mon/Messenger/MessageHandler/Search/ParentChildIndexing/Content/PublishVersionHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\Content; | ||
|
||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\AncestorIndexer; | ||
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as LocationHandler; | ||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\PublishVersion; | ||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
|
||
final class PublishVersionHandler | ||
{ | ||
public function __construct( | ||
private readonly LocationHandler $locationHandler, | ||
private readonly AncestorIndexer $ancestorIndexer, | ||
) {} | ||
|
||
public function __invoke(PublishVersion $message): void | ||
{ | ||
$this->ancestorIndexer->indexMultiple( | ||
$this->locationHandler->loadLocationsByContent( | ||
$message->contentId, | ||
), | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...mmon/Messenger/MessageHandler/Search/ParentChildIndexing/Content/RevealContentHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\Content; | ||
|
||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\MessageHandler\Search\ParentChildIndexing\AncestorIndexer; | ||
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as LocationHandler; | ||
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\RevealContent; | ||
|
||
final class RevealContentHandler | ||
{ | ||
public function __construct( | ||
private readonly LocationHandler $locationHandler, | ||
private readonly AncestorIndexer $ancestorIndexer, | ||
) {} | ||
|
||
public function __invoke(RevealContent $message): void | ||
{ | ||
$this->ancestorIndexer->indexMultiple( | ||
$this->locationHandler->loadLocationsByContent( | ||
$message->contentId, | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.