vendor/store.shopware.com/cbaxmodulmanufacturers/src/CbaxModulManufacturers.php line 25

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cbax\ModulManufacturers;
  3. use Doctrine\DBAL\Connection;
  4. use Symfony\Component\Config\FileLocator;
  5. use Symfony\Component\DependencyInjection\ContainerBuilder;
  6. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
  9. use Shopware\Core\Framework\Plugin;
  10. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  11. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  12. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  13. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  14. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  15. use Cbax\ModulManufacturers\Bootstrap\Attributes;
  16. use Cbax\ModulManufacturers\Bootstrap\Updater;
  17. use Cbax\ModulManufacturers\Bootstrap\Database;
  18. use Cbax\ModulManufacturers\Bootstrap\DefaultConfig;
  19. class CbaxModulManufacturers extends Plugin
  20. {
  21.     public function install(InstallContext $context): void
  22.     {
  23.         // Attribut Felder anlegen
  24.         $builder = new Attributes();
  25.         $builder->install($context$this->container);
  26.         parent::install($context);
  27.     }
  28.     public function update(UpdateContext $context): void
  29.     {
  30.         // Attribut Felder anlegen
  31.         $builder = new Attributes();
  32.         $builder->update($context$this->container);
  33.         $update = new Updater();
  34.         $update->updateScheduledTask($this->container$context);
  35.         //Default CMS Pages erstellen
  36.         $services $this->getServices();
  37.         $db = new Database($context->getContext()->getLanguageId());
  38.         $db->createDefaultManufacturersCmsPages($services$context->getContext());
  39.         $db->updateManufacturersCmsPages($services$context);
  40.         // den alten 'Topslider' updaten
  41.         $update->update($services$context);
  42.         //Default CMS Pages in config setzen
  43.         $dc = new DefaultConfig();
  44.         $dc->activate($services$context->getContext());
  45.         parent::update($context);
  46.     }
  47.     public function uninstall(UninstallContext $context): void
  48.     {
  49.         if ($context->keepUserData()) {
  50.             parent::uninstall($context);
  51.             return;
  52.         }
  53.         // Attribut Felder löschen
  54.         $builder = new Attributes();
  55.         $builder->uninstall($context$this->container);
  56.         $services $this->getServices();
  57.         $db = new Database($context->getContext()->getLanguageId());
  58.         // CMS Slots löschen
  59.         $db->deleteManufacturersCmsSlots($services$context->getContext());
  60.         // CMS Blocks löschen
  61.         $db->deleteManufacturersCmsBlocks($services$context->getContext());
  62.         // CMS Pages löschen
  63.         $db->deleteManufacturersCmsPages($services$context->getContext());
  64.         $this->removePluginConfig($context->getContext());
  65.         parent::uninstall($context);
  66.     }
  67.     public function activate(ActivateContext $context): void
  68.     {
  69.         // Attribut Felder set checken
  70.         $builder = new Attributes();
  71.         $builder->activate($context$this->container);
  72.         //Default CMS Pages erstellen
  73.         $services $this->getServices();
  74.         $db = new Database($context->getContext()->getLanguageId());
  75.         $db->createDefaultManufacturersCmsPages($services$context->getContext());
  76.         $db->updateManufacturersCmsPages($services$context);
  77.         //Default CMS Pages in config setzen
  78.         $dc = new DefaultConfig();
  79.         $dc->activate($services$context->getContext());
  80.         parent::activate($context);
  81.     }
  82.     public function deactivate(DeactivateContext $context): void
  83.     {
  84.         // Attribut Felder ausblenden
  85.         //$builder = new Attributes();
  86.         //$builder->deactivate($context, $this->container);
  87.         parent::deactivate($context);
  88.     }
  89.     private function removePluginConfig($context)
  90.     {
  91.         $systemConfigRepository $this->container->get('system_config.repository');
  92.         $criteria = new Criteria();
  93.         $criteria->addFilter(new ContainsFilter('configurationKey'$this->getName() . '.config.'));
  94.         $idSearchResult $systemConfigRepository->searchIds($criteria$context);
  95.         $ids array_map(static function ($id) {
  96.             return ['id' => $id];
  97.         }, $idSearchResult->getIds());
  98.         if ($ids === []) {
  99.             return;
  100.         }
  101.         $systemConfigRepository->delete($ids$context);
  102.     }
  103.     private function getServices() {
  104.         $services = array();
  105.         /* Standard Services */
  106.         $services['systemConfigService'] = $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
  107.         $services['connectionService'] =  $this->container->get(Connection::class);
  108.         $services['languageRepository'] = $this->container->get('language.repository');
  109.         $services['cmsPageRepository'] = $this->container->get('cms_page.repository');
  110.         $services['cmsBlockRepository'] = $this->container->get('cms_block.repository');
  111.         $services['cmsSlotRepository'] = $this->container->get('cms_slot.repository');
  112.         $services['cmsSlotTranslationRepository'] = $this->container->get('cms_slot_translation.repository');
  113.         return $services;
  114.     }
  115.     /**
  116.      * Load services.xml to add cms data resolver services
  117.      * @param ContainerBuilder $container
  118.      * @throws \Exception
  119.      */
  120.     public function build(ContainerBuilder $container): void
  121.     {
  122.         parent::build($container);
  123.         $loader = new XmlFileLoader($container, new FileLocator($this->getPath() . '/Core/Content/DependencyInjection'));
  124.         $loader->load('services.xml');
  125.     }
  126. }