Skip to content

Commit

Permalink
NGSTACK-843 use cs fixer on edited files
Browse files Browse the repository at this point in the history
  • Loading branch information
Katarina Miočić committed May 10, 2024
1 parent f7258c9 commit efd39bc
Show file tree
Hide file tree
Showing 26 changed files with 204 additions and 171 deletions.
22 changes: 13 additions & 9 deletions bundle/Command/IndexPageContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

use Ibexa\Contracts\Core\Persistence\Handler as PersistenceHandler;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentList;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
use Ibexa\Contracts\Core\Search\Handler as SearchHandler;
Expand All @@ -16,9 +20,8 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentList;

use Symfony\Component\Console\Style\SymfonyStyle;

use function count;
use function explode;

Expand Down Expand Up @@ -57,14 +60,14 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
* @throws NotFoundException
* @throws InvalidArgumentException
* @throws UnauthorizedException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
foreach ($this->sitesConfig as $site => $siteConfig) {
$this->style->info("Indexing for site " . $site);
$this->style->info('Indexing for site ' . $site);
$this->indexContent($output, $input, $siteConfig);
}

Expand Down Expand Up @@ -103,11 +106,10 @@ private function indexContent(OutputInterface $output, InputInterface $input, ar

$output->writeln('');
$this->style->info('Finished.');

}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*/
private function getTotalCount(array $allowedContentTypes, array $contentIds): int
{
Expand All @@ -121,7 +123,7 @@ private function getTotalCount(array $allowedContentTypes, array $contentIds): i
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*/
private function getChunk(int $limit, int $offset, array $allowedContentTypes, array $contentIds): ContentList
{
Expand All @@ -130,6 +132,7 @@ private function getChunk(int $limit, int $offset, array $allowedContentTypes, a
->withLimit($limit)
->withOffset($offset)
;

return $this->contentService->find($filter);
}

Expand All @@ -141,6 +144,7 @@ private function getFilter(array $allowedContentTypes, array $contentIds = []):
if (count($contentIds) > 0) {
$filter->andWithCriterion(new Query\Criterion\ContentId($contentIds));
}

return $filter;
}

Expand Down
7 changes: 5 additions & 2 deletions bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

use function array_keys;
use function is_string;

class Configuration implements ConfigurationInterface
{
protected string $rootNodeName;
Expand Down Expand Up @@ -83,6 +86,7 @@ private function addPageIndexingSection(ArrayNodeDefinition $nodeDefinition): vo
return true;
}
}

return false;
};
$nodeDefinition
Expand All @@ -106,7 +110,7 @@ private function addPageIndexingSection(ArrayNodeDefinition $nodeDefinition): vo
->children()
->integerNode('tree_root_location_id')
->info('Site root Location ID')
->beforeNormalization()->always(static fn ($v) => is_string($v) ? (int)$v : $v)->end()
->beforeNormalization()->always(static fn ($v) => is_string($v) ? (int) $v : $v)->end()
->end()
->arrayNode('languages_siteaccess_map')
->info('Language code mapped to page siteaccess')
Expand Down Expand Up @@ -163,5 +167,4 @@ private function addPageIndexingSection(ArrayNodeDefinition $nodeDefinition): vo
->end()
->end();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

use Symfony\Component\Yaml\Yaml;

use function array_key_exists;
use function file_get_contents;

class NetgenIbexaSearchExtraExtension extends Extension implements PrependExtensionInterface
{
Expand All @@ -21,8 +22,9 @@ class NetgenIbexaSearchExtraExtension extends Extension implements PrependExtens
'languages_siteaccess_map' => [],
'host' => null,
'fields' => [],
'allowed_content_types' => []
'allowed_content_types' => [],
];

public function getAlias(): string
{
return 'netgen_ibexa_search_extra';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
namespace Netgen\IbexaSearchExtra\Container\Compiler;

use Ibexa\Contracts\Core\Persistence\Content\Handler;
use Ibexa\Elasticsearch\DocumentMapper\DocumentFactoryInterface;
use Netgen\IbexaSearchExtra\Core\Search\Elasticsearch\DocumentMapper\DocumentFactory;
use Netgen\IbexaSearchExtra\Core\Search\Elasticsearch\Query\CriterionVisitor\Content\VisibilityVisitor as ContentVisibilityVisitor;
use Netgen\IbexaSearchExtra\Core\Search\Elasticsearch\Query\CriterionVisitor\Location\VisibilityVisitor as LocationVisibilityVisitor;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Ibexa\Elasticsearch\DocumentMapper\DocumentFactoryInterface;

use function array_keys;
use function sprintf;

/**
* This compiler pass will register elastic search field mappers.
Expand All @@ -40,29 +42,8 @@ public function process(ContainerBuilder $container): void
->addTag('ibexa.search.elasticsearch.query.location.criterion.visitor');
}

private function processVisitors(ContainerBuilder $container, string $name): void
{
if (!$container->hasDefinition(sprintf('netgen.ibexa_search_extra.elasticsearch.field_mapper.%s.aggregate', $name))) {
return;
}

$aggregateDefinition = $container->getDefinition(
sprintf('netgen.ibexa_search_extra.elasticsearch.field_mapper.%s.aggregate', $name),
);

$this->registerMappers($aggregateDefinition, $container->findTaggedServiceIds(sprintf('netgen.ibexa_search_extra.elasticsearch.field_mapper.%s', $name)));
}

private function registerMappers(Definition $definition, array $mapperIds): void
{
foreach (array_keys($mapperIds) as $id) {
$definition->addMethodCall('addMapper', [new Reference($id)]);
}
}

/**
* @param ContainerBuilder $container
* @return void
*/
public function processDocumentFactory(ContainerBuilder $container): void
{
Expand All @@ -80,4 +61,24 @@ public function processDocumentFactory(ContainerBuilder $container): void
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.block_translation.aggregate'),
]);
}

private function processVisitors(ContainerBuilder $container, string $name): void
{
if (!$container->hasDefinition(sprintf('netgen.ibexa_search_extra.elasticsearch.field_mapper.%s.aggregate', $name))) {
return;
}

$aggregateDefinition = $container->getDefinition(
sprintf('netgen.ibexa_search_extra.elasticsearch.field_mapper.%s.aggregate', $name),
);

$this->registerMappers($aggregateDefinition, $container->findTaggedServiceIds(sprintf('netgen.ibexa_search_extra.elasticsearch.field_mapper.%s', $name)));
}

private function registerMappers(Definition $definition, array $mapperIds): void
{
foreach (array_keys($mapperIds) as $id) {
$definition->addMethodCall('addMapper', [new Reference($id)]);
}
}
}
5 changes: 2 additions & 3 deletions lib/Container/Compiler/PageIndexingPass.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?php

declare(strict_types=1);

namespace Netgen\IbexaSearchExtra\Container\Compiler;

use Netgen\IbexaSearchExtra\Core\Search\Solr\FieldMapper\ContentTranslation\ContentPageTextFieldMapper;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Ibexa\Elasticsearch\DocumentMapper\DocumentFactoryInterface;


class PageIndexingPass implements CompilerPassInterface
{

public function process(ContainerBuilder $container)
{
$usePageIndexing = $container->getParameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Ibexa\Contracts\Core\Persistence\Content\Handler as ContentHandler;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException;
use Netgen\IbexaSearchExtra\Core\Search\Common\PageTextExtractor;
use Netgen\IbexaSearchExtra\Core\Search\Common\SiteConfigResolver;
use Netgen\IbexaSearchExtra\Exception\IndexPageUnavailableException;
use Psr\Log\LoggerInterface;
Expand All @@ -18,6 +19,7 @@
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;

use function count;
use function explode;
use function in_array;
Expand All @@ -27,11 +29,12 @@
use function mb_substr;
use function sprintf;
use function trim;

use const XML_ELEMENT_NODE;
use const XML_HTML_DOCUMENT_NODE;
use const XML_TEXT_NODE;

class NativePageTextExtractor extends \Netgen\IbexaSearchExtra\Core\Search\Common\PageTextExtractor
class NativePageTextExtractor extends PageTextExtractor
{
/** @var array<int, array<string, array<string, array<int, string>|string>>> */
private array $cache = [];
Expand Down Expand Up @@ -88,9 +91,9 @@ public function extractPageText(int $contentId, string $languageCode): array
* @param string $languageCode
* @param int $contentId
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*
* @return string
*
* @throws NotFoundException
*/
private function generateUrl(string $languageCode, int $contentId, array $siteConfig): string
{
Expand Down Expand Up @@ -118,7 +121,6 @@ private function generateUrl(string $languageCode, int $contentId, array $siteCo
],
UrlGeneratorInterface::ABSOLUTE_URL,
);

}

private function resolveSiteAccess(ContentInfo $contentInfo, string $languageCode): string
Expand All @@ -128,18 +130,17 @@ private function resolveSiteAccess(ContentInfo $contentInfo, string $languageCod
if (!isset($siteConfig['languages_siteaccess_map'][$languageCode])) {
throw new RuntimeException(
sprintf(
"Language not supported for matched siteaccess group %s",
$siteConfig['site']
)
'Language not supported for matched siteaccess group %s',
$siteConfig['site'],
),
);
}

return $siteConfig['languages_siteaccess_map'][$languageCode];

}

/**
* @param \DOMNode $node
* @param DOMNode $node
* @param array<string, array<int, string>> $textArray
*
* @return array<string, array<int, string>>
Expand All @@ -158,7 +159,6 @@ private function recursiveExtractTextArray(DOMNode $node, array &$textArray, int
foreach ($node->childNodes as $childNode) {
$this->recursiveExtractTextArray($childNode, $textArray, $contentId);
}

}
if ($node->nodeType === XML_TEXT_NODE) {
$textContent = trim($node->textContent);
Expand Down Expand Up @@ -207,7 +207,7 @@ private function hasClass(DOMNode $node, string $className): bool
/**
* @throws NotFoundException
* @throws UnauthorizedException
* @throws \RuntimeException
* @throws RuntimeException
*/
private function fetchPageSource(int $contentId, string $languageCode, array $siteConfig): string
{
Expand All @@ -218,7 +218,7 @@ private function fetchPageSource(int $contentId, string $languageCode, array $si

$response = $httpClient->request(
'GET',
$url
$url,
);

$html = $response->getContent();
Expand Down
22 changes: 13 additions & 9 deletions lib/Core/Search/Common/SiteConfigResolver.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?php

declare(strict_types=1);

namespace Netgen\IbexaSearchExtra\Core\Search\Common;

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 RuntimeException;

use function explode;
use function in_array;
use function sprintf;

class SiteConfigResolver
{

/**
* @param array<string, mixed> $sitesConfig
*/
public function __construct(
private readonly ContentHandler $contentHandler,
private readonly LocationHandler $locationHandler,
private readonly array $sitesConfig
) {
}
) {}

public function getSiteConfigForContent(int $contentId): array
{
Expand All @@ -38,19 +42,19 @@ public function getSiteConfigForContent(int $contentId): array
$pathString = $location->pathString;
$pathArray = explode('/', $pathString);

foreach ($this->sitesConfig as $site => $siteConfig) {
foreach ($this->sitesConfig as $site => $siteConfig) {
if (in_array($siteConfig['tree_root_location_id'], $pathArray, false)) {
$siteConfig['site'] = $site;
$siteConfig['site'] = $site;

return $siteConfig;
}
}

throw new RuntimeException(
sprintf(
"Failed to match content ID %d to a siteaccess",
$contentInfo->id
)
'Failed to match content ID %d to a siteaccess',
$contentInfo->id,
),
);

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Netgen\IbexaSearchExtra\Core\Search\Elasticsearch\DocumentMapper;

use Ibexa\Contracts\Core\Persistence\Content as SPIContent;
Expand Down
Loading

0 comments on commit efd39bc

Please sign in to comment.