diff --git a/src/Controller/Api/Assets/CollectionController.php b/src/Controller/Api/Assets/CollectionController.php index dac059fd8..b48b65e43 100644 --- a/src/Controller/Api/Assets/CollectionController.php +++ b/src/Controller/Api/Assets/CollectionController.php @@ -36,7 +36,6 @@ use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\Parameters; use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface; use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface; -use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapQueryString; use Symfony\Component\Routing\Attribute\Route; @@ -85,7 +84,6 @@ public function __construct( #[UnauthorizedResponse] public function getAssets(#[MapQueryString] Parameters $parameters): JsonResponse { - /** @var AssetQuery $assetQuery */ $assetQuery = $this->filterService->applyFilters( $parameters, FilterServiceInterface::TYPE_ASSET diff --git a/src/Controller/Api/DataObjects/CollectionController.php b/src/Controller/Api/DataObjects/CollectionController.php index 60bdd5ce7..0d8ca614b 100644 --- a/src/Controller/Api/DataObjects/CollectionController.php +++ b/src/Controller/Api/DataObjects/CollectionController.php @@ -37,7 +37,6 @@ use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\DataObjectParameters; use Pimcore\Bundle\StudioApiBundle\Service\DataObjectSearchServiceInterface; use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface; -use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapQueryString; use Symfony\Component\Routing\Attribute\Route; @@ -85,7 +84,6 @@ public function __construct( public function getDataObjects(#[MapQueryString] DataObjectParameters $parameters): JsonResponse { - /** @var DataObjectQuery $dataObjectQuery */ $dataObjectQuery = $this->filterService->applyFilters($parameters, 'dataObject'); $result = $this->dataObjectSearchService->searchDataObjects($dataObjectQuery); diff --git a/src/Exception/InvalidSearchException.php b/src/Exception/InvalidSearchException.php new file mode 100644 index 000000000..17ab96cbd --- /dev/null +++ b/src/Exception/InvalidSearchException.php @@ -0,0 +1,23 @@ +assetSearchAdapter->searchAssets($assetQuery); } diff --git a/src/Service/AssetSearchServiceInterface.php b/src/Service/AssetSearchServiceInterface.php index 482a74f4c..5a49605a5 100644 --- a/src/Service/AssetSearchServiceInterface.php +++ b/src/Service/AssetSearchServiceInterface.php @@ -25,11 +25,11 @@ use Pimcore\Bundle\StudioApiBundle\Response\Asset\Text; use Pimcore\Bundle\StudioApiBundle\Response\Asset\Unknown; use Pimcore\Bundle\StudioApiBundle\Response\Asset\Video; -use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; interface AssetSearchServiceInterface { - public function searchAssets(AssetQuery $assetQuery): AssetSearchResult; + public function searchAssets(QueryInterface $assetQuery): AssetSearchResult; public function getAssetById(int $id): Asset|Archive|Audio|Document|Folder|Image|Text|Unknown|Video|null; } diff --git a/src/Service/DataObjectSearchService.php b/src/Service/DataObjectSearchService.php index aa7ab6625..c09c8ee2a 100644 --- a/src/Service/DataObjectSearchService.php +++ b/src/Service/DataObjectSearchService.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioApiBundle\Service; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\DataObjectSearchAdapterInterface; -use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; use Pimcore\Model\DataObject\Concrete; final readonly class DataObjectSearchService implements DataObjectSearchServiceInterface @@ -26,7 +26,7 @@ public function __construct(private DataObjectSearchAdapterInterface $dataObject { } - public function searchDataObjects(DataObjectQuery $dataObjectQuery): DataObjectSearchResult + public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSearchResult { return $this->dataObjectSearchAdapter->searchDataObjects($dataObjectQuery); } diff --git a/src/Service/DataObjectSearchServiceInterface.php b/src/Service/DataObjectSearchServiceInterface.php index 018181607..a485dabda 100644 --- a/src/Service/DataObjectSearchServiceInterface.php +++ b/src/Service/DataObjectSearchServiceInterface.php @@ -16,12 +16,12 @@ namespace Pimcore\Bundle\StudioApiBundle\Service; -use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; use Pimcore\Model\DataObject\Concrete; interface DataObjectSearchServiceInterface { - public function searchDataObjects(DataObjectQuery $dataObjectQuery): DataObjectSearchResult; + public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSearchResult; public function getDataObjectById(int $id): Concrete|null; } diff --git a/src/Service/GenericData/AssetSearchAdapterInterface.php b/src/Service/GenericData/AssetSearchAdapterInterface.php index e2de598a7..69c14cbdc 100644 --- a/src/Service/GenericData/AssetSearchAdapterInterface.php +++ b/src/Service/GenericData/AssetSearchAdapterInterface.php @@ -18,11 +18,11 @@ use Pimcore\Bundle\StudioApiBundle\Response\Asset; use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchResult; -use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; interface AssetSearchAdapterInterface { - public function searchAssets(AssetQuery $assetQuery): AssetSearchResult; + public function searchAssets(QueryInterface $assetQuery): AssetSearchResult; public function getAssetById(int $id): ?Asset; } diff --git a/src/Service/GenericData/DataObjectSearchAdapterInterface.php b/src/Service/GenericData/DataObjectSearchAdapterInterface.php index 8b64f8d13..47f63779a 100644 --- a/src/Service/GenericData/DataObjectSearchAdapterInterface.php +++ b/src/Service/GenericData/DataObjectSearchAdapterInterface.php @@ -17,12 +17,12 @@ namespace Pimcore\Bundle\StudioApiBundle\Service\GenericData; use Pimcore\Bundle\StudioApiBundle\Service\DataObjectSearchResult; -use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; use Pimcore\Model\Element\ElementInterface; interface DataObjectSearchAdapterInterface { - public function searchDataObjects(DataObjectQuery $dataObjectQuery): DataObjectSearchResult; + public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSearchResult; public function getDataObjectById(int $id): ?ElementInterface; } diff --git a/src/Service/GenericData/V1/AssetQueryProvider.php b/src/Service/GenericData/V1/AssetQueryProvider.php index 297a6b8c8..5c5a2180f 100644 --- a/src/Service/GenericData/V1/AssetQueryProvider.php +++ b/src/Service/GenericData/V1/AssetQueryProvider.php @@ -24,7 +24,7 @@ public function __construct(private SearchProviderInterface $searchProvider) { } - public function createAssetQuery(): AssetQuery + public function createAssetQuery(): QueryInterface { return new AssetQuery($this->searchProvider->createAssetSearch()); } diff --git a/src/Service/GenericData/V1/AssetQueryProviderInterface.php b/src/Service/GenericData/V1/AssetQueryProviderInterface.php index b0428781a..c8a0addaa 100644 --- a/src/Service/GenericData/V1/AssetQueryProviderInterface.php +++ b/src/Service/GenericData/V1/AssetQueryProviderInterface.php @@ -18,5 +18,5 @@ interface AssetQueryProviderInterface { - public function createAssetQuery(): AssetQuery; + public function createAssetQuery(): QueryInterface; } diff --git a/src/Service/GenericData/V1/AssetSearchAdapter.php b/src/Service/GenericData/V1/AssetSearchAdapter.php index def594701..6ab1462cc 100644 --- a/src/Service/GenericData/V1/AssetSearchAdapter.php +++ b/src/Service/GenericData/V1/AssetSearchAdapter.php @@ -34,7 +34,7 @@ public function __construct( /** * @throws Exception */ - public function searchAssets(AssetQuery $assetQuery): AssetSearchResult + public function searchAssets(QueryInterface $assetQuery): AssetSearchResult { $searchResult = $this->searchService->search($assetQuery->getSearch()); $result = []; diff --git a/src/Service/GenericData/V1/DataObjectQueryProvider.php b/src/Service/GenericData/V1/DataObjectQueryProvider.php index a1bcd9233..be8265ae6 100644 --- a/src/Service/GenericData/V1/DataObjectQueryProvider.php +++ b/src/Service/GenericData/V1/DataObjectQueryProvider.php @@ -28,7 +28,7 @@ public function __construct( ) { } - public function createDataObjectQuery(): DataObjectQuery + public function createDataObjectQuery(): QueryInterface { /** @var DataObjectSearch $dataObjectSearch */ $dataObjectSearch = $this->searchProvider->createDataObjectSearch(); diff --git a/src/Service/GenericData/V1/DataObjectQueryProviderInterface.php b/src/Service/GenericData/V1/DataObjectQueryProviderInterface.php index efc50209c..a602b8ab1 100644 --- a/src/Service/GenericData/V1/DataObjectQueryProviderInterface.php +++ b/src/Service/GenericData/V1/DataObjectQueryProviderInterface.php @@ -18,5 +18,5 @@ interface DataObjectQueryProviderInterface { - public function createDataObjectQuery(): DataObjectQuery; + public function createDataObjectQuery(): QueryInterface; } diff --git a/src/Service/GenericData/V1/DataObjectSearchAdapter.php b/src/Service/GenericData/V1/DataObjectSearchAdapter.php index 874d6391e..d1c1bce4e 100644 --- a/src/Service/GenericData/V1/DataObjectSearchAdapter.php +++ b/src/Service/GenericData/V1/DataObjectSearchAdapter.php @@ -16,8 +16,10 @@ namespace Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\DataObjectSearchInterface; use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\DataObject\DataObjectSearchServiceInterface; use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolver; +use Pimcore\Bundle\StudioApiBundle\Exception\InvalidSearchException; use Pimcore\Bundle\StudioApiBundle\Response\DataObject; use Pimcore\Bundle\StudioApiBundle\Service\DataObjectSearchResult; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\DataObjectSearchAdapterInterface; @@ -32,9 +34,23 @@ public function __construct( ) { } - public function searchDataObjects(DataObjectQuery $dataObjectQuery): DataObjectSearchResult + /** + * @throws InvalidSearchException + */ + public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSearchResult { - $searchResult = $this->searchService->search($dataObjectQuery->getSearch()); + + $search = $dataObjectQuery->getSearch(); + if (!$search instanceof DataObjectSearchInterface) { + throw new InvalidSearchException( + sprintf( + 'Expected search to be an instance of %s, got %s', + DataObjectSearchInterface::class, + get_class($search) + ) + ); + } + $searchResult = $this->searchService->search($search); $result = []; foreach($searchResult->getIds() as $id) { /** @var Concrete $dataObject */