<?php
declare(strict_types=1);
namespace Fourtwosix\Attachments;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
class FourtwosixAttachments extends Plugin
{
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
return;
}
$connection = $this->container->get(Connection::class);
$this->deleteAttachmentTranslationTable($connection);
$this->deleteAttachmentLanguageTable($connection);
$this->deleteAttachmentTable($connection);
$this->deleteColumnAttachment($connection);
}
private function deleteAttachmentTable(Connection &$connection): void
{
$sql = <<<SQL
DROP TABLE IF EXISTS `fts_attachment`;
SQL;
$connection->executeStatement($sql);
}
private function deleteAttachmentTranslationTable(Connection &$connection): void
{
$sql = <<<SQL
DROP TABLE IF EXISTS `fts_attachment_translation`;
SQL;
$connection->executeStatement($sql);
}
private function deleteAttachmentLanguageTable(Connection &$connection): void
{
$sql = <<<SQL
DROP TABLE IF EXISTS `fts_attachment_language`;
SQL;
$connection->executeStatement($sql);
}
private function deleteColumnAttachment(Connection &$connection)
{
$sql = <<<SQL
ALTER TABLE `product`
DROP COLUMN `attachments`;
SQL;
try {
$connection->executeStatement($sql);
} catch (\Throwable $th) {
//throw $th;
}
}
}