custom/plugins/CbaxModulOrderImportGalaxus/src/CbaxModulOrderImportGalaxus.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cbax\ModulOrderImportGalaxus;
  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\DataAbstractionLayer\Search\Criteria;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
  11. use Doctrine\DBAL\Connection;
  12. use Cbax\ModulExternalOrder\Core\Exception\PluginCustomError;
  13. use Cbax\ModulExternalOrder\Controller\ApiController;
  14. use Cbax\ModulExternalOrder\Bootstrap\Database as externalOrderDatabase;
  15. use Cbax\ModulExternalOrder\Components\ExternalOrderHelper;
  16. use Cbax\ModulExternalOrder\Bootstrap\Assets as externalOrderAssets;
  17. use Cbax\ModulExternalOrder\Components\DatabaseHelper;
  18. use Cbax\ModulOrderImportGalaxus\Bootstrap\Database;
  19. use Cbax\ModulOrderImportGalaxus\Bootstrap\Updater;
  20. class CbaxModulOrderImportGalaxus extends Plugin
  21. {
  22.     private function getServices() {
  23.         $services = array();
  24.         // check if external Order is installed
  25.         try {
  26.             $this->container->get(ApiController::class);
  27.         } catch (\Exception $e) {
  28.             $locale null;
  29.             if ($locale === null) {
  30.                 $locale 'de-DE';
  31.             }
  32.             $message 'cbax-galaxus.exceptionActivateExternalOrdersFirst';
  33.             $cbaxCatalog $this->container->get('translator')->getCatalogue($locale)->all('cbax');
  34.             if (!empty($cbaxCatalog[$message])) {
  35.                 $message $cbaxCatalog[$message];
  36.             }
  37.             throw new PluginCustomError($message);
  38.         }
  39.         /* Standard Services */
  40.         $services['systemConfigService'] = $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
  41.         $services['systemConfigRepository'] = $this->container->get('system_config.repository');
  42.         $services['connectionService'] =  $this->container->get(Connection::class);
  43.         $services['databaseHelper'] = new DatabaseHelper();
  44.         /* Services der Externen Bestellverwaltung */
  45.         $services['externalOrderDatabase'] = $this->container->get(externalOrderDatabase::class);
  46.         $services['externalOrderHelper'] = $this->container->get(externalOrderHelper::class);
  47.         $services['externalOrderAssets'] = $this->container->get(externalOrderAssets::class);
  48.         /* Connector spezifische Services */
  49.         $services['stateMachineRepository'] = $this->container->get('state_machine.repository');
  50.         $services['stateMachineStateRepository'] = $this->container->get('state_machine_state.repository');
  51.         return $services;
  52.     }
  53.     public function install(InstallContext $context): void
  54.     {
  55.         parent::install($context);
  56.     }
  57.     public function update(UpdateContext $context): void
  58.     {
  59.         $services $this->getServices();
  60.         $db = new Database();
  61.         $db->patch($services$context);
  62.         $updater = new Updater();
  63.         $updater->update($services$context);
  64.         parent::update($context);
  65.     }
  66.     public function postUpdate(UpdateContext $context) : void {
  67.         $services $this->getServices();
  68.         $updater = new Updater();
  69.         $updater->afterUpdateSteps($services$context);
  70.     }
  71.     public function uninstall(UninstallContext $context): void
  72.     {
  73.         if ($context->keepUserData()) {
  74.             parent::uninstall($context);
  75.             return;
  76.         }
  77.         $services $this->getServices();
  78.         // Datenbank Tabellen löschen
  79.         $db = new Database();
  80.         $db->removeDatabaseTables($services$context->getContext());
  81.         $this->removePluginConfig($services$context->getContext());
  82.         parent::uninstall($context);
  83.     }
  84.     public function activate(ActivateContext $context): void
  85.     {
  86.         $services $this->getServices();
  87.         $db = new Database();
  88.         $db->patch($services$context);
  89.         parent::activate($context);
  90.     }
  91.     public function deactivate(DeactivateContext $context): void
  92.     {
  93.         parent::deactivate($context);
  94.     }
  95.     private function removePluginConfig($services$context)
  96.     {
  97.         $systemConfigRepository $services['systemConfigRepository'];
  98.         $criteria = new Criteria();
  99.         $criteria->addFilter(new ContainsFilter('configurationKey'$this->getName() . '.config.'));
  100.         $idSearchResult $systemConfigRepository->searchIds($criteria$context);
  101.         $ids array_map(static function ($id) {
  102.             return ['id' => $id];
  103.         }, $idSearchResult->getIds());
  104.         if ($ids === []) {
  105.             return;
  106.         }
  107.         $systemConfigRepository->delete($ids$context);
  108.     }
  109. }