-
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.
* adapt list batch patch to use GEE * add missing subscriber * Apply php-cs-fixer changes --------- Co-authored-by: lukmzig <lukmzig@users.noreply.github.com>
- Loading branch information
Showing
27 changed files
with
570 additions
and
49 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
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
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
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,71 @@ | ||
<?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\Element\EventSubscriber; | ||
|
||
use Pimcore\Bundle\GenericExecutionEngineBundle\Event\JobRunStateChangedEvent; | ||
use Pimcore\Bundle\GenericExecutionEngineBundle\Model\JobRunStates; | ||
use Pimcore\Bundle\StudioBackendBundle\Element\Mercure\Events; | ||
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Service\EventSubscriberServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Jobs; | ||
use Pimcore\Bundle\StudioBackendBundle\Mercure\Schema\ExecutionEngine\Finished; | ||
use Pimcore\Bundle\StudioBackendBundle\Mercure\Service\PublishServiceInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class PatchSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private EventSubscriberServiceInterface $eventSubscriberService, | ||
private PublishServiceInterface $publishService, | ||
) { | ||
|
||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
JobRunStateChangedEvent::class => 'onStateChanged', | ||
]; | ||
} | ||
|
||
public function onStateChanged(JobRunStateChangedEvent $event): void | ||
{ | ||
if ($event->getJobName() !== Jobs::PATCH_ELEMENTS->value) { | ||
return; | ||
} | ||
|
||
match ($event->getNewState()) { | ||
JobRunStates::FINISHED->value => $this->publishService->publish( | ||
Events::PATCH_FINISHED->value, | ||
new Finished( | ||
$event->getJobRunId(), | ||
$event->getJobName(), | ||
$event->getJobRunOwnerId(), | ||
$event->getNewState() | ||
) | ||
), | ||
JobRunStates::FINISHED_WITH_ERRORS->value => $this->eventSubscriberService->handleFinishedWithErrors( | ||
$event->getJobRunId(), | ||
$event->getJobRunOwnerId(), | ||
$event->getJobName() | ||
), | ||
default => null, | ||
}; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/Element/ExecutionEngine/AutomationAction/Messenger/Handler/PatchHandler.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,101 @@ | ||
<?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\Element\ExecutionEngine\AutomationAction\Messenger\Handler; | ||
|
||
use Exception; | ||
use Pimcore\Bundle\StaticResolverBundle\Models\User\UserResolverInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Element\ExecutionEngine\AutomationAction\Messenger\Messages\PatchMessage; | ||
use Pimcore\Bundle\StudioBackendBundle\Element\Service\ElementServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\AutomationAction\AbstractHandler; | ||
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Model\AbortActionData; | ||
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Config; | ||
use Pimcore\Bundle\StudioBackendBundle\Mercure\Service\PublishServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Patcher\Service\PatchServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\HandlerProgressTrait; | ||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[AsMessageHandler] | ||
final class PatchHandler extends AbstractHandler | ||
{ | ||
use ElementProviderTrait; | ||
use HandlerProgressTrait; | ||
|
||
public function __construct( | ||
private readonly PatchServiceInterface $patchService, | ||
private readonly PublishServiceInterface $publishService, | ||
private readonly ElementServiceInterface $elementService, | ||
private readonly UserResolverInterface $userResolver, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function __invoke(PatchMessage $message): void | ||
{ | ||
$jobRun = $this->getJobRun($message); | ||
|
||
$validatedParameters = $this->validateJobParameters( | ||
$message, | ||
$jobRun, | ||
$this->userResolver, | ||
); | ||
|
||
if ($validatedParameters instanceof AbortActionData) { | ||
$this->abort($validatedParameters); | ||
} | ||
|
||
$element = $this->getElementById( | ||
$validatedParameters->getSubject(), | ||
$validatedParameters->getUser(), | ||
$this->elementService | ||
); | ||
$elementId = $element->getId(); | ||
$elementType = $this->getElementType($element); | ||
$jobEnvironmentData = $jobRun->getJob()?->getEnvironmentData(); | ||
if (!isset($jobEnvironmentData[(string)$elementId])) { | ||
$this->abort($this->getAbortData( | ||
Config::ELEMENT_PATCH_FAILED_MESSAGE->value, | ||
[ | ||
'type' => $elementType, | ||
'id' => $element->getId(), | ||
'message' => Config::NO_ELEMENT_DATA_FOUND->value, | ||
], | ||
)); | ||
} | ||
|
||
try { | ||
$this->patchService->patchElement($element, $elementType, $jobEnvironmentData[$elementId]); | ||
} catch (Exception $exception) { | ||
$this->abort($this->getAbortData( | ||
Config::ELEMENT_PATCH_FAILED_MESSAGE->value, | ||
[ | ||
'type' => $elementType, | ||
'id' => $elementId, | ||
'message' => $exception->getMessage(), | ||
], | ||
)); | ||
} | ||
|
||
$this->updateProgress($this->publishService, $jobRun, $this->getJobStep($message)->getName()); | ||
} | ||
} |
Oops, something went wrong.