Skip to content

Commit

Permalink
[BC] Introduce type specific interfaces (#227)
Browse files Browse the repository at this point in the history
* Introduce type specific interfaces

* Apply php-cs-fixer changes

* fix namespace

* Import correct interfaces

* More interface related problems

* Update search provider

* Fix more name

* Fix elementservice

* Add upgrade notes

---------

Co-authored-by: mattamon <[email protected]>
  • Loading branch information
mattamon and mattamon authored Oct 7, 2024
1 parent 04b255b commit 1f3662d
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 23 deletions.
21 changes: 21 additions & 0 deletions doc/01_Installation/02_Upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,24 @@ Following steps are necessary during updating to newer versions.
- Execute the following command to reindex all elements to be able to use all new features:

```bin/console generic-data-index:update:index```

## Upgrade to 2.0.0

### BC-Breaks

#### Interface changes
- Added `PermissionTypes $permissionType` parameter with default type `PermissionTypes::LIST` to
- `AssetSearchServiceInterface::search` method
- `DocumentSearchServiceInterface::search` method
- `DataObjectSearchServiceInterface::search` method
- `ElementSearchServiceInterface::search` method
- Search services `byId` methods now return elements based on the `PermissionTypes::VIEW` permission
- Added type specific interfaces for searches to avoid mixing up different search types in search services
- `AssetSearch` now implements `AssetSearchInterface`
- `DocumentSearch` now implements `DocumentSearchInterface`
- `ElementSearch` now implements `ElementSearchInterface`
- Search services now require the specific search type for the search
- `AssetSearchServiceInterface::search` now requires a `AssetSearchInterface`
- `DocumentSearchServiceInterface::search` now requires a `DocumentSearchInterface`
- `ElementSearchServiceInterface::search` now requires a `ElementSearchInterface`
- `SearchProviderInterface` now returns type specific search interfaces
2 changes: 1 addition & 1 deletion src/Model/Search/Asset/AssetSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\BaseSearch;

final class AssetSearch extends BaseSearch
final class AssetSearch extends BaseSearch implements AssetSearchInterface
{
}
23 changes: 23 additions & 0 deletions src/Model/Search/Asset/AssetSearchInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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\GenericDataIndexBundle\Model\Search\Asset;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;

interface AssetSearchInterface extends SearchInterface
{
}
2 changes: 1 addition & 1 deletion src/Model/Search/Document/DocumentSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\BaseSearch;

final class DocumentSearch extends BaseSearch
final class DocumentSearch extends BaseSearch implements DocumentSearchInterface
{
}
23 changes: 23 additions & 0 deletions src/Model/Search/Document/DocumentSearchInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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\GenericDataIndexBundle\Model\Search\Document;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;

interface DocumentSearchInterface extends SearchInterface
{
}
2 changes: 1 addition & 1 deletion src/Model/Search/Element/ElementSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\BaseSearch;

final class ElementSearch extends BaseSearch
final class ElementSearch extends BaseSearch implements ElementSearchInterface
{
}
23 changes: 23 additions & 0 deletions src/Model/Search/Element/ElementSearchInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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\GenericDataIndexBundle\Model\Search\Element;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;

interface ElementSearchInterface extends SearchInterface
{
}
4 changes: 2 additions & 2 deletions src/Service/Search/SearchService/Asset/AssetSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use Pimcore\Bundle\GenericDataIndexBundle\Enum\Permission\PermissionTypes;
use Pimcore\Bundle\GenericDataIndexBundle\Enum\Permission\UserPermissionTypes;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\AssetSearchException;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\AssetSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetSearchResult;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetSearchResultItem;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Permission\Workspace\AssetWorkspace;
use Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\Search\Pagination\PaginationInfoServiceInterface;
Expand All @@ -49,7 +49,7 @@ public function __construct(
* @throws AssetSearchException
*/
public function search(
SearchInterface $assetSearch,
AssetSearchInterface $assetSearch,
PermissionTypes $permissionType = PermissionTypes::LIST
): AssetSearchResult {
$assetSearch = $this->searchHelper->addSearchRestrictions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

use Pimcore\Bundle\GenericDataIndexBundle\Enum\Permission\PermissionTypes;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\AssetSearchException;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\AssetSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetSearchResult;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetSearchResultItem;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;

use Pimcore\Model\User;

interface AssetSearchServiceInterface
Expand All @@ -29,7 +30,7 @@ interface AssetSearchServiceInterface
* @throws AssetSearchException
*/
public function search(
SearchInterface $assetSearch,
AssetSearchInterface $assetSearch,
PermissionTypes $permissionType = PermissionTypes::LIST
): AssetSearchResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use Pimcore\Bundle\GenericDataIndexBundle\Enum\Permission\PermissionTypes;
use Pimcore\Bundle\GenericDataIndexBundle\Enum\Permission\UserPermissionTypes;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\DocumentSearchException;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\DocumentSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\SearchResult\DocumentSearchResult;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\SearchResult\DocumentSearchResultItem;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Permission\Workspace\DocumentWorkspace;
use Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\Search\Pagination\PaginationInfoServiceInterface;
Expand All @@ -49,7 +49,7 @@ public function __construct(
* @throws DocumentSearchException
*/
public function search(
SearchInterface $documentSearch,
DocumentSearchInterface $documentSearch,
PermissionTypes $permissionType = PermissionTypes::LIST
): DocumentSearchResult {
$documentSearch = $this->searchHelper->addSearchRestrictions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

use Pimcore\Bundle\GenericDataIndexBundle\Enum\Permission\PermissionTypes;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\DocumentSearchException;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\DocumentSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\SearchResult\DocumentSearchResult;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\SearchResult\DocumentSearchResultItem;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;
use Pimcore\Model\User;

interface DocumentSearchServiceInterface
Expand All @@ -29,7 +29,7 @@ interface DocumentSearchServiceInterface
* @throws DocumentSearchException
*/
public function search(
SearchInterface $documentSearch,
DocumentSearchInterface $documentSearch,
PermissionTypes $permissionType = PermissionTypes::LIST
): DocumentSearchResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use Pimcore\Bundle\GenericDataIndexBundle\Enum\Permission\PermissionTypes;
use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\ElementType;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\ElementSearchException;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element\ElementSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element\SearchResult\ElementSearchResult;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\Search\Pagination\PaginationInfoServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Asset\AssetSearchServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\DataObject\DataObjectSearchServiceInterface;
Expand All @@ -46,7 +46,7 @@ public function __construct(
}

public function search(
SearchInterface $elementSearch,
ElementSearchInterface $elementSearch,
PermissionTypes $permissionType = PermissionTypes::LIST
): ElementSearchResult {
$elementSearch = $this->searchHelper->addSearchRestrictions($elementSearch, $permissionType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
use Pimcore\Bundle\GenericDataIndexBundle\Enum\Permission\PermissionTypes;
use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\ElementType;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\ElementSearchException;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element\ElementSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element\SearchResult\ElementSearchResult;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;
use Pimcore\Model\User;

interface ElementSearchServiceInterface
Expand All @@ -30,7 +30,7 @@ interface ElementSearchServiceInterface
* @throws ElementSearchException
*/
public function search(
SearchInterface $elementSearch,
ElementSearchInterface $elementSearch,
PermissionTypes $permissionType = PermissionTypes::LIST
): ElementSearchResult;

Expand Down
10 changes: 6 additions & 4 deletions src/Service/Search/SearchService/SearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
namespace Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\AssetSearch;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\AssetSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\DataObjectSearch;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\DataObjectSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\DocumentSearch;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\DocumentSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element\ElementSearch;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element\ElementSearchInterface;

/**
* @internal
*/
final class SearchProvider implements SearchProviderInterface
{
public function createAssetSearch(): SearchInterface
public function createAssetSearch(): AssetSearchInterface
{
return new AssetSearch();
}
Expand All @@ -38,12 +40,12 @@ public function createDataObjectSearch(): DataObjectSearchInterface
return new DataObjectSearch();
}

public function createDocumentSearch(): SearchInterface
public function createDocumentSearch(): DocumentSearchInterface
{
return new DocumentSearch();
}

public function createElementSearch(): SearchInterface
public function createElementSearch(): ElementSearchInterface
{
return new ElementSearch();
}
Expand Down
10 changes: 6 additions & 4 deletions src/Service/Search/SearchService/SearchProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\AssetSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\DataObjectSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\DocumentSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element\ElementSearchInterface;

interface SearchProviderInterface
{
public function createAssetSearch(): SearchInterface;
public function createAssetSearch(): AssetSearchInterface;

public function createDataObjectSearch(): DataObjectSearchInterface;

public function createDocumentSearch(): SearchInterface;
public function createDocumentSearch(): DocumentSearchInterface;

public function createElementSearch(): SearchInterface;
public function createElementSearch(): ElementSearchInterface;
}

0 comments on commit 1f3662d

Please sign in to comment.