custom/plugins/CbaxModulAnalytics/src/CbaxModulAnalytics.php line 20

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