custom/plugins/SwagFlowBuilder/src/SwagFlowBuilder.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) shopware AG <info@shopware.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Swag\FlowBuilderProfessional;
  8. use Doctrine\DBAL\Connection;
  9. use Doctrine\DBAL\Exception;
  10. use Shopware\Core\Framework\Plugin;
  11. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  12. use Swag\FlowBuilderProfessional\Core\Content\Flow\Dispatching\Action\CallWebhookAction;
  13. use Symfony\Component\Config\FileLocator;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  16. class SwagFlowBuilder extends Plugin
  17. {
  18.     public const PLUGIN_NAME 'SwagFlowBuilder';
  19.     /**
  20.      * {@inheritdoc}
  21.      */
  22.     public function build(ContainerBuilder $container): void
  23.     {
  24.         parent::build($container);
  25.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/Core/Content/Flow/DependencyInjection/'));
  26.         $loader->load('flow.xml');
  27.     }
  28.     public function uninstall(UninstallContext $uninstallContext): void
  29.     {
  30.         if ($uninstallContext->keepUserData()) {
  31.             parent::uninstall($uninstallContext);
  32.             return;
  33.         }
  34.         $this->cleanWebhookActionRelatedDatabase();
  35.         parent::uninstall($uninstallContext);
  36.     }
  37.     /**
  38.      * @throws Exception
  39.      * @throws \Doctrine\DBAL\ConnectionException
  40.      */
  41.     public function cleanWebhookActionRelatedDatabase(): void
  42.     {
  43.         $connection $this->container->get(Connection::class);
  44.         $connection->beginTransaction();
  45.         try {
  46.             $connection->delete('flow_sequence', [
  47.                 'action_name' => CallWebhookAction::getName(),
  48.             ]);
  49.             $connection->executeStatement('DROP TABLE IF EXISTS `swag_sequence_webhook_event_log`');
  50.             $connection->commit();
  51.         } catch (Exception $e) {
  52.             $connection->rollBack();
  53.             throw $e;
  54.         }
  55.     }
  56. }