vendor/store.shopware.com/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('shopware6.xml');
  36.         $loader->load('shopware63.xml');
  37.         $loader->load('subscriber.xml');
  38.         $loader->load('writer.xml');
  39.         $loader->load('dataProvider.xml');
  40.     }
  41.     public function rebuildContainer(): bool
  42.     {
  43.         return false;
  44.     }
  45.     /**
  46.      * {@inheritdoc}
  47.      */
  48.     public function getMigrationNamespace(): string
  49.     {
  50.         return $this->getNamespace() . '\Core\Migration';
  51.     }
  52.     /**
  53.      * {@inheritdoc}
  54.      */
  55.     public function postInstall(InstallContext $installContext): void
  56.     {
  57.         /** @var Connection $connection */
  58.         $connection $this->container->get(Connection::class);
  59.         $now = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);
  60.         $connection->beginTransaction();
  61.         try {
  62.             $connection->insert('swag_migration_general_setting', [
  63.                 'id' => Uuid::randomBytes(),
  64.                 'created_at' => $now,
  65.             ]);
  66.             $connection->commit();
  67.         } catch (DBALException $e) {
  68.             $connection->rollBack();
  69.             throw $e;
  70.         }
  71.     }
  72.     /**
  73.      * {@inheritdoc}
  74.      */
  75.     public function uninstall(UninstallContext $context): void
  76.     {
  77.         if ($context->keepUserData()) {
  78.             parent::uninstall($context);
  79.             return;
  80.         }
  81.         /** @var Connection $connection */
  82.         $connection $this->container->get(Connection::class);
  83.         $connection->exec('
  84. DROP TABLE IF EXISTS swag_migration_general_setting;
  85. DROP TABLE IF EXISTS swag_migration_data;
  86. DROP TABLE IF EXISTS swag_migration_mapping;
  87. DROP TABLE IF EXISTS swag_migration_logging;
  88. DROP TABLE IF EXISTS swag_migration_media_file;
  89. DROP TABLE IF EXISTS swag_migration_run;
  90. DROP TABLE IF EXISTS swag_migration_connection;
  91. ');
  92.         parent::uninstall($context);
  93.     }
  94. }