custom/plugins/KilbShopwareProductDesigner/src/KilbShopwareProductDesigner.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Kilb\KilbShopwareProductDesigner;
  3. use Doctrine\DBAL\Connection;
  4. use Doctrine\DBAL\DBALException;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
  8. require_once dirname(__DIR__) . '/vendor/autoload.php';
  9. }
  10. class KilbShopwareProductDesigner extends Plugin
  11. {
  12.     /**
  13.      * @param UninstallContext $uninstallContext
  14.      * @throws DBALException
  15.      */
  16.     public function uninstall(UninstallContext $uninstallContext): void
  17.     {
  18.         if (false === $uninstallContext->keepUserData()) {
  19.             $this->dropDatabaseTables();
  20.             $this->removeConfigurationValues();
  21.         }
  22.         parent::uninstall($uninstallContext);
  23.     }
  24.     /**
  25.      * @return void
  26.      * @throws DBALException
  27.      */
  28.     private function dropDatabaseTables(): void
  29.     {
  30.         $this->getDatabaseConnection()->exec('DROP TABLE IF EXISTS `product_designer_design`');
  31.         $this->getDatabaseConnection()->exec('DROP TABLE IF EXISTS `product_designer_design_group`');
  32.         $this->getDatabaseConnection()->exec('DROP TABLE IF EXISTS `product_designer_configuration`');
  33.     }
  34.     /**
  35.      * @return void
  36.      * @throws DBALException
  37.      */
  38.     private function removeConfigurationValues(): void
  39.     {
  40.         $sql sprintf(
  41.             'DELETE FROM system_config WHERE configuration_key LIKE \'%s.%%\'',
  42.             Constants::PLUGIN_NAME
  43.         );
  44.         $this->getDatabaseConnection()->exec($sql);
  45.     }
  46.     /**
  47.      * @return Connection
  48.      */
  49.     private function getDatabaseConnection(): Connection
  50.     {
  51.         return $this->container->get(Connection::class);
  52.     }
  53. }