custom/plugins/CbaxModulCrossSelling/src/CbaxModulCrossSelling.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cbax\ModulCrossSelling;
  3. use Doctrine\DBAL\Connection;
  4. //use Shopware\Core\Framework\Context;
  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\ActivateContext;
  9. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  10. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  13. use Cbax\ModulCrossSelling\Bootstrap\Uninstaller;
  14. class CbaxModulCrossSelling extends Plugin
  15. {
  16.     const MODUL_NAME 'CbaxModulCrossSelling';
  17.     public function install(InstallContext $context): void
  18.     {
  19.         parent::install($context);
  20.     }
  21.     public function uninstall(UninstallContext $context): void
  22.     {
  23.         if ($context->keepUserData()) {
  24.             parent::uninstall($context);
  25.             return;
  26.         }
  27.         $services $this->getServices();
  28.         // Datenbank Tabellen löschen
  29.         $db = new Uninstaller();
  30.         $db->removeDatabaseTables($services);
  31.         $this->removePluginConfig($services$context->getContext());
  32.         parent::uninstall($context);
  33.     }
  34.     public function activate(ActivateContext $context): void
  35.     {
  36.         parent::activate($context);
  37.     }
  38.     public function deactivate(DeactivateContext $context): void
  39.     {
  40.         parent::deactivate($context);
  41.     }
  42.     public function update(UpdateContext $context): void
  43.     {
  44.         parent::update($context);
  45.     }
  46.     private function removePluginConfig($services$context)
  47.     {
  48.         $systemConfigRepository $services['systemConfigRepository'];
  49.         $criteria = new Criteria();
  50.         $criteria->addFilter(new ContainsFilter('configurationKey'$this->getName() . '.config.'));
  51.         $idSearchResult $systemConfigRepository->searchIds($criteria$context);
  52.         $ids array_map(static function ($id) {
  53.             return ['id' => $id];
  54.         }, $idSearchResult->getIds());
  55.         if ($ids === []) {
  56.             return;
  57.         }
  58.         $systemConfigRepository->delete($ids$context);
  59.     }
  60.     private function getServices() {
  61.         $services = array();
  62.         /* Standard Services */
  63.         $services['systemConfigService'] = $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
  64.         $services['systemConfigRepository'] = $this->container->get('system_config.repository');
  65.         $services['connectionService'] =  $this->container->get(Connection::class);
  66.         return $services;
  67.     }
  68. }