custom/plugins/NetiNextStoreLocator/src/NetiNextStoreLocator.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace NetInventors\NetiNextStoreLocator;
  3. use Doctrine\DBAL\Connection;
  4. use NetInventors\NetiNextStoreLocator\Components\Setup;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  9. use Symfony\Component\Config\FileLocator;
  10. use Symfony\Component\DependencyInjection\ContainerBuilder;
  11. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  12. class NetiNextStoreLocator extends Plugin
  13. {
  14.     /**
  15.      * @param InstallContext $installContext
  16.      *
  17.      * @throws \Exception
  18.      */
  19.     public function install(InstallContext $installContext): void
  20.     {
  21.         parent::install($installContext);
  22.         $setup = new Setup($this->container$installContext);
  23.         $setup->install($installContext->getContext());
  24.     }
  25.     public function uninstall(UninstallContext $uninstallContext): void
  26.     {
  27.         parent::uninstall($uninstallContext);
  28.         if (false === $uninstallContext->keepUserData()) {
  29.             $setup = new Setup($this->container$uninstallContext);
  30.             $setup->uninstall($uninstallContext->getContext());
  31.             $connection $this->container->get(Connection::class);
  32.             if (!$connection instanceof Connection) {
  33.                 return;
  34.             }
  35.             $query = <<<SQL
  36. SET foreign_key_checks=0;
  37. DROP TABLE IF EXISTS `neti_store_locator`,
  38. `neti_store_locator_contact_form`,
  39. `neti_store_locator_contact_form_translation`,
  40. `neti_store_locator_translation`,
  41. `neti_store_sales_channel`,
  42. `neti_store_tag`,
  43. `neti_business_weekday`,
  44. `neti_business_weekday_translation`,
  45. `neti_business_hour`,
  46. `neti_business_hour_translation`,
  47. `neti_store_business_hour`;
  48. SET foreign_key_checks=1;
  49. SQL;
  50.             $connection->executeQuery($query);
  51.             $query = <<<SQL
  52. DELETE FROM `media_folder` WHERE `default_folder_id` = (SELECT `id` FROM `media_default_folder` WHERE `media_default_folder`.`entity` = 'neti_store_locator');
  53. SQL;
  54.             $connection->executeStatement($query);
  55.             $query = <<<SQL
  56. DELETE FROM `media_default_folder` WHERE `entity` = 'neti_store_locator';
  57. SQL;
  58.             $connection->executeStatement($query);
  59.             $sql '
  60.                 DELETE FROM seo_url_template WHERE entity_name = "neti_store_locator"
  61.             ';
  62.             $connection->executeStatement($sql);
  63.         }
  64.         // Since it is not possible to remove the profile if an import/export was done, the uninstall method is deactivated until it is possible
  65.         // Setup::uninstallImportExportProfile($this->container, $uninstallContext->getContext());
  66.     }
  67.     public function update(UpdateContext $updateContext): void
  68.     {
  69.         parent::update($updateContext);
  70.         $setup = new Setup($this->container$updateContext);
  71.         $setup->update($updateContext->getContext());
  72.     }
  73.     public function build(ContainerBuilder $container): void
  74.     {
  75.         parent::build($container);
  76.         if (version_compare($container->getParameter('kernel.shopware_version'), '6.3.3.0''>=')) {
  77.             $loader = new XmlFileLoader(
  78.                 $container,
  79.                 new FileLocator(__DIR__ '/Resources/config/services')
  80.             );
  81.             $loader->load('business-events.xml');
  82.         }
  83.     }
  84. }