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

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