<?php
declare(strict_types=1);
namespace Iwv\IwvOrdersCsvExporterV6;
if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
require_once dirname(__DIR__) . '/vendor/autoload.php';
}
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Iwv\IwvOrdersCsvExporterV6\Services\Installation\IwvCustomFieldsInstallationService;
use Iwv\IwvOrdersCsvExporterV6\Services\Installation\IwvCreateDefaultCsvProfile;
class IwvOrdersCsvExporterV6 extends Plugin
{
/**
* @param InstallContext $installContext
* @return void
*/
public function install(InstallContext $installContext): void
{
$this->getIwvCustomFieldService()->installCustomFields($installContext->getContext(), $this->isActive());
$this->getIwvCreateDefaultCsvProfileService()->createDefaultProfile($installContext->getContext(), $this->container->get(Connection::class));
}
/**
* @param UninstallContext $uninstallContext
* @return void
*/
public function uninstall(UninstallContext $uninstallContext): void
{
if (!$uninstallContext->keepUserData()) {
$this->getIwvCustomFieldService()->uninstallCustomFields($uninstallContext->getContext());
$this->removeIwvOrderProfilers();
}
}
/**
* @param UpdateContext $updateContext
* @return void
*/
public function update(UpdateContext $updateContext): void
{
$this->getIwvCustomFieldService()->installCustomFields($updateContext->getContext());
$this->getIwvCreateDefaultCsvProfileService()->createDefaultProfile($updateContext->getContext(), $this->container->get(Connection::class));
}
/**
* @param ActivateContext $activateContext
* @return void
*/
public function activate(ActivateContext $activateContext): void
{
$this->getIwvCustomFieldService()->changeCustomFieldsState(true, $activateContext->getContext());
}
/**
* @param DeactivateContext $deactivateContext
* @return void
*/
public function deactivate(DeactivateContext $deactivateContext): void
{
$this->getIwvCustomFieldService()->changeCustomFieldsState(false, $deactivateContext->getContext());
}
/**
* @return IwvCustomFieldsInstallationService
*/
protected function getIwvCustomFieldService(): IwvCustomFieldsInstallationService
{
$customFieldsSetRepository = $this->container->get('custom_field_set.repository');
return (new IwvCustomFieldsInstallationService($customFieldsSetRepository));
}
/**
* @return IwvCreateDefaultCsvProfile
*/
protected function getIwvCreateDefaultCsvProfileService(): IwvCreateDefaultCsvProfile
{
//$wvOrderCsvProfileRepository = $this->container->get('iwv_order_csv_profile.repository');
return (new IwvCreateDefaultCsvProfile());
}
/**
* @return void
*/
protected function removeIwvOrderProfilers(): void
{
$connection = $this->container->get(Connection::class);
$connection->exec('
DROP TABLE IF EXISTS `iwv_order_csv_profile`;
');
}
}