custom/plugins/HbdevLegalText/src/HbdevLegalText.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Hbdev\HbdevLegalText;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  6. use Doctrine\DBAL\Connection;
  7. use Hbdev\HbdevLegalText\Traits\ConfiguredLayoutsTrait;
  8. class HbdevLegalText extends Plugin
  9. {
  10.     use ConfiguredLayoutsTrait;
  11.     public function uninstall(UninstallContext $context): void
  12.     {
  13.         parent::uninstall($context);
  14.         if ($context->keepUserData()) {
  15.             return;
  16.         }
  17.         $connection $this->container->get(Connection::class);
  18.         $configuredLayouts $this->getConfiguredLayouts($connection);
  19.         $unassignedLayouts $this->getUnassignedLayouts($connection);
  20.         // delete hbdev_config (config table)
  21.         $connection->executeUpdate('
  22.             DROP TABLE `hbdev_config`;
  23.         ');
  24.         // Delete unassigned HB layouts in shopware
  25.         $this->deleteHbdevLayouts($connection$unassignedLayouts);
  26.         if (count($configuredLayouts) === 0) {
  27.             // delete hbdev_layout (helper table)
  28.             $connection->executeUpdate('
  29.                 DROP TABLE `hbdev_layout`;
  30.             ');
  31.         }
  32.     }
  33.     /**
  34.      * Delete all HB layouts
  35.      *
  36.      * @param $connection
  37.      * @param $layouts
  38.      * @return void
  39.      */
  40.     private function deleteHbdevLayouts($connection$layouts)
  41.     {
  42.         foreach ($layouts as $layout) {
  43.             $connection->delete('cms_page', ['id' => $layout]);
  44.             $connection->delete('hbdev_layout', ['cms_page_id' => $layout]);
  45.         }
  46.     }
  47. }