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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cbax\ModulManufacturers;
  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\UpdateContext;
  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 Cbax\ModulManufacturers\Bootstrap\Attributes;
  11. use Cbax\ModulManufacturers\Bootstrap\Updater;
  12. use Cbax\ModulManufacturers\Bootstrap\Database;
  13. use Cbax\ModulManufacturers\Bootstrap\DefaultConfig;
  14. use Shopware\Core\Framework\Context;
  15. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  16. //use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  17. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
  18. class CbaxModulManufacturers extends Plugin
  19. {
  20.     public function install(InstallContext $context): void
  21.     {
  22.         // Attribut Felder anlegen
  23.         $builder = new Attributes();
  24.         $builder->install($context$this->container);
  25.         parent::install($context);
  26.     }
  27.     public function update(UpdateContext $context): void
  28.     {
  29.         // Attribut Felder anlegen
  30.         $builder = new Attributes();
  31.         $builder->update($context$this->container);
  32.         $update = new Updater();
  33.         $update->updateScheduledTask($this->container$context);
  34.         //Default CMS Pages erstellen
  35.         $services $this->getServices();
  36.         $db = new Database($context->getContext()->getLanguageId());
  37.         $db->createDefaultManufacturersCmsPages($services$context->getContext());
  38.         $db->updateManufacturersCmsPages($services$context);
  39.         //Default CMS Pages in config setzen
  40.         $dc = new DefaultConfig();
  41.         $dc->activate($services$context->getContext());
  42.         parent::update($context);
  43.     }
  44.     public function uninstall(UninstallContext $context): void
  45.     {
  46.         if ($context->keepUserData()) {
  47.             parent::uninstall($context);
  48.             return;
  49.         }
  50.         // Attribut Felder löschen
  51.         $builder = new Attributes();
  52.         $builder->uninstall($context$this->container);
  53.         //CMS Pages löschen
  54.         $services $this->getServices();
  55.         $db = new Database($context->getContext()->getLanguageId());
  56.         $db->deleteManufacturersCmsPages($services$context->getContext());
  57.         $this->removePluginConfig($context->getContext());
  58.         parent::uninstall($context);
  59.     }
  60.     public function activate(ActivateContext $context): void
  61.     {
  62.         // Attribut Felder set checken
  63.         $builder = new Attributes();
  64.         $builder->activate($context$this->container);
  65.         //Default CMS Pages erstellen
  66.         $services $this->getServices();
  67.         $db = new Database($context->getContext()->getLanguageId());
  68.         $db->createDefaultManufacturersCmsPages($services$context->getContext());
  69.         $db->updateManufacturersCmsPages($services$context);
  70.         //Default CMS Pages in config setzen
  71.         $dc = new DefaultConfig();
  72.         $dc->activate($services$context->getContext());
  73.         parent::activate($context);
  74.     }
  75.     public function deactivate(DeactivateContext $context): void
  76.     {
  77.         // Attribut Felder ausblenden
  78.         //$builder = new Attributes();
  79.         //$builder->deactivate($context, $this->container);
  80.         parent::deactivate($context);
  81.     }
  82.     private function removePluginConfig($context)
  83.     {
  84.         $systemConfigRepository $this->container->get('system_config.repository');
  85.         $criteria = new Criteria();
  86.         $criteria->addFilter(new ContainsFilter('configurationKey'$this->getName() . '.config.'));
  87.         $idSearchResult $systemConfigRepository->searchIds($criteria$context);
  88.         $ids array_map(static function ($id) {
  89.             return ['id' => $id];
  90.         }, $idSearchResult->getIds());
  91.         if ($ids === []) {
  92.             return;
  93.         }
  94.         $systemConfigRepository->delete($ids$context);
  95.     }
  96.     private function getServices() {
  97.         $services = array();
  98.         /* Standard Services */
  99.         $services['systemConfigService'] = $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
  100.         $services['connectionService'] =  $this->container->get(Connection::class);
  101.         $services['languageRepository'] = $this->container->get('language.repository');
  102.         $services['cmsPageRepository'] = $this->container->get('cms_page.repository');
  103.         $services['cmsSlotRepository'] = $this->container->get('cms_slot.repository');
  104.         return $services;
  105.     }
  106. }