<?php
declare(strict_types=1);
namespace Wbfk\VatIdValidation;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
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 Wbfk\VatIdValidation\Helper\InstallHelper;
class WbfkVatIdValidation extends Plugin
{
public function install(InstallContext $installContext): void
{
parent::install($installContext);
$this->upsertCustomFields($installContext);
}
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext);
$this->upsertCustomFields($updateContext);
}
/**
* @throws Exception
*/
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if ($uninstallContext->keepUserData()) {
return;
}
/** @var Connection $connection */
$connection = $this->container->get(Connection::class);
$connection->executeStatement('DROP TABLE IF EXISTS `wbfk_vat_id_logging`');
}
private function upsertCustomFields(InstallContext $updateContext): void
{
/** @var EntityRepository $customFieldSetRepository */
$customFieldSetRepository = $this->container->get(
'custom_field_set.repository'
);
InstallHelper::upsertFieldSet(
$updateContext,
$customFieldSetRepository
);
}
}