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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace DreiscSeoPro;
  3. use Shopware\Core\Framework\Plugin;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  6. use Symfony\Component\Config\FileLocator;
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. use Doctrine\DBAL\Connection;
  9. class DreiscSeoPro extends Plugin
  10. {
  11.     /**
  12.     * @param ContainerBuilder $container
  13.     * @throws \Exception
  14.     */
  15.     public function build(ContainerBuilder $container): void
  16.     {
  17.         parent::build($container);
  18.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/Resources/config/'));
  19.         $loader->load('dependency.injection.xml');
  20.     }
  21.     public function uninstall(UninstallContext $context): void
  22.     {
  23.         parent::uninstall($context);
  24.         if ($context->keepUserData()) {
  25.             return;
  26.         }
  27.         /** Drop the database tables */
  28.         $this->dropDatabase();
  29.         /** Delete the custom fields */
  30.         $this->deleteCustomFields();
  31.     }
  32.     private function dropDatabase(): void
  33.     {
  34.         $connection $this->container->get(Connection::class);
  35.         $connection->executeStatement('SET FOREIGN_KEY_CHECKS=0;');
  36.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_seo_redirect_import_export_log`');
  37.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_seo_redirect_import_export_file`');
  38.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_seo_setting`');
  39.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_seo_bulk_template`');
  40.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_seo_bulk`');
  41.         $connection->executeStatement('DROP TABLE IF EXISTS `dreisc_seo_redirect`');
  42.         $connection->executeStatement('SET FOREIGN_KEY_CHECKS=1;');
  43.     }
  44.     private function deleteCustomFields()
  45.     {
  46.         $connection $this->container->get(Connection::class);
  47.         $connection->executeStatement("
  48.             DELETE FROM `custom_field` WHERE `name` LIKE 'dreisc_seo_%'
  49.         ");
  50.     }
  51. }