custom/plugins/ApplifactionVisualDocumentEditor/src/ApplifactionVisualDocumentEditor.php line 26

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) Applifaction LLC. All rights reserved.
  4.  * This file is part of software that is released under a proprietary license.
  5.  * You must not copy, modify, distribute, make publicly available, or execute
  6.  * its contents or parts thereof without express permission by the copyright
  7.  * holder, unless otherwise permitted by law.
  8.  */
  9. declare(strict_types=1);
  10. namespace Applifaction\DragNDropDocumentEditor;
  11. use Doctrine\DBAL\Connection;
  12. use Shopware\Core\Framework\Plugin;
  13. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  14. use Exception;
  15. use Applifaction\DragNDropDocumentEditor\Compatibility\DependencyLoader;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
  18. use Symfony\Component\Filesystem\Filesystem;
  19. use Shopware\Core\Kernel;
  20. use Symfony\Component\DependencyInjection\Container;
  21. class ApplifactionVisualDocumentEditor extends Plugin
  22. {
  23.     /**
  24.      * @param ContainerBuilder $container
  25.      * @throws Exception
  26.      */
  27.     public function build(ContainerBuilder $container): void
  28.     {
  29.         parent::build($container);
  30.         $this->container $container;
  31.         # load the dependencies that are compatible
  32.         # with our current shopware version
  33.         $loader = new DependencyLoader($this->container);
  34.         $loader->loadServices();
  35.     }
  36.     /**
  37.      * @param RoutingConfigurator $routes
  38.      * @param string $environment
  39.      * @return void
  40.      */
  41.     public function configureRoutes(RoutingConfigurator $routesstring $environment): void
  42.     {
  43.         if (!$this->isActive()) {
  44.             return;
  45.         }
  46.         /** @var Container $container */
  47.         $container $this->container;
  48.         $loader = new DependencyLoader($container);
  49.         $routeDir $loader->getRoutesPath($this->getPath());
  50.         $fileSystem = new Filesystem();
  51.         if ($fileSystem->exists($routeDir)) {
  52.             $routes->import($routeDir '/{routes}/*' Kernel::CONFIG_EXTS'glob');
  53.             $routes->import($routeDir '/{routes}/' $environment '/**/*' Kernel::CONFIG_EXTS'glob');
  54.             $routes->import($routeDir '/{routes}' Kernel::CONFIG_EXTS'glob');
  55.             $routes->import($routeDir '/{routes}_' $environment Kernel::CONFIG_EXTS'glob');
  56.         }
  57.     }
  58.     public function uninstall(UninstallContext $uninstallContext): void
  59.     {
  60.         parent::uninstall($uninstallContext);
  61.         if ($uninstallContext->keepUserData()) {
  62.             return;
  63.         }
  64.         $this->dropTables();
  65.     }
  66.     private function dropTables(): void
  67.     {
  68.         $connection $this->container->get(Connection::class);
  69.         $connection->executeUpdate('DROP TABLE IF EXISTS `dde_editor_state_translation`');
  70.         $connection->executeUpdate('DROP TABLE IF EXISTS `dde_editor_state`');
  71.         $connection->executeUpdate('DROP TABLE IF EXISTS `dde_custom_preset`');
  72.     }
  73. }