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

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Iwv\IwvOrdersCsvExporterV6;
  4. if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
  5.     require_once dirname(__DIR__) . '/vendor/autoload.php';
  6. }
  7. use Doctrine\DBAL\Connection;
  8. use Shopware\Core\Framework\Plugin;
  9. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  11. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  12. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  13. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  14. use Iwv\IwvOrdersCsvExporterV6\Services\Installation\IwvCustomFieldsInstallationService;
  15. use Iwv\IwvOrdersCsvExporterV6\Services\Installation\IwvCreateDefaultCsvProfile;
  16. class IwvOrdersCsvExporterV6 extends Plugin
  17. {
  18.     /**
  19.      * @param InstallContext $installContext
  20.      * @return void
  21.      */
  22.     public function install(InstallContext $installContext): void
  23.     {
  24.         $this->getIwvCustomFieldService()->installCustomFields($installContext->getContext(), $this->isActive());
  25.         $this->getIwvCreateDefaultCsvProfileService()->createDefaultProfile($installContext->getContext(), $this->container->get(Connection::class));
  26.     }
  27.     /**
  28.      * @param UninstallContext $uninstallContext
  29.      * @return void
  30.      */
  31.     public function uninstall(UninstallContext $uninstallContext): void
  32.     {
  33.         if (!$uninstallContext->keepUserData()) {
  34.             $this->getIwvCustomFieldService()->uninstallCustomFields($uninstallContext->getContext());
  35.             $this->removeIwvOrderProfilers();
  36.         }
  37.     }
  38.     /**
  39.      * @param UpdateContext $updateContext
  40.      * @return void
  41.      */
  42.     public function update(UpdateContext $updateContext): void
  43.     {
  44.         $this->getIwvCustomFieldService()->installCustomFields($updateContext->getContext());
  45.         $this->getIwvCreateDefaultCsvProfileService()->createDefaultProfile($updateContext->getContext(), $this->container->get(Connection::class));
  46.     }
  47.     /**
  48.      * @param ActivateContext $activateContext
  49.      * @return void
  50.      */
  51.     public function activate(ActivateContext $activateContext): void
  52.     {
  53.         $this->getIwvCustomFieldService()->changeCustomFieldsState(true$activateContext->getContext());
  54.     }
  55.     /**
  56.      * @param DeactivateContext $deactivateContext
  57.      * @return void
  58.      */
  59.     public function deactivate(DeactivateContext $deactivateContext): void
  60.     {
  61.         $this->getIwvCustomFieldService()->changeCustomFieldsState(false$deactivateContext->getContext());
  62.     }
  63.     /**
  64.      * @return IwvCustomFieldsInstallationService
  65.      */
  66.     protected function getIwvCustomFieldService(): IwvCustomFieldsInstallationService
  67.     {
  68.         $customFieldsSetRepository $this->container->get('custom_field_set.repository');
  69.         return (new IwvCustomFieldsInstallationService($customFieldsSetRepository));
  70.     }
  71.     /**
  72.      * @return IwvCreateDefaultCsvProfile
  73.      */
  74.     protected function getIwvCreateDefaultCsvProfileService(): IwvCreateDefaultCsvProfile
  75.     {
  76.         //$wvOrderCsvProfileRepository = $this->container->get('iwv_order_csv_profile.repository');
  77.         return (new IwvCreateDefaultCsvProfile());
  78.     }
  79.     /**
  80.      * @return void
  81.      */
  82.     protected function removeIwvOrderProfilers(): void
  83.     {
  84.         $connection $this->container->get(Connection::class);
  85.         $connection->exec('
  86.             DROP TABLE IF EXISTS `iwv_order_csv_profile`;
  87.         ');
  88.     }
  89. }