custom/plugins/fourtwosixattachments/src/FourtwosixAttachments.php line 11

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Fourtwosix\Attachments;
  4. use Doctrine\DBAL\Connection;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. class FourtwosixAttachments extends Plugin
  8. {
  9.     public function uninstall(UninstallContext $uninstallContext): void
  10.     {
  11.         if ($uninstallContext->keepUserData()) {
  12.             return;
  13.         }
  14.         $connection $this->container->get(Connection::class);
  15.         $this->deleteAttachmentTranslationTable($connection);
  16.         $this->deleteAttachmentLanguageTable($connection);
  17.         $this->deleteAttachmentTable($connection);
  18.         $this->deleteColumnAttachment($connection);
  19.     }
  20.     private function deleteAttachmentTable(Connection &$connection): void
  21.     {
  22.         $sql = <<<SQL
  23.             DROP TABLE IF EXISTS `fts_attachment`;
  24.         SQL;
  25.         $connection->executeStatement($sql);
  26.     }
  27.     private function deleteAttachmentTranslationTable(Connection &$connection): void
  28.     {
  29.         $sql = <<<SQL
  30.             DROP TABLE IF EXISTS `fts_attachment_translation`;
  31.         SQL;
  32.         $connection->executeStatement($sql);
  33.     }
  34.     private function deleteAttachmentLanguageTable(Connection &$connection): void
  35.     {
  36.         $sql = <<<SQL
  37.             DROP TABLE IF EXISTS `fts_attachment_language`;
  38.         SQL;
  39.         $connection->executeStatement($sql);
  40.     }
  41.     private function deleteColumnAttachment(Connection &$connection)
  42.     {
  43.         $sql = <<<SQL
  44.             ALTER TABLE `product`
  45.             DROP COLUMN `attachments`;
  46.         SQL;
  47.         try {
  48.             $connection->executeStatement($sql);
  49.         } catch (\Throwable $th) {
  50.             //throw $th;
  51.         }
  52.     }
  53. }