custom/plugins/WbfkJtl/src/WbfkJtl.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * WBFK
  5.  * Copyright © 2023 WBFK - Anselm Ruby
  6.  *
  7.  * @copyright  Copyright (c) 2022, 2023 WBFK - Anselm Ruby (http://www.wbfk.at)
  8.  * @author     Anselm Ruby <anselm.ruby@wbfk.at>
  9.  */
  10. namespace Wbfk\Jtl;
  11. use Doctrine\DBAL\Connection;
  12. use Shopware\Core\Framework\Context;
  13. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  14. use Shopware\Core\Framework\Plugin;
  15. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  16. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  17. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  18. use Wbfk\Jtl\Helper\InstallHelper;
  19. class WbfkJtl extends Plugin
  20. {
  21.     public function install(InstallContext $installContext): void
  22.     {
  23.         parent::install($installContext);
  24.         $this->upsertCustomFields($installContext->getContext());
  25.     }
  26.     public function update(UpdateContext $updateContext): void
  27.     {
  28.         parent::update($updateContext);
  29.         $this->upsertCustomFields($updateContext->getContext());
  30.     }
  31.     public function uninstall(UninstallContext $uninstallContext): void
  32.     {
  33.         if ($uninstallContext->keepUserData()) {
  34.             return;
  35.         }
  36.         $this->cleanupDatabase();
  37.         $this->removeCustomFields($uninstallContext->getContext());
  38.     }
  39.     private function upsertCustomFields(Context $context): void
  40.     {
  41.         /** @var EntityRepository $customFieldSetRepository */
  42.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  43.         InstallHelper::upsertFieldSet($context$customFieldSetRepository);
  44.     }
  45.     private function cleanupDatabase(): void
  46.     {
  47.         $connection $this->container->get(Connection::class);
  48.         $connection->executeStatement('DROP TABLE IF EXISTS wbfk_jtl_order_stash');
  49.     }
  50.     private function removeCustomFields(Context $context): void
  51.     {
  52.         /** @var EntityRepository $customFieldSetRepository */
  53.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  54.         InstallHelper::removeFieldSet($context$customFieldSetRepository);
  55.     }
  56. }