2222use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Model \AbortActionData ;
2323use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Util \Config ;
2424use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Util \EnvironmentVariables ;
25+ use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Util \StepConfig ;
2526use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Util \Trait \HandlerProgressTrait ;
2627use Pimcore \Bundle \StudioBackendBundle \Mercure \Service \PublishServiceInterface ;
2728use Pimcore \Bundle \StudioBackendBundle \Mercure \Service \UserTopicServiceInterface ;
2829use Pimcore \Bundle \StudioBackendBundle \Util \Trait \ElementProviderTrait ;
30+ use Pimcore \Model \Element \ElementDescriptor ;
2931use Symfony \Component \Messenger \Attribute \AsMessageHandler ;
3032
3133/**
@@ -57,7 +59,7 @@ public function __invoke(RewriteRefMessage $message): void
5759 }
5860
5961 $ jobRun = $ this ->getJobRun ($ message );
60- $ validatedParameters = $ this ->validateFullParameters (
62+ $ validatedParameters = $ this ->validateJobParameters (
6163 $ message ,
6264 $ jobRun ,
6365 $ this ->userResolver ,
@@ -71,36 +73,64 @@ public function __invoke(RewriteRefMessage $message): void
7173 $ this ->abort ($ validatedParameters );
7274 }
7375
76+ $ user = $ validatedParameters ->getUser ();
7477 $ environmentVariables = $ validatedParameters ->getEnvironmentData ();
75- $ element = $ this ->getElementById (
76- $ validatedParameters ->getSubject (),
77- $ validatedParameters ->getUser (),
78- $ this ->elementService
79- );
78+ $ rewriteConfiguration = $ environmentVariables [EnvironmentVariables::REWRITE_CONFIGURATION ->value ];
79+ $ rewriteParameters = $ environmentVariables [EnvironmentVariables::REWRITE_PARAMETERS ->value ];
80+
81+ $ elementIds = $ this ->extractConfigFieldFromJobStepConfig ($ message , StepConfig::ELEMENTS_TO_REWRITE_REFERENCES ->value );
82+ $ elementType = $ this ->extractConfigFieldFromJobStepConfig ($ message , StepConfig::ELEMENT_TYPE_TO_REWRITE_REFERENCES ->value );
83+ $ totalItems = count ($ elementIds );
84+ $ stepName = $ this ->getJobStep ($ message )->getName ();
85+
86+ foreach ($ elementIds as $ elementId ) {
87+ $ element = $ this ->getElementById (
88+ new ElementDescriptor ($ elementType , $ elementId ),
89+ $ user ,
90+ $ this ->elementService ,
91+ );
92+
93+ try {
94+ $ this ->elementReferenceService ->rewriteElementReferences (
95+ $ user ,
96+ $ element ,
97+ $ rewriteConfiguration ,
98+ $ rewriteParameters ,
99+ );
100+ } catch (Exception $ exception ) {
101+ $ this ->abort ($ this ->getAbortData (
102+ Config::ELEMENT_REWRITE_REFERENCES_FAILED_MESSAGE ->value ,
103+ [
104+ 'type ' => $ element ->getType (),
105+ 'id ' => $ element ->getId (),
106+ 'message ' => $ exception ->getMessage (),
107+ ],
108+ ));
109+ }
80110
81- try {
82- $ this ->elementReferenceService ->rewriteElementReferences (
83- $ validatedParameters ->getUser (),
84- $ element ,
85- $ environmentVariables [EnvironmentVariables::REWRITE_CONFIGURATION ->value ],
86- $ environmentVariables [EnvironmentVariables::REWRITE_PARAMETERS ->value ],
111+ $ this ->updateProgress (
112+ $ this ->publishService ,
113+ $ this ->userTopicService ,
114+ $ jobRun ,
115+ $ stepName ,
116+ $ totalItems ,
117+ 100 ,
87118 );
88- } catch (Exception $ exception ) {
89- $ this ->abort ($ this ->getAbortData (
90- Config::ELEMENT_REWRITE_REFERENCES_FAILED_MESSAGE ->value ,
91- [
92- 'type ' => $ element ->getType (),
93- 'id ' => $ element ->getId (),
94- 'message ' => $ exception ->getMessage (),
95- ],
96- ));
97119 }
120+ }
98121
99- $ this ->updateProgress (
100- $ this ->publishService ,
101- $ this ->userTopicService ,
102- $ jobRun ,
103- $ this ->getJobStep ($ message )->getName ()
122+ protected function configureStep (): void
123+ {
124+ $ this ->stepConfiguration ->setRequired (StepConfig::ELEMENTS_TO_REWRITE_REFERENCES ->value );
125+ $ this ->stepConfiguration ->setAllowedTypes (
126+ StepConfig::ELEMENTS_TO_REWRITE_REFERENCES ->value ,
127+ StepConfig::CONFIG_TYPE_ARRAY ->value
128+ );
129+
130+ $ this ->stepConfiguration ->setRequired (StepConfig::ELEMENT_TYPE_TO_REWRITE_REFERENCES ->value );
131+ $ this ->stepConfiguration ->setAllowedTypes (
132+ StepConfig::ELEMENT_TYPE_TO_REWRITE_REFERENCES ->value ,
133+ StepConfig::CONFIG_TYPE_STRING ->value
104134 );
105135 }
106136}
0 commit comments