vendor/store.shopware.com/dreiscset/src/DreiscSet.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace DreiscSet;
  3. use DreiscSet\Core\Setup\Installer;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  6. use Symfony\Component\DependencyInjection\ContainerBuilder;
  7. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  8. use Symfony\Component\Config\FileLocator;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. use Doctrine\DBAL\Connection;
  11. class DreiscSet extends Plugin
  12. {
  13.     /**
  14.     * @param ContainerBuilder $container
  15.     * @throws \Exception
  16.     */
  17.     public function build(ContainerBuilder $container): void
  18.     {
  19.         parent::build($container);
  20.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/Resources/config/'));
  21.         $loader->load('dependency.injection.xml');
  22.     }
  23.     public function uninstall(UninstallContext $context): void
  24.     {
  25.         parent::uninstall($context);
  26.         if ($context->keepUserData()) {
  27.             return;
  28.         }
  29.         /** Drop the database tables */
  30.         $this->dropDatabase();
  31.     }
  32.     private function dropDatabase(): void
  33.     {
  34.         $connection $this->container->get(Connection::class);
  35.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_order`');
  36.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_group_item`');
  37.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_group_mapping`');
  38.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_product_group`');
  39.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_group_translation`');
  40.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_group`');
  41.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_product_extension`');
  42.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set`');
  43.     }
  44.     public function activate(ActivateContext $activateContext): void
  45.     {
  46.         parent::activate($activateContext);
  47.         /** Install the demo data, if the environment varianble DREISCHILD_TEST_SYSTEM is set  */
  48.         if(!empty(getenv('DREISCHILD_TEST_SYSTEM'))) {
  49.             /** @var Installer $installer */
  50.             $installer $this->container->get(Installer::class);
  51.             $installer->install(true);
  52.         }
  53.     }
  54. }