custom/plugins/WbfkVatIdValidation/src/WbfkVatIdValidation.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Wbfk\VatIdValidation;
  4. use Doctrine\DBAL\Connection;
  5. use Doctrine\DBAL\Exception;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  7. use Shopware\Core\Framework\Plugin;
  8. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  11. use Wbfk\VatIdValidation\Helper\InstallHelper;
  12. class WbfkVatIdValidation extends Plugin
  13. {
  14.     public function install(InstallContext $installContext): void
  15.     {
  16.         parent::install($installContext);
  17.         $this->upsertCustomFields($installContext);
  18.     }
  19.     public function update(UpdateContext $updateContext): void
  20.     {
  21.         parent::update($updateContext);
  22.         $this->upsertCustomFields($updateContext);
  23.     }
  24.     /**
  25.      * @throws Exception
  26.      */
  27.     public function uninstall(UninstallContext $uninstallContext): void
  28.     {
  29.         parent::uninstall($uninstallContext);
  30.         if ($uninstallContext->keepUserData()) {
  31.             return;
  32.         }
  33.         /** @var Connection $connection */
  34.         $connection $this->container->get(Connection::class);
  35.         $connection->executeStatement('DROP TABLE IF EXISTS `wbfk_vat_id_logging`');
  36.     }
  37.     private function upsertCustomFields(InstallContext $updateContext): void
  38.     {
  39.         /** @var EntityRepository $customFieldSetRepository */
  40.         $customFieldSetRepository $this->container->get(
  41.             'custom_field_set.repository'
  42.         );
  43.         InstallHelper::upsertFieldSet(
  44.             $updateContext,
  45.             $customFieldSetRepository
  46.         );
  47.     }
  48. }