Skip to content

Commit

Permalink
Introduce two new interfaces for DataIndex Query (#430)
Browse files Browse the repository at this point in the history
* Refactor QueryInterface

* Apply php-cs-fixer changes

* Add some unit tests for Asset Filter.

* Apply php-cs-fixer changes

---------

Co-authored-by: martineiber <[email protected]>
  • Loading branch information
martineiber and martineiber authored Sep 23, 2024
1 parent 83dc3bd commit 85febaa
Show file tree
Hide file tree
Showing 31 changed files with 1,044 additions and 31 deletions.
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ services:
environment:
PHP_IDE_CONFIG: serverName=localhost
volumes:
- .:/var/cli/
- .:/var/cli/
- ./.docker/30-xdebug.ini:/usr/local/etc/php/conf.d/30-xdebug.ini
6 changes: 3 additions & 3 deletions src/DataIndex/Filter/Asset/IsAssetFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset;

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\ColumnFiltersParameterInterface;

/**
Expand All @@ -33,9 +33,9 @@ public function validateParameterType(mixed $parameters): ?ColumnFiltersParamete
return null;
}

public function validateQueryType(mixed $query): ?AssetQuery
public function validateQueryType(mixed $query): ?AssetQueryInterface
{
if ($query instanceof AssetQuery) {
if ($query instanceof AssetQueryInterface) {
return $query;
}

Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/Metadata/AssetFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applyAssetFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applyAssetFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_int($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for asset must be a integer (ID of the asset)');
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/Metadata/CheckboxFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applyCheckboxFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applyCheckboxFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_bool($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for checkbox must be a boolean');
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/Metadata/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\OpenSearch\Query\DateFilter as GenericDateFilter;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -49,7 +49,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applyDateFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applyDateFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_array($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for date must be an array');
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/Metadata/DocumentFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applyDocumentFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applyDocumentFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_int($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for document must be a integer (ID of the document)');
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/Metadata/InputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applyInputFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applyInputFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_string($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for input must be a string');
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/Metadata/ObjectFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applyAssetFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applyAssetFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_int($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for object must be a integer (ID of the object)');
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/Metadata/SelectFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applySelectFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applySelectFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_string($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for select must be a string');
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/Metadata/TextAreaFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applyTextAreaFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applyTextAreaFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_string($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for textarea must be a string');
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/SortFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\GenericDataIndexBundle\Enum\Search\SortDirection;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\SortFilterParameterInterface;

Expand All @@ -29,7 +29,7 @@ final class SortFilter implements FilterInterface
{
public function apply(mixed $parameters, QueryInterface $query): QueryInterface
{
if (!$query instanceof AssetQuery) {
if (!$query instanceof AssetQueryInterface) {
return $query;
}

Expand Down
6 changes: 3 additions & 3 deletions src/DataIndex/Filter/Asset/System/DatetimeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applyDatetimeFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applyDatetimeFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_array($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for this filter must be an array');
Expand All @@ -57,7 +57,7 @@ private function applyDatetimeFilter(ColumnFilter $column, AssetQuery $query): A
$filterValue = $column->getFilterValue();

if (isset($filterValue['on'])) {
$query->filterDatetime($column->getKey(), null, $filterValue['on']);
$query->filterDatetime($column->getKey(), null, null, $filterValue['on']);
}

if (isset($filterValue['to'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/Asset/System/StringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\IsAssetFilterTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
return $assetQuery;
}

private function applyStringFilter(ColumnFilter $column, AssetQuery $query): AssetQuery
private function applyStringFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_string($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for this filter must be a string');
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Filter/DataObject/ClassNameFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Exception;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\DataObjectQuery;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\DataObjectQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Request\ClassNameParametersInterface;

Expand All @@ -34,7 +34,7 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface
{
if (
!$parameters instanceof ClassNameParametersInterface ||
!$query instanceof DataObjectQuery ||
!$query instanceof DataObjectQueryInterface ||
!$parameters->getClassName()
) {
return $query;
Expand Down
2 changes: 1 addition & 1 deletion src/DataIndex/Query/AssetQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\OrderByField;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath;

final class AssetQuery implements QueryInterface
final class AssetQuery implements AssetQueryInterface
{
public const ASSET_QUERY_ID = 'asset_query';

Expand Down
44 changes: 44 additions & 0 deletions src/DataIndex/Query/AssetQueryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Query;

use Pimcore\Bundle\GenericDataIndexBundle\Enum\Search\SortDirection;

/**
* @internal
*/
interface AssetQueryInterface extends QueryInterface
{
public function filterMetadata(string $name, string $type, mixed $data): self;

public function orderByField(string $fieldName, SortDirection $direction): self;

public function wildcardSearch(
string $fieldName,
string $searchTerm,
bool $enablePqlFieldNameResolution = true
): self;

public function filterDatetime(
string $field,
int|null $startDate = null,
int|null $endDate = null,
int|null $onDate = null,
bool $roundToDay = true,
bool $enablePqlFieldNameResolution = true
): self;
}
2 changes: 1 addition & 1 deletion src/DataIndex/Query/DataObjectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ClassDefinitionResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;

final class DataObjectQuery implements QueryInterface
final class DataObjectQuery implements DataObjectQueryInterface
{
public const DATA_OBJECT_QUERY_ID = 'data_object_query';

Expand Down
30 changes: 30 additions & 0 deletions src/DataIndex/Query/DataObjectQueryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Query;

use Exception;

/**
* @internal
*/
interface DataObjectQueryInterface extends QueryInterface
{
/**
* @throws Exception
*/
public function setClassDefinitionName(string $classDefinitionId): self;
}
Loading

0 comments on commit 85febaa

Please sign in to comment.