Skip to content

Commit

Permalink
Merge branch '1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Aug 6, 2021
2 parents f32b98c + 6c3b2f4 commit c8355d6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 33 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
},
"branch-alias": {
"dev-master": "2.0-dev",
"dev-1.x": "1.2-dev"
}
}
}
54 changes: 25 additions & 29 deletions src/WorkflowGui/Controller/WorkflowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Bundle\CoreBundle\DependencyInjection\Configuration;
use Pimcore\Cache\Symfony\CacheClearer;
use Pimcore\Model\User;
use Pimcore\Tool\Console;
use Symfony\Component\Config\Definition\Processor;
Expand All @@ -28,7 +29,6 @@
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Process\Process;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Yaml\Yaml;
use Youwe\Pimcore\WorkflowGui\Repository\WorkflowRepositoryInterface;
use Youwe\Pimcore\WorkflowGui\Resolver\ConfigFileResolverInterface;

Expand All @@ -37,15 +37,18 @@ class WorkflowController extends AdminController
protected WorkflowRepositoryInterface $repository;
protected ConfigFileResolverInterface $configResolver;
protected KernelInterface $kernel;
protected CacheClearer $cacheClearer;

public function __construct(
WorkflowRepositoryInterface $repository,
ConfigFileResolverInterface $configFileResolver,
KernelInterface $kernel
KernelInterface $kernel,
CacheClearer $cacheClearer
) {
$this->repository = $repository;
$this->configResolver = $configFileResolver;
$this->kernel = $kernel;
$this->cacheClearer = $cacheClearer;
}

public function listAction(): JsonResponse
Expand Down Expand Up @@ -99,14 +102,11 @@ public function cloneAction(Request $request): JsonResponse
]);
}

$configPath = $this->configResolver->getConfigPath();

$contents = Yaml::parseFile($configPath);
$newWorkflow = $contents['pimcore']['workflows'][$id];

$contents['pimcore']['workflows'][$name] = $newWorkflow;

file_put_contents($configPath, Yaml::dump($contents, 100));
$this->repository->updateConfig(function (array $workflows) use ($id, $name): array {
$workflows[$name] = $workflows[$id];
return $workflows;
});
$this->cacheClearer->clear($this->kernel->getEnvironment());

return $this->json(['success' => true, 'id' => $name]);
}
Expand Down Expand Up @@ -140,17 +140,15 @@ public function saveAction(Request $request): JsonResponse
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}

$configPath = $this->configResolver->getConfigPath();

$contents = Yaml::parseFile($configPath);

if (isset($contents['pimcore']['workflows'][$id])) {
unset($contents['pimcore']['workflows'][$id]);
}

$contents['pimcore']['workflows'][$newId] = $newConfiguration;
$this->repository->updateConfig(function (array $workflows) use ($id, $newId, $newConfiguration): array {
if (isset($workflows[$id])) {
unset($workflows[$id]);
}

file_put_contents($configPath, Yaml::dump($contents, 100));
$workflows[$newId] = $newConfiguration;
return $workflows;
});
$this->cacheClearer->clear($this->kernel->getEnvironment());

$workflow = $this->repository->find($id);

Expand All @@ -163,15 +161,13 @@ public function deleteAction(Request $request): JsonResponse

$id = $request->get('id');

$configPath = $this->configResolver->getConfigPath();

$contents = Yaml::parseFile($configPath);

if (isset($contents['pimcore']['workflows'][$id])) {
unset($contents['pimcore']['workflows'][$id]);
}

file_put_contents($configPath, Yaml::dump($contents, 100));
$this->repository->updateConfig(function (array $workflows) use ($id): array {
if (isset($workflows[$id])) {
unset($workflows[$id]);
}
return $workflows;
});
$this->cacheClearer->clear($this->kernel->getEnvironment());

return $this->json(['success' => true]);
}
Expand Down
26 changes: 23 additions & 3 deletions src/WorkflowGui/Repository/WorkflowRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ function ($key) use ($id) {
return reset($filtered);
}

public function updateConfig(callable $workflowsRewriter): void
{
$config = $this->loadConfig();
$config['pimcore']['workflows'] = $workflowsRewriter($config['pimcore']['workflows']);
$this->storeConfig($config);
}

protected function processConfiguration(): array
{
$config = Yaml::parse(
file_get_contents($this->configFileResolver->getConfigPath())
);
$config = $this->loadConfig();

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

return $config['workflows'];
}

protected function loadConfig(): array
{
return Yaml::parse(
file_get_contents($this->configFileResolver->getConfigPath())
);
}

protected function storeConfig(array $config): void
{
file_put_contents(
$this->configFileResolver->getConfigPath(),
Yaml::dump($config, 100)
);
}
}
1 change: 1 addition & 0 deletions src/WorkflowGui/Repository/WorkflowRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ interface WorkflowRepositoryInterface
{
public function findAll(): array;
public function find($id): array;
public function updateConfig(callable $workflowsRewriter): void;
}
1 change: 1 addition & 0 deletions src/WorkflowGui/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
- '@Youwe\Pimcore\WorkflowGui\Repository\WorkflowRepository'
- '@Youwe\Pimcore\WorkflowGui\Resolver\ConfigFileResolver'
- '@kernel'
- '@Pimcore\Cache\Symfony\CacheClearer'
tags:
- { name: controller.service_arguments }
calls:
Expand Down

0 comments on commit c8355d6

Please sign in to comment.