<?php declare(strict_types=1);
/*
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Swag\FlowBuilderProfessional;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Swag\FlowBuilderProfessional\Core\Content\Flow\Dispatching\Action\CallWebhookAction;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
class SwagFlowBuilder extends Plugin
{
public const PLUGIN_NAME = 'SwagFlowBuilder';
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container): void
{
parent::build($container);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/Core/Content/Flow/DependencyInjection/'));
$loader->load('flow.xml');
}
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
parent::uninstall($uninstallContext);
return;
}
$this->cleanWebhookActionRelatedDatabase();
parent::uninstall($uninstallContext);
}
/**
* @throws Exception
* @throws \Doctrine\DBAL\ConnectionException
*/
public function cleanWebhookActionRelatedDatabase(): void
{
$connection = $this->container->get(Connection::class);
$connection->beginTransaction();
try {
$connection->delete('flow_sequence', [
'action_name' => CallWebhookAction::getName(),
]);
$connection->executeStatement('DROP TABLE IF EXISTS `swag_sequence_webhook_event_log`');
$connection->commit();
} catch (Exception $e) {
$connection->rollBack();
throw $e;
}
}
}