Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Dec 22, 2023
1 parent 94bf067 commit 3aafbb7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ services:
- {name: ibexa.search.legacy.gateway.criterion_handler.content}
- {name: ibexa.search.legacy.gateway.criterion_handler.location}

Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\ContentName:
parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler
tags:
- { name: ibexa.search.legacy.gateway.criterion_handler.content }
- { name: ibexa.search.legacy.gateway.criterion_handler.location }

Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\ContentTypeGroupId:
parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler
class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\ContentTypeGroupId
Expand Down Expand Up @@ -339,11 +345,3 @@ services:

ibexa.search.legacy.gateway.criterion_field_value_handler.default:
alias: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldValue\Handler\Composite

Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\ContentName:
parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler
arguments:
$transformationProcessor: '@Ibexa\Core\Persistence\TransformationProcessor\PreprocessedBased'
tags:
- { name: ibexa.search.legacy.gateway.criterion_handler.content }
- { name: ibexa.search.legacy.gateway.criterion_handler.location }
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,17 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Core\Persistence\TransformationProcessor;
use Ibexa\Core\Persistence\Legacy\Content\Gateway;
use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler;

/**
* @internal
*/
final class ContentName extends CriterionHandler
{
private const CONTENTOBJECT_NAME_ALIAS = 'ezc_n';
private const CONTENTOBJECT_ALIAS = 'c';

private TransformationProcessor $transformationProcessor;

public function __construct(
Connection $connection,
TransformationProcessor $transformationProcessor
) {
parent::__construct($connection);

$this->transformationProcessor = $transformationProcessor;
}
private const CONTENTOBJECT_ALIAS = 'ezc';

public function accept(Criterion $criterion): bool
{
Expand All @@ -42,6 +34,8 @@ public function accept(Criterion $criterion): bool
* languages: array<string>,
* useAlwaysAvailable: bool,
* } $languageSettings
*
* @throws \Doctrine\DBAL\Exception
*/
public function handle(
CriteriaConverter $converter,
Expand All @@ -53,18 +47,20 @@ public function handle(
$subQuery
->select('contentobject_id')
->distinct()
->from('ezcontentobject_name', self::CONTENTOBJECT_NAME_ALIAS)
->from(Gateway::CONTENT_NAME_TABLE, self::CONTENTOBJECT_NAME_ALIAS)
->innerJoin(
self::CONTENTOBJECT_NAME_ALIAS,
'ezcontentobject',
Gateway::CONTENT_ITEM_TABLE,
self::CONTENTOBJECT_ALIAS,
$this->getInnerJoinCondition()
)
->andWhere(
$queryBuilder->expr()->like(
$this->toLowerCase(self::CONTENTOBJECT_NAME_ALIAS . '.name'),
$queryBuilder->createNamedParameter(
$this->prepareValue($criterion)
$this->toLowerCase(
$queryBuilder->createNamedParameter(
$this->prepareValue($criterion)
)
)
)
);
Expand All @@ -78,7 +74,7 @@ public function handle(
}

return $queryBuilder->expr()->in(
self::CONTENTOBJECT_ALIAS . '.id',
'c.id',
$subQuery->getSQL()
);
}
Expand All @@ -96,6 +92,8 @@ private function getInnerJoinCondition(): string

/**
* @param array<string> $languages
*
* @throws \Doctrine\DBAL\Exception
*/
private function addLanguageConditionToSubQuery(
QueryBuilder $subQuery,
Expand All @@ -105,7 +103,9 @@ private function addLanguageConditionToSubQuery(
$subQuery
->andWhere(
$queryBuilder->expr()->in(
$this->toLowerCase(self::CONTENTOBJECT_NAME_ALIAS . '.content_translation'),
$this->toLowerCase(
self::CONTENTOBJECT_NAME_ALIAS . '.content_translation'
),
$this->toLowerCase(
$queryBuilder->createNamedParameter(
$languages,
Expand All @@ -125,20 +125,17 @@ private function prepareValue(Criterion $criterion): string
'*',
'%',
addcslashes(
$this->transformationProcessor->transformByGroup(
$value,
'lowercase'
),
$value,
'%_'
)
);
}

/**
* @throws \Doctrine\DBAL\Exception
*/
private function toLowerCase(string $value): string
{
return sprintf(
'LOWER(%s)',
$value
);
return $this->connection->getDatabasePlatform()->getLowerExpression($value);
}
}

0 comments on commit 3aafbb7

Please sign in to comment.