-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Task] Saving strategy for elements (#78)
* 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
Showing
26 changed files
with
526 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/DependencyInjection/CompilerPass/UpdateAdapterPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.