Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: [Grid] [Asset] Refactor Data Source #447

Merged
merged 15 commits into from
Oct 2, 2024
10 changes: 10 additions & 0 deletions config/data_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ services:

Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator\AssetHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator\AssetHydrator
Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator\DocumentHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator\DocumentHydrator
Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator\Asset\PermissionsHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator\Asset\PermissionsHydrator

Expand Down Expand Up @@ -63,6 +65,14 @@ services:
class: Pimcore\Bundle\StudioBackendBundle\DataIndex\Provider\DataObjectQueryProvider


# Documents
Pimcore\Bundle\StudioBackendBundle\DataIndex\Adapter\DocumentSearchAdapterInterface:
class: Pimcore\Bundle\StudioBackendBundle\DataIndex\Adapter\DocumentSearchAdapter

Pimcore\Bundle\StudioBackendBundle\DataIndex\DocumentSearchServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\DataIndex\DocumentSearchService


#Service Locator
open_search.asset_hydrator.service_locator:
class: Symfony\Component\DependencyInjection\ServiceLocator
Expand Down
9 changes: 9 additions & 0 deletions config/documents.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

# Secvices
Pimcore\Bundle\StudioBackendBundle\Document\Service\DocumentServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Document\Service\DocumentService
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Exception;
use Pimcore\Bundle\StaticResolverBundle\Models\User\UserResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvCollectionMessage;
use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv;
use Pimcore\Bundle\StudioBackendBundle\Element\Service\ElementServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\AutomationAction\AbstractHandler;
Expand All @@ -45,7 +46,8 @@ public function __construct(
private readonly PublishServiceInterface $publishService,
private readonly ElementServiceInterface $elementService,
private readonly UserResolverInterface $userResolver,
private readonly GridServiceInterface $gridService
private readonly GridServiceInterface $gridService,
private readonly AssetServiceInterface $assetService
) {
parent::__construct();
}
Expand All @@ -70,6 +72,8 @@ public function __invoke(CsvCollectionMessage $message): void
}

$jobAsset = $this->extractConfigFieldFromJobStepConfig($message, Csv::ASSET_TO_EXPORT->value);
// TODO: Replace getElementById with getAsset with permission check.
// We do not want to load the asset form the database. Permission check should be done in the index.
$asset = $this->getElementById(
new ElementDescriptor($jobAsset['type'], $jobAsset['id']),
$user,
Expand All @@ -91,11 +95,13 @@ public function __invoke(CsvCollectionMessage $message): void
true
);

$indexAsset = $this->assetService->getAsset($asset->getId());

try {
$assetData = [
$asset->getId() => $this->gridService->getGridValuesForElement(
$columnCollection,
$asset,
$indexAsset,
ElementTypes::TYPE_ASSET
),
];
Expand Down
18 changes: 17 additions & 1 deletion src/Asset/Schema/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use OpenApi\Attributes\Property;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetMetaData;
use Pimcore\Bundle\StudioBackendBundle\Response\Element;
use Pimcore\Bundle\StudioBackendBundle\Response\ElementIcon;
use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface;
Expand Down Expand Up @@ -71,7 +72,9 @@ public function __construct(
?string $locked,
bool $isLocked,
?int $creationDate,
?int $modificationDate
?int $modificationDate,
private readonly array $metadata = [],
private readonly int $fileSize = 0,
) {
parent::__construct(
$id,
Expand Down Expand Up @@ -126,4 +129,17 @@ public function getPermissions(): AssetPermissions
{
return $this->permissions;
}

/**
* @return AssetMetaData[]
*/
public function getMetadata(): array
{
return $this->metadata;
}

public function getFileSize(): int
{
return $this->fileSize;
}
}
6 changes: 5 additions & 1 deletion src/Asset/Schema/Type/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function __construct(
bool $isLocked,
?int $creationDate,
?int $modificationDate,
array $metadata = [],
int $fileSize = 0,
) {
parent::__construct(
$hasChildren,
Expand All @@ -78,7 +80,9 @@ public function __construct(
$locked,
$isLocked,
$creationDate,
$modificationDate
$modificationDate,
$metadata,
$fileSize
);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Asset/Schema/Type/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public function __construct(
?string $locked,
bool $isLocked,
?int $creationDate,
?int $modificationDate
?int $modificationDate,
array $metadata = [],
int $fileSize = 0,
) {
parent::__construct(
$hasChildren,
Expand All @@ -87,6 +89,8 @@ public function __construct(
$isLocked,
$creationDate,
$modificationDate,
$metadata,
$fileSize
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Asset/Schema/Type/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function __construct(
bool $isLocked,
?int $creationDate,
?int $modificationDate,
array $metadata = [],
int $fileSize = 0
) {
parent::__construct(
$hasChildren,
Expand All @@ -79,6 +81,8 @@ public function __construct(
$isLocked,
$creationDate,
$modificationDate,
$metadata,
$fileSize
);
}

Expand Down
55 changes: 55 additions & 0 deletions src/DataIndex/Adapter/DocumentSearchAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Adapter;

use Pimcore\Bundle\GenericDataIndexBundle\Exception\DocumentSearchException;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Document\DocumentSearchServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator\DocumentHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Document;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException;
use function sprintf;

/**
* @internal
*/
final readonly class DocumentSearchAdapter implements DocumentSearchAdapterInterface
{
public function __construct(
private DocumentSearchServiceInterface $searchService,
private DocumentHydratorInterface $hydratorService
) {
}

/**
* @throws SearchException|NotFoundException
*/
public function getDocumentById(int $id): Document
{
try {
$document = $this->searchService->byId($id);
} catch (DocumentSearchException) {
throw new SearchException(sprintf('Document with id %s', $id));
}

if (!$document) {
throw new NotFoundException('Asset', $id);
}

return $this->hydratorService->hydrate($document);
}
}
32 changes: 32 additions & 0 deletions src/DataIndex/Adapter/DocumentSearchAdapterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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\Adapter;

use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Document;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException;

/**
* @internal
*/
interface DocumentSearchAdapterInterface
{
/**
* @throws SearchException|NotFoundException
*/
public function getDocumentById(int $id): Document;
}
41 changes: 41 additions & 0 deletions src/DataIndex/DocumentSearchService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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;

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Adapter\DocumentSearchAdapterInterface;
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Document;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException;

/**
* @internal
*/
final readonly class DocumentSearchService implements DocumentSearchServiceInterface
{
public function __construct(
private DocumentSearchAdapterInterface $documentSearchAdapter
) {
}

/**
* @throws SearchException|NotFoundException
*/
public function getDocumentById(int $id): Document
{
return $this->documentSearchAdapter->getDocumentById($id);
}
}
32 changes: 32 additions & 0 deletions src/DataIndex/DocumentSearchServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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;

use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Document;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException;

/**
* @internal
*/
interface DocumentSearchServiceInterface
{
/**
* @throws SearchException|NotFoundException
*/
public function getDocumentById(int $id): Document;
}
2 changes: 2 additions & 0 deletions src/DataIndex/Hydrator/Asset/ArchiveHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function hydrate(ArchiveItem $item): Archive
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$item->getMetaData(),
$item->getFileSize(),
);
}
}
2 changes: 2 additions & 0 deletions src/DataIndex/Hydrator/Asset/AudioHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function hydrate(AudioItem $item): Audio
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$item->getMetaData(),
$item->getFileSize(),
);
}
}
2 changes: 2 additions & 0 deletions src/DataIndex/Hydrator/Asset/DocumentHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function hydrate(DocumentItem $item): Document
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$item->getMetaData(),
$item->getFileSize(),
);
}
}
2 changes: 2 additions & 0 deletions src/DataIndex/Hydrator/Asset/FolderHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function hydrate(FolderItem $item): AssetFolder
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$item->getMetaData(),
$item->getFileSize(),
);
}
}
2 changes: 2 additions & 0 deletions src/DataIndex/Hydrator/Asset/ImageHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function hydrate(ImageItem $item): Image
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$item->getMetaData(),
$item->getFileSize(),
);
}
}
2 changes: 2 additions & 0 deletions src/DataIndex/Hydrator/Asset/TextHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function hydrate(TextItem $item): Text
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$item->getMetaData(),
$item->getFileSize(),
);
}
}
2 changes: 2 additions & 0 deletions src/DataIndex/Hydrator/Asset/UnknownHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function hydrate(UnknownItem $item): Unknown
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$item->getMetaData(),
$item->getFileSize(),
);
}
}
Loading
Loading