custom/plugins/SwagMigrationAssistant/SwagMigrationAssistant.php line 21

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 SwagMigrationAssistant;
  8. use Doctrine\DBAL\Connection;
  9. use Doctrine\DBAL\DBALException;
  10. use Shopware\Core\Defaults;
  11. use Shopware\Core\Framework\Plugin;
  12. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  13. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  14. use Shopware\Core\Framework\Uuid\Uuid;
  15. use Symfony\Component\Config\FileLocator;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  18. class SwagMigrationAssistant extends Plugin
  19. {
  20.     /**
  21.      * {@inheritdoc}
  22.      */
  23.     public function build(ContainerBuilder $container): void
  24.     {
  25.         parent::build($container);
  26.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  27.         $loader->load('entity.xml');
  28.         $loader->load('gateway.xml');
  29.         $loader->load('migration.xml');
  30.         $loader->load('profile.xml');
  31.         $loader->load('shopware.xml');
  32.         $loader->load('shopware54.xml');
  33.         $loader->load('shopware55.xml');
  34.         $loader->load('shopware56.xml');
  35.         $loader->load('shopware57.xml');
  36.         $loader->load('shopware6.xml');
  37.         $loader->load('shopware63.xml');
  38.         $loader->load('subscriber.xml');
  39.         $loader->load('writer.xml');
  40.         $loader->load('dataProvider.xml');
  41.     }
  42.     public function rebuildContainer(): bool
  43.     {
  44.         return false;
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     public function getMigrationNamespace(): string
  50.     {
  51.         return $this->getNamespace() . '\Core\Migration';
  52.     }
  53.     /**
  54.      * {@inheritdoc}
  55.      */
  56.     public function postInstall(InstallContext $installContext): void
  57.     {
  58.         /** @var Connection $connection */
  59.         $connection $this->container->get(Connection::class);
  60.         $now = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);
  61.         $connection->beginTransaction();
  62.         try {
  63.             $connection->insert('swag_migration_general_setting', [
  64.                 'id' => Uuid::randomBytes(),
  65.                 'created_at' => $now,
  66.             ]);
  67.             $connection->commit();
  68.         } catch (DBALException $e) {
  69.             $connection->rollBack();
  70.             throw $e;
  71.         }
  72.     }
  73.     /**
  74.      * {@inheritdoc}
  75.      */
  76.     public function uninstall(UninstallContext $context): void
  77.     {
  78.         if ($context->keepUserData()) {
  79.             parent::uninstall($context);
  80.             return;
  81.         }
  82.         /** @var Connection $connection */
  83.         $connection $this->container->get(Connection::class);
  84.         $connection->executeStatement('
  85. DROP TABLE IF EXISTS swag_migration_general_setting;
  86. DROP TABLE IF EXISTS swag_migration_data;
  87. DROP TABLE IF EXISTS swag_migration_mapping;
  88. DROP TABLE IF EXISTS swag_migration_logging;
  89. DROP TABLE IF EXISTS swag_migration_media_file;
  90. DROP TABLE IF EXISTS swag_migration_run;
  91. DROP TABLE IF EXISTS swag_migration_connection;
  92. ');
  93.         parent::uninstall($context);
  94.     }
  95. }