Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"coreshop/pimcore-bundle": "^4.0",
"coreshop/resource-bundle": "^4.0",
"coreshop/rule-bundle": "^4.0",
"elements/process-manager-bundle": "^5.0",
"jms/serializer": "^3.17",
"league/csv": "^9.7",
"nyholm/psr7": "^1.5",
Expand Down
10 changes: 10 additions & 0 deletions src/DataDefinitionsBundle/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ protected function configure(): void
InputOption::VALUE_REQUIRED,
'JSON Encoded Params',
)
->addOption(
'monitoring-item-id',
null,
InputOption::VALUE_REQUIRED,
'Contains the monitoring item for Elements ProcessManager if executed via the Pimcore backend'
)
;
}

Expand All @@ -85,6 +91,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$params['userId'] = 0;
}

if ($input->getOption('monitoring-item-id')) {
$params['monitoringItemId'] = $input->getOption('monitoring-item-id');
}

$definition = null;

try {
Expand Down
2 changes: 2 additions & 0 deletions src/DataDefinitionsBundle/DataDefinitionsBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use CoreShop\Bundle\ResourceBundle\CoreShopResourceBundle;
use CoreShop\Bundle\RuleBundle\CoreShopRuleBundle;
use Instride\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\CleanerRegistryCompilerPass;
use Instride\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ElementsProcessManagerCommandsValidatorPass;
use Instride\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ExportProviderRegistryCompilerPass;
use Instride\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ExportRunnerRegistryCompilerPass;
use Instride\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\FetcherRegistryCompilerPass;
Expand Down Expand Up @@ -80,6 +81,7 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new ImportRuleConditionPass());
$container->addCompilerPass(new ImportRuleActionPass());
$container->addCompilerPass(new PersisterRegistryCompilerPass());
$container->addCompilerPass(new ElementsProcessManagerCommandsValidatorPass());
}

public function getVersion(): string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Data Definitions Commercial License (DDCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) CORS GmbH (https://www.cors.gmbh) in combination with instride AG (https://instride.ch)
* @license GPLv3 and DDCL
*/

namespace Instride\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler;

use Elements\Bundle\ProcessManagerBundle\Service\CommandsValidator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class ElementsProcessManagerCommandsValidatorPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition(CommandsValidator::class)) {
return;
}

$def = $container->getDefinition(CommandsValidator::class);
$whitelist = $def->getArgument('$whiteList');

$whitelist[] = 'data-definitions:import';

$def->setArgument('$whiteList', $whitelist);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('guzzle_psr7.yml');
}

if (array_key_exists('ElementsProcessManagerBundle', $bundles)) {
$loader->load('services/elements-pm.yml');
}

$this->registerDependantBundles('coreshop', [PimcoreSimpleBackendSearchBundle::class], $container);
$this->registerPimcoreResources('data_definitions', $config['pimcore_admin'], $container);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

declare(strict_types=1);

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Data Definitions Commercial License (DDCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) CORS GmbH (https://www.cors.gmbh) in combination with instride AG (https://instride.ch)
* @license GPLv3 and DDCL
*/

namespace Instride\Bundle\DataDefinitionsBundle\ElementsProcessManager;

use Elements\Bundle\ProcessManagerBundle\Model\MonitoringItem;
use Instride\Bundle\DataDefinitionsBundle\Event\ImportDefinitionEvent;

final class ImportListener
{
public function onTotalEvent(ImportDefinitionEvent $event): void
{
$monitoringItem = $this->findMonitoringItem($event);

if (!$monitoringItem) {
return;
}

$monitoringItem->getLogger()->info('Total: ' . $event->getSubject());
$monitoringItem->setTotalSteps((int)$event->getSubject());
$monitoringItem->save();
}

public function onProgressEvent(ImportDefinitionEvent $event): void
{
$monitoringItem = $this->findMonitoringItem($event);

if (!$monitoringItem) {
return;
}

$monitoringItem->getLogger()->info('Progress: ' . $event->getSubject());
$monitoringItem->setCurrentStep($monitoringItem->getCurrentStep() + 1);
$monitoringItem->save();
}

public function onStatusEvent(ImportDefinitionEvent $event): void
{
$monitoringItem = $this->findMonitoringItem($event);

if (!$monitoringItem) {
return;
}

$monitoringItem->getLogger()->info('Status: ' . $event->getSubject());
$monitoringItem->setMessage((string)$event->getSubject());
$monitoringItem->save();
}

public function onFinishedEvent(ImportDefinitionEvent $event): void
{
$monitoringItem = $this->findMonitoringItem($event);

if (!$monitoringItem) {
return;
}

$monitoringItem->getLogger()->info('Finished: ' . $event->getSubject());
$monitoringItem->setStatus(MonitoringItem::STATUS_FINISHED);
$monitoringItem->save();
}

public function onFailureEvent(ImportDefinitionEvent $event): void
{
$monitoringItem = $this->findMonitoringItem($event);

if (!$monitoringItem) {
return;
}

$monitoringItem->getLogger()->error('Failed: ' . $event->getSubject());
$monitoringItem->setMessage((string)$event->getSubject());
$monitoringItem->setStatus(MonitoringItem::STATUS_FAILED);
$monitoringItem->save();
}

private function findMonitoringItem(ImportDefinitionEvent $event): ?MonitoringItem
{
if (!isset($event->getOptions()['monitoringItemId'])) {
return null;
}

$monitoringItemId = (int)$event->getOptions()['monitoringItemId'];

return MonitoringItem::getById($monitoringItemId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
Instride\Bundle\DataDefinitionsBundle\ElementsProcessManager\ImportListener:
tags:
- { name: 'kernel.event_listener', event: 'data_definitions.import.total', method: 'onTotalEvent' }
- { name: 'kernel.event_listener', event: 'data_definitions.import.progress', method: 'onProgressEvent' }
- { name: 'kernel.event_listener', event: 'data_definitions.import.status', method: 'onStatusEvent' }
- { name: 'kernel.event_listener', event: 'data_definitions.import.finished', method: 'onFinishedEvent' }
- { name: 'kernel.event_listener', event: 'data_definitions.import.failure', method: 'onFailureEvent' }
5 changes: 5 additions & 0 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ class Kernel extends PimcoreKernel
{
public function registerBundlesToCollection(BundleCollection $collection): void
{
$collection->addBundle(new Pimcore\Bundle\ApplicationLoggerBundle\PimcoreApplicationLoggerBundle());
$collection->addBundle(new \Instride\Bundle\DataDefinitionsBundle\DataDefinitionsBundle());
$collection->addBundle(new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle());

if (class_exists(\Elements\Bundle\ProcessManagerBundle\ElementsProcessManagerBundle::class)) {
$collection->addBundle(new \Elements\Bundle\ProcessManagerBundle\ElementsProcessManagerBundle());
}
}

public function boot(): void
Expand Down
Loading