<?php declare(strict_types=1);
namespace Acris\Voucher;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
class AcrisVoucherCS extends Plugin
{
public function uninstall(UninstallContext $context): void
{
if ($context->keepUserData()) {
return;
}
$this->cleanupDatabase();
}
private function cleanupDatabase(): void
{
$connection = $this->container->get(Connection::class);
$connection->executeUpdate('DROP TABLE IF EXISTS acris_promotion_code_value');
$connection->executeUpdate('DROP TABLE IF EXISTS acris_promotion_code_history');
$this->removeInheritance($connection, 'promotion_individual_code', 'acrisVoucher');
$this->removeInheritance($connection, 'promotion_individual_code', 'acrisVoucherValue');
}
protected function removeInheritance(Connection $connection, string $entity, string $propertyName): void
{
$sql = str_replace(
['#table#', '#column#'],
[$entity, $propertyName],
'ALTER TABLE `#table#` DROP COLUMN `#column#`'
);
$connection->executeUpdate($sql);
}
}