<?php
declare(strict_types=1);
namespace Fourtwosix\PaymentSurcharge;
use Doctrine\DBAL\Connection;
use Fourtwosix\PaymentSurcharge\Core\Content\PaymentCost\Aggregate\PaymentCostTranslation\PaymentCostTranslationDefinition;
use Fourtwosix\PaymentSurcharge\Core\Content\PaymentCost\PaymentCostDefinition;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
class FourtwosixPaymentSurcharge extends Plugin
{
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
parent::uninstall($uninstallContext);
return;
}
$connection = $this->container->get(Connection::class);
$this->dropPaymentCostTranslation($connection);
$this->dropPaymentCost($connection);
}
private function dropPaymentCostTranslation(Connection $connection): void
{
$table = PaymentCostTranslationDefinition::ENTITY_NAME;
$this->dropTable($connection, $table);
}
private function dropPaymentCost(Connection $connection): void
{
$table = PaymentCostDefinition::ENTITY_NAME;
$this->dropTable($connection, $table);
}
private function dropTable(Connection $connection, string $table)
{
$sql = <<<SQL
DROP TABLE IF EXISTS $table;
SQL;
$connection->executeStatement($sql);
}
}