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

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