Skip to content

Commit c8355d6

Browse files
committed
Merge branch '1.x'
2 parents f32b98c + 6c3b2f4 commit c8355d6

File tree

5 files changed

+50
-33
lines changed

5 files changed

+50
-33
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
},
4141
"branch-alias": {
4242
"dev-master": "2.0-dev",
43-
"dev-1.x": "1.2-dev"
4443
}
4544
}
4645
}

src/WorkflowGui/Controller/WorkflowController.php

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use Pimcore\Bundle\AdminBundle\Controller\AdminController;
2020
use Pimcore\Bundle\CoreBundle\DependencyInjection\Configuration;
21+
use Pimcore\Cache\Symfony\CacheClearer;
2122
use Pimcore\Model\User;
2223
use Pimcore\Tool\Console;
2324
use Symfony\Component\Config\Definition\Processor;
@@ -28,7 +29,6 @@
2829
use Symfony\Component\HttpKernel\KernelInterface;
2930
use Symfony\Component\Process\Process;
3031
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
31-
use Symfony\Component\Yaml\Yaml;
3232
use Youwe\Pimcore\WorkflowGui\Repository\WorkflowRepositoryInterface;
3333
use 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
}

src/WorkflowGui/Repository/WorkflowRepository.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ function ($key) use ($id) {
4949
return reset($filtered);
5050
}
5151

52+
public function updateConfig(callable $workflowsRewriter): void
53+
{
54+
$config = $this->loadConfig();
55+
$config['pimcore']['workflows'] = $workflowsRewriter($config['pimcore']['workflows']);
56+
$this->storeConfig($config);
57+
}
58+
5259
protected function processConfiguration(): array
5360
{
54-
$config = Yaml::parse(
55-
file_get_contents($this->configFileResolver->getConfigPath())
56-
);
61+
$config = $this->loadConfig();
5762

5863
$configuration = new Configuration();
5964
$processor = new Processor();
@@ -62,4 +67,19 @@ protected function processConfiguration(): array
6267

6368
return $config['workflows'];
6469
}
70+
71+
protected function loadConfig(): array
72+
{
73+
return Yaml::parse(
74+
file_get_contents($this->configFileResolver->getConfigPath())
75+
);
76+
}
77+
78+
protected function storeConfig(array $config): void
79+
{
80+
file_put_contents(
81+
$this->configFileResolver->getConfigPath(),
82+
Yaml::dump($config, 100)
83+
);
84+
}
6585
}

src/WorkflowGui/Repository/WorkflowRepositoryInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ interface WorkflowRepositoryInterface
2020
{
2121
public function findAll(): array;
2222
public function find($id): array;
23+
public function updateConfig(callable $workflowsRewriter): void;
2324
}

src/WorkflowGui/Resources/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
- '@Youwe\Pimcore\WorkflowGui\Repository\WorkflowRepository'
1616
- '@Youwe\Pimcore\WorkflowGui\Resolver\ConfigFileResolver'
1717
- '@kernel'
18+
- '@Pimcore\Cache\Symfony\CacheClearer'
1819
tags:
1920
- { name: controller.service_arguments }
2021
calls:

0 commit comments

Comments
 (0)