<?php declare(strict_types=1);
namespace ValCSVImport;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\Filesystem\Filesystem;
class ValCSVImport extends Plugin
{
public function activate(ActivateContext $activateContext): void
{
parent::activate($activateContext);
$this->setDefaultValues();
$this->createImportDirectories();
}
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext);
$this->setDefaultValues();
$this->createImportDirectories();
}
private function createImportDirectories(): void
{
$filesystem = new Filesystem();
$basePath = $this->container->getParameter('kernel.project_dir') . '/var/import/ValCSVImport/';
$directories = [
$basePath . 'bauscher_import/delivery_time',
$basePath . 'cent_import/delivery_time',
$basePath . 'cookmax_import/delivery_time',
$basePath . 'hepp_import/delivery_time',
$basePath . 'schottzwi_import/delivery_time',
];
foreach ($directories as $directory) {
if (!$filesystem->exists($directory)) {
$filesystem->mkdir($directory, 0755);
}
}
}
private function setDefaultValues(): void
{
$systemConfigService = $this->container->get(SystemConfigService::class);
$defaultValues = [
'ValCSVImport.config.bauscherDownloadPath' => '/bauscher_import/delivery_time',
'ValCSVImport.config.centDownloadPath' => '/cent_import/delivery_time',
'ValCSVImport.config.cookmaxDownloadPath' => '/cookmax_import/delivery_time',
'ValCSVImport.config.heppDownloadPath' => '/hepp_import/delivery_time',
'ValCSVImport.config.schottZwieselDownloadPath' => '/schottzwi_import/delivery_time',
];
foreach ($defaultValues as $key => $value) {
if ($systemConfigService->get($key) === null) {
$systemConfigService->set($key, $value);
}
}
}
}