Skip to content

Commit

Permalink
NGSTACK replace persistance handler with location handler, use indexS…
Browse files Browse the repository at this point in the history
…ingleForParent location method for trash and move subtree handlers and fix bugs
  • Loading branch information
Katarina Miočić committed Mar 28, 2024
1 parent c778868 commit 7e34ad4
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/Container/Compiler/AsynchronousIndexingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function process(ContainerBuilder $container): void
->setDecoratedService(CoreContentEventSubscriber::class)
->setArguments([
new Reference('netgen.ibexa_search_extra.asynchronous_indexing.messenger.bus'),
new Reference('ibexa.api.service.location'),
new Reference('Ibexa\Contracts\Core\Persistence\Content\Location\Handler'),
]);

$container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Ibexa\Contracts\Core\Repository\Events\Content\PublishVersionEvent;
use Ibexa\Contracts\Core\Repository\Events\Content\RevealContentEvent;
use Ibexa\Contracts\Core\Repository\Events\Content\UpdateContentMetadataEvent;
use Ibexa\Contracts\Core\Persistence\Handler as PersistenceHandler;
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as LocationHandler;
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\CopyContent;
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\DeleteContent;
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\DeleteTranslation;
Expand All @@ -29,7 +29,7 @@ class ContentEventSubscriber implements EventSubscriberInterface
private array $parentLocationIdsByContentId = [];
public function __construct(
private readonly MessageBusInterface $messageBus,
private readonly PersistenceHandler $persistenceHandler,
private readonly LocationHandler $locationHandler,

) {}

Expand Down Expand Up @@ -59,10 +59,10 @@ public function onCopyContent(CopyContentEvent $event): void

public function onBeforeDeleteContent(BeforeDeleteContentEvent $event): void
{
$contentLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($event->getContentInfo()->id);
$contentLocations = $this->locationHandler->loadLocationsByContent($event->getContentInfo()->id);
try {
foreach ($contentLocations as $contentLocation){
$this->parentLocationIdsByContentId[$event->getContentInfo()->id][] = $contentLocation->parentLocationId;
$this->parentLocationIdsByContentId[$event->getContentInfo()->id][] = $contentLocation->parentId;
}
} catch (Throwable) {
// does nothing
Expand All @@ -78,7 +78,7 @@ public function onDeleteContent(DeleteContentEvent $event): void
$this->parentLocationIdsByContentId[$event->getContentInfo()->id] ?? [],
),
);
$this->parentLocationIdsByContentId = [];
unset($this->parentLocationIdsByContentId[$event->getContentInfo()->id]);
}

public function onDeleteTranslation(DeleteTranslationEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public function indexSingle(Location $location): void
/**
* @param \Ibexa\Contracts\Core\Persistence\Content\Location $location
*/
public function indexSingleForDeleteContent(Location $location): void
public function indexSingleForParentLocation(Location $location): void
{
$ancestor = $this->ancestorResolver->resolveAncestorForDeleteContent($location);

$ancestor = $this->ancestorResolver->resolveAncestorForParentLocation($location);
if ($ancestor === null) {
return;
}
Expand Down Expand Up @@ -71,12 +70,12 @@ public function indexMultiple(array $locations): void
/***
* @param \Ibexa\Contracts\Core\Persistence\Content\Location[] $locations
*/
public function indexMultipleForDeleteContent(array $locations): void
public function indexMultipleForParentLocation(array $locations): void
{
$this->indexMultiple($locations);

foreach ($locations as $location) {
$this->indexSingleForDeleteContent($location);
$this->indexSingleForParentLocation($location);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public function __invoke(DeleteContent $message): void
);
}
}
$this->ancestorIndexer->indexMultipleForDeleteContent($locations);
$this->ancestorIndexer->indexMultipleForParentLocation($locations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __invoke(MoveSubtree $message): void
$message->oldParentLocationId,
);

$this->ancestorIndexer->indexSingle($location);
$this->ancestorIndexer->indexSingleForParentLocation($location);
} catch (NotFoundException) {
$this->logger->info(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function __invoke(Trash $message): void
return;
}

$this->ancestorIndexer->indexSingle($location);
$this->ancestorIndexer->indexSingleForParentLocation($location);
}
}
8 changes: 3 additions & 5 deletions lib/Core/Search/Solr/FieldMapper/ParentChildFieldMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Ibexa\Contracts\Core\Persistence\Content\ContentInfo;
use Ibexa\Contracts\Core\Persistence\Content\Handler as ContentHandler;
use Ibexa\Contracts\Core\Persistence\Content\Type\Handler as ContentTypeHandler;
use Ibexa\Contracts\Core\Persistence\Handler as PersistenceHandler;
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as LocationHandler;
use Ibexa\Contracts\Core\Repository\Exceptions\BadStateException;
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidCriterionArgumentException;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
Expand All @@ -19,10 +19,8 @@
use Ibexa\Contracts\Core\Persistence\Filter\Content\Handler;
use Ibexa\Contracts\Solr\FieldMapper\ContentTranslationFieldMapper;

use Ibexa\Core\Repository\Values\Content\Content;
use function array_key_exists;
use function array_keys;
use function array_map;
use function array_merge;
use function count;

Expand All @@ -42,7 +40,7 @@ public function __construct(
private readonly ContentTypeHandler $contentTypeHandler,
private readonly ContentHandler $contentHandler,
private readonly Handler $contentFilteringHandler,
private readonly PersistenceHandler $persistenceHandler,
private readonly LocationHandler $locationHandler,
private readonly int $childrenLimit = 99,
) {}

Expand Down Expand Up @@ -165,7 +163,7 @@ private function loadChildrenContentInfoList(
$items = [];

foreach ($contentItemList as $contentItem) {
$contentLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentItem->contentInfo->id);
$contentLocations = $this->locationHandler->loadLocationsByContent($contentItem->contentInfo->id);

foreach ($contentLocations as $contentLocation) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function resolveAncestor(Location $location): ?Location
*
* @param Location $location
*/
public function resolveAncestorForDeleteContent(Location $location): ?Location
public function resolveAncestorForParentLocation(Location $location): ?Location
{
$contentTypeIdentifier = $this->getContentTypeIdentifier($location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- '@Ibexa\Contracts\Core\Persistence\Content\Type\Handler'
- '@Ibexa\Contracts\Core\Persistence\Content\Handler'
- '@Ibexa\Contracts\Core\Persistence\Filter\Content\Handler'
- '@Ibexa\Contracts\Core\Persistence\Handler'
- '@Ibexa\Contracts\Core\Persistence\Content\Location\Handler'
tags:
- { name: ibexa.search.solr.field.mapper.content.translation }

Expand Down

0 comments on commit 7e34ad4

Please sign in to comment.