custom/static-plugins/ValCSVImport/src/ValCSVImport.php line 12

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace ValCSVImport;
  3. use Shopware\Core\Framework\Plugin;
  4. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  5. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\System\SystemConfig\SystemConfigService;
  8. use Symfony\Component\Filesystem\Filesystem;
  9. class ValCSVImport extends Plugin
  10. {
  11.     public function activate(ActivateContext $activateContext): void
  12.     {
  13.         parent::activate($activateContext);
  14.         $this->setDefaultValues();
  15.         $this->createImportDirectories();
  16.     }
  17.     public function update(UpdateContext $updateContext): void
  18.     {
  19.         parent::update($updateContext);
  20.         $this->setDefaultValues();
  21.         $this->createImportDirectories();
  22.     }
  23.     
  24.     private function createImportDirectories(): void
  25.     {
  26.         $filesystem = new Filesystem();
  27.         $basePath $this->container->getParameter('kernel.project_dir') . '/var/import/ValCSVImport/';
  28.         $directories = [
  29.             $basePath 'bauscher_import/delivery_time',
  30.             $basePath 'cent_import/delivery_time',
  31.             $basePath 'cookmax_import/delivery_time',
  32.             $basePath 'hepp_import/delivery_time',
  33.             $basePath 'schottzwi_import/delivery_time',
  34.         ];
  35.         foreach ($directories as $directory) {
  36.             if (!$filesystem->exists($directory)) {
  37.                 $filesystem->mkdir($directory0755);
  38.             }
  39.         }
  40.     }
  41.     private function setDefaultValues(): void
  42.     {
  43.         $systemConfigService $this->container->get(SystemConfigService::class);
  44.         $defaultValues = [
  45.             'ValCSVImport.config.bauscherDownloadPath' => '/bauscher_import/delivery_time',
  46.             'ValCSVImport.config.centDownloadPath' => '/cent_import/delivery_time',
  47.             'ValCSVImport.config.cookmaxDownloadPath' => '/cookmax_import/delivery_time',
  48.             'ValCSVImport.config.heppDownloadPath' => '/hepp_import/delivery_time',
  49.             'ValCSVImport.config.schottZwieselDownloadPath' => '/schottzwi_import/delivery_time',
  50.         ];
  51.         foreach ($defaultValues as $key => $value) {
  52.             if ($systemConfigService->get($key) === null) {
  53.                 $systemConfigService->set($key$value);
  54.             }
  55.         }
  56.     }
  57. }