custom/plugins/WbfkITScope/src/WbfkITScope.php line 21

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Wbfk\ITScope;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  9. use Shopware\Core\Kernel;
  10. use Symfony\Component\Config\FileLocator;
  11. use Symfony\Component\Config\Loader\DelegatingLoader;
  12. use Symfony\Component\Config\Loader\LoaderResolver;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  15. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  16. use Wbfk\ITScope\DependencyInjection\WbfkITScopeExtension;
  17. use Wbfk\ITScope\Helper\InstallHelper;
  18. class WbfkITScope extends Plugin
  19. {
  20.     public function install(InstallContext $installContext): void
  21.     {
  22.         parent::install($installContext);
  23.         $this->upsertCustomFields($installContext);
  24.     }
  25.     public function createContainerExtension(): WbfkITScopeExtension
  26.     {
  27.         return new WbfkITScopeExtension();
  28.     }
  29.     public function build(ContainerBuilder $container): void
  30.     {
  31.         $this->buildConfig($container);
  32.         parent::build($container);
  33.     }
  34.     private function buildConfig(ContainerBuilder $container): void
  35.     {
  36.         $locator = new FileLocator('Resources/config');
  37.         $resolver = new LoaderResolver([
  38.             new YamlFileLoader($container$locator),
  39.             new GlobFileLoader($container$locator),
  40.         ]);
  41.         $configLoader = new DelegatingLoader($resolver);
  42.         $confDir $this->getPath().'/Resources/config';
  43.         $configLoader->load($confDir.'/{packages}/*'.Kernel::CONFIG_EXTS'glob');
  44.     }
  45.     public function update(UpdateContext $updateContext): void
  46.     {
  47.         parent::update($updateContext);
  48.         $this->upsertCustomFields($updateContext);
  49.     }
  50.     public function uninstall(UninstallContext $uninstallContext): void
  51.     {
  52.         if($uninstallContext->keepUserData()) {
  53.             return;
  54.         }
  55.         $connection $this->container->get(Connection::class);
  56.         $query = <<<SQL
  57.             DROP TABLE `wbfk_it_scope_product_extension`;
  58.             DROP TABLE `wbfk_it_scope_product_warehouse_extension`;
  59.             DROP TABLE wbfk_supplier_delivery_time;
  60.         SQL;
  61.         $connection->executeStatement($query);
  62.     }
  63.     private function upsertCustomFields(InstallContext $updateContext)
  64.     {
  65.         /** @var EntityRepository $customFieldSetRepository */
  66.         $customFieldSetRepository $this->container->get(
  67.             'custom_field_set.repository'
  68.         );
  69.         InstallHelper::upsertFieldSet(
  70.             $updateContext,
  71.             $customFieldSetRepository
  72.         );
  73.     }
  74. }