1818
1919use Pimcore \Bundle \AdminBundle \Controller \AdminController ;
2020use Pimcore \Bundle \CoreBundle \DependencyInjection \Configuration ;
21+ use Pimcore \Cache \Symfony \CacheClearer ;
2122use Pimcore \Model \User ;
2223use Pimcore \Tool \Console ;
2324use Symfony \Component \Config \Definition \Processor ;
2829use Symfony \Component \HttpKernel \KernelInterface ;
2930use Symfony \Component \Process \Process ;
3031use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
31- use Symfony \Component \Yaml \Yaml ;
3232use Youwe \Pimcore \WorkflowGui \Repository \WorkflowRepositoryInterface ;
3333use Youwe \Pimcore \WorkflowGui \Resolver \ConfigFileResolverInterface ;
3434
@@ -37,15 +37,18 @@ class WorkflowController extends AdminController
3737 protected WorkflowRepositoryInterface $ repository ;
3838 protected ConfigFileResolverInterface $ configResolver ;
3939 protected KernelInterface $ kernel ;
40+ protected CacheClearer $ cacheClearer ;
4041
4142 public function __construct (
4243 WorkflowRepositoryInterface $ repository ,
4344 ConfigFileResolverInterface $ configFileResolver ,
44- KernelInterface $ kernel
45+ KernelInterface $ kernel ,
46+ CacheClearer $ cacheClearer
4547 ) {
4648 $ this ->repository = $ repository ;
4749 $ this ->configResolver = $ configFileResolver ;
4850 $ this ->kernel = $ kernel ;
51+ $ this ->cacheClearer = $ cacheClearer ;
4952 }
5053
5154 public function listAction (): JsonResponse
@@ -99,14 +102,11 @@ public function cloneAction(Request $request): JsonResponse
99102 ]);
100103 }
101104
102- $ configPath = $ this ->configResolver ->getConfigPath ();
103-
104- $ contents = Yaml::parseFile ($ configPath );
105- $ newWorkflow = $ contents ['pimcore ' ]['workflows ' ][$ id ];
106-
107- $ contents ['pimcore ' ]['workflows ' ][$ name ] = $ newWorkflow ;
108-
109- file_put_contents ($ configPath , Yaml::dump ($ contents , 100 ));
105+ $ this ->repository ->updateConfig (function (array $ workflows ) use ($ id , $ name ): array {
106+ $ workflows [$ name ] = $ workflows [$ id ];
107+ return $ workflows ;
108+ });
109+ $ this ->cacheClearer ->clear ($ this ->kernel ->getEnvironment ());
110110
111111 return $ this ->json (['success ' => true , 'id ' => $ name ]);
112112 }
@@ -140,17 +140,15 @@ public function saveAction(Request $request): JsonResponse
140140 return $ this ->json (['success ' => false , 'message ' => $ ex ->getMessage ()]);
141141 }
142142
143- $ configPath = $ this ->configResolver ->getConfigPath ();
144-
145- $ contents = Yaml::parseFile ($ configPath );
146-
147- if (isset ($ contents ['pimcore ' ]['workflows ' ][$ id ])) {
148- unset($ contents ['pimcore ' ]['workflows ' ][$ id ]);
149- }
150-
151- $ contents ['pimcore ' ]['workflows ' ][$ newId ] = $ newConfiguration ;
143+ $ this ->repository ->updateConfig (function (array $ workflows ) use ($ id , $ newId , $ newConfiguration ): array {
144+ if (isset ($ workflows [$ id ])) {
145+ unset($ workflows [$ id ]);
146+ }
152147
153- file_put_contents ($ configPath , Yaml::dump ($ contents , 100 ));
148+ $ workflows [$ newId ] = $ newConfiguration ;
149+ return $ workflows ;
150+ });
151+ $ this ->cacheClearer ->clear ($ this ->kernel ->getEnvironment ());
154152
155153 $ workflow = $ this ->repository ->find ($ id );
156154
@@ -163,15 +161,13 @@ public function deleteAction(Request $request): JsonResponse
163161
164162 $ id = $ request ->get ('id ' );
165163
166- $ configPath = $ this ->configResolver ->getConfigPath ();
167-
168- $ contents = Yaml::parseFile ($ configPath );
169-
170- if (isset ($ contents ['pimcore ' ]['workflows ' ][$ id ])) {
171- unset($ contents ['pimcore ' ]['workflows ' ][$ id ]);
172- }
173-
174- file_put_contents ($ configPath , Yaml::dump ($ contents , 100 ));
164+ $ this ->repository ->updateConfig (function (array $ workflows ) use ($ id ): array {
165+ if (isset ($ workflows [$ id ])) {
166+ unset($ workflows [$ id ]);
167+ }
168+ return $ workflows ;
169+ });
170+ $ this ->cacheClearer ->clear ($ this ->kernel ->getEnvironment ());
175171
176172 return $ this ->json (['success ' => true ]);
177173 }
0 commit comments