Skip to content

Commit

Permalink
extend patcher to use adapters for editable data
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmzig committed Dec 18, 2024
1 parent 8d249ee commit 6b5e127
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\UpdateBooleanProperty;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\UpdateIntegerProperty;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\UpdateObjectProperty;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\UpdateStringProperty;

/**
Expand Down Expand Up @@ -57,6 +58,7 @@ public function __construct()
new UpdateStringProperty('childrenSortBy'),
new UpdateStringProperty('childrenSortOrder'),
new UpdateBooleanProperty('published'),
new UpdateObjectProperty('editableData'),
],
type: 'object',
),
Expand Down
18 changes: 15 additions & 3 deletions src/Patcher/Service/PatchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Config;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Jobs;
use Pimcore\Bundle\StudioBackendBundle\Updater\Service\UpdateServiceInterface;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\Element\ElementDescriptor;
use Pimcore\Model\Element\ElementInterface;
use Pimcore\Model\UserInterface;
Expand All @@ -43,10 +45,11 @@
final readonly class PatchService implements PatchServiceInterface
{
public function __construct(
private SynchronousProcessingServiceInterface $synchronousProcessingService,
private JobExecutionAgentInterface $jobExecutionAgent,
private AdapterLoaderInterface $adapterLoader,
private ElementServiceInterface $elementService,
private AdapterLoaderInterface $adapterLoader
private JobExecutionAgentInterface $jobExecutionAgent,
private SynchronousProcessingServiceInterface $synchronousProcessingService,
private UpdateServiceInterface $updateService,
) {
}

Expand Down Expand Up @@ -112,6 +115,15 @@ public function patchElement(
UserInterface $user,
): void {
try {
if (isset($elementPatchData[UpdateServiceInterface::EDITABLE_DATA_KEY]) && $element instanceof Concrete) {
$this->updateService->updateEditableData(
$element,
$elementPatchData[UpdateServiceInterface::EDITABLE_DATA_KEY]
);

unset($elementPatchData[UpdateServiceInterface::EDITABLE_DATA_KEY]);
}

$adapters = $this->adapterLoader->loadAdapters($elementType);
foreach ($adapters as $adapter) {
$adapter->patch($element, $elementPatchData);
Expand Down
4 changes: 1 addition & 3 deletions src/Updater/Service/UpdateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
use ElementProviderTrait;
use ValidateFieldTypeTrait;

private const EDITABLE_DATA_KEY = 'editableData';

public function __construct(
private AdapterLoaderInterface $adapterLoader,
private DataAdapterServiceInterface $dataAdapterService,
Expand Down Expand Up @@ -74,7 +72,7 @@ public function update(string $elementType, int $id, array $data): void
/**
* @throws ElementSavingFailedException
*/
private function updateEditableData(Concrete $element, array $editableData): void
public function updateEditableData(Concrete $element, array $editableData): void
{
try {
$class = $element->getClass();
Expand Down
8 changes: 8 additions & 0 deletions src/Updater/Service/UpdateServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@

use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ElementSavingFailedException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Model\DataObject\Concrete;

/**
* @internal
*/
interface UpdateServiceInterface
{
public const EDITABLE_DATA_KEY = 'editableData';

/**
* @throws ElementSavingFailedException|NotFoundException
*/
public function update(string $elementType, int $id, array $data): void;

/**
* @throws ElementSavingFailedException
*/
public function updateEditableData(Concrete $element, array $editableData): void;
}

0 comments on commit 6b5e127

Please sign in to comment.