18
18
19
19
use Pimcore \Bundle \AdminBundle \Controller \AdminController ;
20
20
use Pimcore \Bundle \CoreBundle \DependencyInjection \Configuration ;
21
+ use Pimcore \Cache \Symfony \CacheClearer ;
21
22
use Pimcore \Model \User ;
22
23
use Pimcore \Tool \Console ;
23
24
use Symfony \Component \Config \Definition \Processor ;
26
27
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
27
28
use Symfony \Component \HttpKernel \KernelInterface ;
28
29
use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
29
- use Symfony \Component \Yaml \Yaml ;
30
30
use Youwe \Pimcore \WorkflowGui \Repository \WorkflowRepositoryInterface ;
31
31
use Youwe \Pimcore \WorkflowGui \Resolver \ConfigFileResolver ;
32
32
@@ -47,19 +47,27 @@ class WorkflowController extends AdminController
47
47
*/
48
48
protected $ kernel ;
49
49
50
+ /**
51
+ * @var CacheClearer
52
+ */
53
+ protected $ cacheClearer ;
54
+
50
55
/**
51
56
* @param WorkflowRepositoryInterface $repository
52
57
* @param ConfigFileResolver $configFileResolver
53
58
* @param KernelInterface $kernel
59
+ * @param CacheClearer $cacheClearer
54
60
*/
55
61
public function __construct (
56
62
WorkflowRepositoryInterface $ repository ,
57
63
ConfigFileResolver $ configFileResolver ,
58
- KernelInterface $ kernel
64
+ KernelInterface $ kernel ,
65
+ CacheClearer $ cacheClearer
59
66
) {
60
67
$ this ->repository = $ repository ;
61
68
$ this ->configResolver = $ configFileResolver ;
62
69
$ this ->kernel = $ kernel ;
70
+ $ this ->cacheClearer = $ cacheClearer ;
63
71
}
64
72
65
73
/**
@@ -122,14 +130,11 @@ public function cloneAction(Request $request)
122
130
return $ this ->json (['success ' => false , 'message ' => $ this ->trans ('workflow_gui_workflow_with_name_already_exists ' )]);
123
131
}
124
132
125
- $ configPath = $ this ->configResolver ->getConfigPath ();
126
-
127
- $ contents = Yaml::parseFile ($ configPath );
128
- $ newWorkflow = $ contents ['pimcore ' ]['workflows ' ][$ id ];
129
-
130
- $ contents ['pimcore ' ]['workflows ' ][$ name ] = $ newWorkflow ;
131
-
132
- file_put_contents ($ configPath , Yaml::dump ($ contents , 100 ));
133
+ $ this ->repository ->updateConfig (function (array $ workflows ) use ($ id , $ name ): array {
134
+ $ workflows [$ name ] = $ workflows [$ id ];
135
+ return $ workflows ;
136
+ });
137
+ $ this ->cacheClearer ->clear ($ this ->kernel ->getEnvironment ());
133
138
134
139
return $ this ->json (['success ' => true , 'id ' => $ name ]);
135
140
}
@@ -167,17 +172,15 @@ public function saveAction(Request $request)
167
172
return $ this ->json (['success ' => false , 'message ' => $ ex ->getMessage ()]);
168
173
}
169
174
170
- $ configPath = $ this ->configResolver ->getConfigPath ();
171
-
172
- $ contents = Yaml::parseFile ($ configPath );
173
-
174
- if (isset ($ contents ['pimcore ' ]['workflows ' ][$ id ])) {
175
- unset($ contents ['pimcore ' ]['workflows ' ][$ id ]);
176
- }
177
-
178
- $ contents ['pimcore ' ]['workflows ' ][$ newId ] = $ newConfiguration ;
175
+ $ this ->repository ->updateConfig (function (array $ workflows ) use ($ id , $ newId , $ newConfiguration ): array {
176
+ if (isset ($ workflows [$ id ])) {
177
+ unset($ workflows [$ id ]);
178
+ }
179
179
180
- file_put_contents ($ configPath , Yaml::dump ($ contents , 100 ));
180
+ $ workflows [$ newId ] = $ newConfiguration ;
181
+ return $ workflows ;
182
+ });
183
+ $ this ->cacheClearer ->clear ($ this ->kernel ->getEnvironment ());
181
184
182
185
$ workflow = $ this ->repository ->find ($ id );
183
186
@@ -194,15 +197,13 @@ public function deleteAction(Request $request)
194
197
195
198
$ id = $ request ->get ('id ' );
196
199
197
- $ configPath = $ this ->configResolver ->getConfigPath ();
198
-
199
- $ contents = Yaml::parseFile ($ configPath );
200
-
201
- if (isset ($ contents ['pimcore ' ]['workflows ' ][$ id ])) {
202
- unset($ contents ['pimcore ' ]['workflows ' ][$ id ]);
203
- }
204
-
205
- file_put_contents ($ configPath , Yaml::dump ($ contents , 100 ));
200
+ $ this ->repository ->updateConfig (function (array $ workflows ) use ($ id ): array {
201
+ if (isset ($ workflows [$ id ])) {
202
+ unset($ workflows [$ id ]);
203
+ }
204
+ return $ workflows ;
205
+ });
206
+ $ this ->cacheClearer ->clear ($ this ->kernel ->getEnvironment ());
206
207
207
208
return $ this ->json (['success ' => true ]);
208
209
}
0 commit comments