vendor/store.shopware.com/rhiemextendedregistration/src/RhiemExtendedRegistration.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace RhiemExtendedRegistration;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  8. class RhiemExtendedRegistration extends Plugin
  9. {
  10.     private array $tables = [
  11.         'rhiem_ar_so_translation',
  12.         'rhiem_ar_so',
  13.         'rhiem_ar_attribute_translation',
  14.         'rhiem_ar_attribute',
  15.         'rhiem_ar_group_translation',
  16.         'rhiem_ar_group',
  17.     ];
  18.     /**
  19.      * @param InstallContext $installContext
  20.      */
  21.     public function install(InstallContext $installContext): void
  22.     {
  23.         parent::install($installContext);
  24.     }
  25.     /**
  26.      * @param UpdateContext $updateContext
  27.      */
  28.     public function update(UpdateContext $updateContext): void
  29.     {
  30.         $updateContext->setAutoMigrate(false);
  31.         $migrationCollection $updateContext->getMigrationCollection();
  32.         if (\version_compare($updateContext->getCurrentPluginVersion(), '2.0.0''<')) {
  33.             $migrationCollection->migrateInPlace(1623051960);
  34.             $migrationCollection->migrateDestructiveInPlace(1623051960);
  35.         }
  36.         if (\version_compare($updateContext->getCurrentPluginVersion(), '2.0.0''ge') &&
  37.             \version_compare($updateContext->getCurrentPluginVersion(), '2.0.2''<')) {
  38.             $migrationCollection->migrateInPlace(1624023259);
  39.             $migrationCollection->migrateDestructiveInPlace(1624023259);
  40.         }
  41.     }
  42.     /**
  43.      * @param UninstallContext $uninstallContext
  44.      *
  45.      * @throws \Doctrine\DBAL\Exception
  46.      */
  47.     public function uninstall(UninstallContext $uninstallContext): void
  48.     {
  49.         parent::uninstall($uninstallContext);
  50.         if ($uninstallContext->keepUserData()) {
  51.             return;
  52.         }
  53.         /** @var Connection $connection */
  54.         $connection $this->container->get(Connection::class);
  55.         $this->deleteCustomFields($connection);
  56.         foreach($this->tables as $tableName) {
  57.             $connection->executeStatement('DROP TABLE IF EXISTS `' $tableName '`');
  58.         }
  59.     }
  60.     /**
  61.      * @param Connection $connection
  62.      *
  63.      * @throws \Doctrine\DBAL\Exception
  64.      */
  65.     private function deleteCustomFields(Connection $connection): void
  66.     {
  67.         $sql "UPDATE customer
  68.                     SET custom_fields = JSON_REMOVE(custom_fields, '$.Rhiem_Additional_Registration_Fields_Personal')
  69.                     WHERE custom_fields IS NOT NULL";
  70.         $connection->executeStatement($sql);
  71.     }
  72. }