1616use Exception ;
1717use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \AutomationAction \AbstractHandler ;
1818use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Util \Config ;
19+ use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Util \StepConfig ;
1920use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Util \Trait \HandlerProgressTrait ;
2021use Pimcore \Bundle \StudioBackendBundle \Mercure \Service \PublishServiceInterface ;
2122use Pimcore \Bundle \StudioBackendBundle \Mercure \Service \UserTopicServiceInterface ;
2223use Pimcore \Bundle \StudioBackendBundle \RecycleBin \ExecutionEngine \Messages \RestoreItemsMessage ;
2324use Pimcore \Bundle \StudioBackendBundle \RecycleBin \Service \RecycleBinServiceInterface ;
2425use Symfony \Component \Messenger \Attribute \AsMessageHandler ;
26+ use function count ;
2527
2628/**
2729 * @internal
@@ -35,7 +37,6 @@ public function __construct(
3537 private readonly RecycleBinServiceInterface $ recycleBinService ,
3638 private readonly PublishServiceInterface $ publishService ,
3739 private readonly UserTopicServiceInterface $ userTopicService ,
38-
3940 ) {
4041 parent ::__construct ();
4142 }
@@ -46,26 +47,44 @@ public function __construct(
4647 public function __invoke (RestoreItemsMessage $ message ): void
4748 {
4849 $ jobRun = $ this ->getJobRun ($ message );
49- if (!$ this ->shouldBeExecuted ($ jobRun ) || ! $ message -> getElement () ) {
50+ if (!$ this ->shouldBeExecuted ($ jobRun )) {
5051 return ;
5152 }
5253
53- $ id = $ message ->getElement ()->getId ();
54+ $ items = $ this ->extractConfigFieldFromJobStepConfig (
55+ $ message ,
56+ StepConfig::ITEMS_TO_RESTORE ->value
57+ );
58+ $ totalItems = count ($ items );
59+ $ stepName = $ this ->getJobStep ($ message )->getName ();
60+
61+ foreach ($ items as $ id ) {
62+ try {
63+ $ this ->recycleBinService ->restoreItem ($ id );
64+ } catch (Exception $ e ) {
65+ $ this ->abort ($ this ->getAbortData (
66+ Config::RECYCLE_BIN_RESTORE_FAILED ->value ,
67+ ['id ' => $ id , 'message ' => $ e ->getMessage ()]
68+ ));
69+ }
5470
55- try {
56- $ this ->recycleBinService ->restoreItem ($ id );
57- } catch (Exception $ e ) {
58- $ this ->abort ($ this ->getAbortData (
59- Config::RECYCLE_BIN_RESTORE_FAILED ->value ,
60- ['id ' => $ id , 'message ' => $ e ->getMessage ()]
61- ));
71+ $ this ->updateProgress (
72+ $ this ->publishService ,
73+ $ this ->userTopicService ,
74+ $ jobRun ,
75+ $ stepName ,
76+ $ totalItems ,
77+ $ totalItems ,
78+ );
6279 }
80+ }
6381
64- $ this ->updateProgress (
65- $ this ->publishService ,
66- $ this ->userTopicService ,
67- $ jobRun ,
68- $ this ->getJobStep ($ message )->getName ()
82+ protected function configureStep (): void
83+ {
84+ $ this ->stepConfiguration ->setRequired (StepConfig::ITEMS_TO_RESTORE ->value );
85+ $ this ->stepConfiguration ->setAllowedTypes (
86+ StepConfig::ITEMS_TO_RESTORE ->value ,
87+ StepConfig::CONFIG_TYPE_ARRAY ->value
6988 );
7089 }
7190}
0 commit comments