Skip to content

Commit

Permalink
[Task] Saving strategy for elements (#78)
Browse files Browse the repository at this point in the history
* Very rudimentary implementation

* Apply php-cs-fixer changes

* Refine updater

* Add space

* Apply php-cs-fixer changes

* Consistency check

* Update files

* Apply php-cs-fixer changes

* Remove updatecontroller for element properties

* Apply php-cs-fixer changes

* Supporting element type

* Remove unused uses

* Add space

* Make property nullable

* Change tag attributes

* Move updating to repository

---------

Co-authored-by: mattamon <[email protected]>
  • Loading branch information
mattamon and mattamon authored May 27, 2024
1 parent 21986aa commit 0bb0619
Show file tree
Hide file tree
Showing 26 changed files with 526 additions and 163 deletions.
5 changes: 4 additions & 1 deletion config/assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ services:
class: Pimcore\Bundle\StudioBackendBundle\Asset\Service\CustomSettingsService

Pimcore\Bundle\StudioBackendBundle\Asset\Service\DataServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Asset\Service\DataService
class: Pimcore\Bundle\StudioBackendBundle\Asset\Service\DataService



16 changes: 8 additions & 8 deletions config/data_index_filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ services:

Pimcore\Bundle\StudioBackendBundle\DataIndex\OpenSearchFilterInterface:
class: Pimcore\Bundle\StudioBackendBundle\DataIndex\OpenSearchFilter
tags: [ 'pimcore.studio_api.filter_service' ]
tags: [ 'pimcore.studio_backend.filter_service' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\PageFilter:
tags: [ 'pimcore.studio_api.open_search.filter' ]
tags: [ 'pimcore.studio_backend.open_search.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\PageSizeFilter:
tags: [ 'pimcore.studio_api.open_search.filter' ]
tags: [ 'pimcore.studio_backend.open_search.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\ExcludeFolderFilter:
tags: [ 'pimcore.studio_api.open_search.filter' ]
tags: [ 'pimcore.studio_backend.open_search.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\IdSearchFilter:
tags: [ 'pimcore.studio_api.open_search.filter' ]
tags: [ 'pimcore.studio_backend.open_search.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\ParentIdFilter:
tags: [ 'pimcore.studio_api.open_search.filter' ]
tags: [ 'pimcore.studio_backend.open_search.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\PathFilter:
tags: [ 'pimcore.studio_api.open_search.filter' ]
tags: [ 'pimcore.studio_backend.open_search.filter' ]

# DataObject
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\ClassNameFilter:
tags: [ 'pimcore.studio_api.open_search.data_object.filter' ]
tags: [ 'pimcore.studio_backend.open_search.data_object.filter' ]
14 changes: 14 additions & 0 deletions config/updater.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Pimcore\Bundle\StudioBackendBundle\Updater\Service\AdapterLoaderInterface:
class: Pimcore\Bundle\StudioBackendBundle\Updater\Service\Loader\TaggedIteratorAdapter

Pimcore\Bundle\StudioBackendBundle\Updater\Service\UpdateServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Updater\Service\UpdateService

Pimcore\Bundle\StudioBackendBundle\Updater\Adapter\PropertiesAdapter:
tags : ['pimcore.studio_backend.update_adapter']
48 changes: 48 additions & 0 deletions src/Asset/Attributes/Request/UpdateAssetRequestBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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\Asset\Attributes\Request;

use Attribute;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\Property\Attributes\Property\UpdateElementProperties;

/**
* @internal
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class UpdateAssetRequestBody extends RequestBody
{
public function __construct()
{
parent::__construct(
required: true,
content: new JsonContent(
properties: [
new Property('data',
properties: [
new UpdateElementProperties(),
],
type: 'object',
),
],
type: 'object',
),
);
}
}
75 changes: 75 additions & 0 deletions src/Asset/Controller/UpdateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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\Asset\Controller;

use OpenApi\Attributes\Put;
use Pimcore\Bundle\StudioBackendBundle\Asset\Attributes\Request\UpdateAssetRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Asset\Attributes\Response\Content\OneOfAssetJson;
use Pimcore\Bundle\StudioBackendBundle\Asset\Request\UpdateAsset;
use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Updater\Service\UpdateServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class UpdateController extends AbstractApiController
{
public function __construct(
SerializerInterface $serializer,
private readonly AssetServiceInterface $assetService,
private readonly UpdateServiceInterface $updateService,
) {
parent::__construct($serializer);
}

#[Route('/assets/{id}', name: 'pimcore_studio_api_update_asset', methods: ['PUT'])]
//#[IsGranted('STUDIO_API')]
//#[IsGranted(UserPermissions::ASSETS->value)]
#[Put(
path: self::API_PATH . '/assets/{id}',
operationId: 'updateAssetById',
description: 'Update assets by id',
summary: 'Update asset',
security: self::SECURITY_SCHEME,
tags: [Tags::Assets->name]
)]
#[IdParameter(type: 'asset')]
#[UpdateAssetRequestBody]
#[SuccessResponse(
description: 'One of asset types',
content: new OneOfAssetJson()
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND,
])]
public function updateAsset(int $id, #[MapRequestPayload] UpdateAsset $updateAsset): JsonResponse
{
$this->updateService->update('asset', $id, $updateAsset->getData());
return $this->jsonResponse($this->assetService->getAsset($id));
}
}
34 changes: 34 additions & 0 deletions src/Asset/Request/UpdateAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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\Asset\Request;

/**
* @internal
*/
final readonly class UpdateAsset
{
public function __construct(
private array $data
)
{
}

public function getData(): array
{
return $this->data;
}
}
8 changes: 4 additions & 4 deletions src/DataIndex/Filter/Loader/TaggedIteratorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
*/
final class TaggedIteratorAdapter implements FilterLoaderInterface
{
public const FILTER_TAG = 'pimcore.studio_api.open_search.filter';
public const FILTER_TAG = 'pimcore.studio_backend.open_search.filter';

public const FILTER_ASSET_TAG = 'pimcore.studio_api.open_search.asset.filter';
public const FILTER_ASSET_TAG = 'pimcore.studio_backend.open_search.asset.filter';

public const FILTER_DATA_OBJECT_TAG = 'pimcore.studio_api.open_search.data_object.filter';
public const FILTER_DATA_OBJECT_TAG = 'pimcore.studio_backend.open_search.data_object.filter';

public const FILTER_DOCUMENT_TAG = 'pimcore.studio_api.open_search.document.filter';
public const FILTER_DOCUMENT_TAG = 'pimcore.studio_backend.open_search.document.filter';

public function __construct(
#[TaggedIterator(self::FILTER_TAG)]
Expand Down
49 changes: 49 additions & 0 deletions src/DependencyInjection/CompilerPass/UpdateAdapterPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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\DependencyInjection\CompilerPass;

use Pimcore\Bundle\StudioBackendBundle\Exception\MustImplementInterfaceException;
use Pimcore\Bundle\StudioBackendBundle\Updater\Adapter\UpdateAdapterInterface;
use Pimcore\Bundle\StudioBackendBundle\Updater\Service\Loader\TaggedIteratorAdapter;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\MustImplementInterfaceTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @internal
*/
final class UpdateAdapterPass implements CompilerPassInterface
{
use MustImplementInterfaceTrait;

/**
* @throws MustImplementInterfaceException
*/
public function process(ContainerBuilder $container): void
{
$taggedServices = array_keys(
[
... $container->findTaggedServiceIds(TaggedIteratorAdapter::ADAPTER_TAG),

]
);

foreach ($taggedServices as $environmentType) {
$this->checkInterface($environmentType, UpdateAdapterInterface::class);
}
}
}
1 change: 1 addition & 0 deletions src/DependencyInjection/PimcoreStudioBackendExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('services.yaml');
$loader->load('settings.yaml');
$loader->load('translation.yaml');
$loader->load('updater.yaml');
$loader->load('versions.yaml');

$definition = $container->getDefinition(TokenServiceInterface::class);
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/Service/Loader/TaggedIteratorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
final class TaggedIteratorAdapter implements FilterServiceLoaderInterface
{
public const FILTER_SERVICE_TAG = 'pimcore.studio_api.filter_service';
public const FILTER_SERVICE_TAG = 'pimcore.studio_backend.filter_service';

public function __construct(
#[TaggedIterator(self::FILTER_SERVICE_TAG)]
Expand Down
2 changes: 2 additions & 0 deletions src/PimcoreStudioBackendBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Pimcore\Bundle\StaticResolverBundle\PimcoreStaticResolverBundle;
use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\FilterPass;
use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\SettingsProviderPass;
use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\UpdateAdapterPass;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\Extension\Bundle\Installer\InstallerInterface;
use Pimcore\HttpKernel\Bundle\DependentBundleInterface;
Expand Down Expand Up @@ -65,6 +66,7 @@ public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new FilterPass());
$container->addCompilerPass(new SettingsProviderPass());
$container->addCompilerPass(new UpdateAdapterPass());
}

public static function registerDependentBundles(BundleCollection $collection): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Property\Attributes\Request;
namespace Pimcore\Bundle\StudioBackendBundle\Property\Attributes\Property;

use Attribute;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Content\ItemsJson;
use OpenApi\Attributes\Items;
use OpenApi\Attributes\Property;
use Pimcore\Bundle\StudioBackendBundle\Property\Schema\UpdateElementProperty;

#[Attribute(Attribute::TARGET_METHOD)]
final class ElementPropertyRequestBody extends RequestBody
/**
* @internal
*/
final class UpdateElementProperties extends Property
{
public function __construct()
{
parent::__construct(
required: true,
content: new ItemsJson(UpdateElementProperty::class)
'properties',
type: 'array',
items: new Items(ref: UpdateElementProperty::class),
nullable: true,
);
}
}
Loading

0 comments on commit 0bb0619

Please sign in to comment.