custom/plugins/IntediaDoofinderSW6/src/IntediaDoofinderSW6.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Intedia\Doofinder;
  3. use Doctrine\DBAL\Connection;
  4. use Intedia\Doofinder\Core\Content\Settings\Service\CommunicationHandler;
  5. use Intedia\Doofinder\Core\Content\Settings\Service\SettingsHandler;
  6. use Intedia\Doofinder\Core\Content\Update\Service\UpdateHandler;
  7. use Shopware\Core\Framework\Plugin;
  8. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  9. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  11. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  12. /**
  13.  * Class IntediaDoofinderSW6
  14.  * @package Intedia\Doofinder
  15.  */
  16. class IntediaDoofinderSW6 extends Plugin
  17. {
  18.     /**
  19.      * @param ActivateContext $activateContext
  20.      * @return void
  21.      */
  22.     public function activate(ActivateContext $activateContext): void
  23.     {
  24.     }
  25.     /**
  26.      * @param InstallContext $installContext
  27.      * @return void
  28.      */
  29.     public function install(InstallContext $installContext): void
  30.     {
  31.         $this->addDoofinderBaseTable();
  32.     }
  33.     /**
  34.      * @param UpdateContext $updateContext
  35.      * @return void
  36.      * @throws \Exception
  37.      */
  38.     public function update(UpdateContext $updateContext): void
  39.     {
  40.         if($updateContext->getPlugin()->isActive() === true) {
  41.             $updateHandler = new UpdateHandler(
  42.                 $this->container->get('product_export.repository'),
  43.                 $this->container->get(SettingsHandler::class),
  44.                 $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService'),
  45.                 $this->container->get('translator'),
  46.                 $this->container->get(CommunicationHandler::class)
  47.             );
  48.             switch ($updateContext->getCurrentPluginVersion()) {
  49.                 case '1.0.0':
  50.                     $updateHandler->updateDoofinderExport101();
  51.                 case '1.0.1':
  52.                 case '1.0.2':
  53.                     // Nothing
  54.                 case '1.0.3':
  55.                     // Nothing
  56.                 case '1.0.4':
  57.                     $updateHandler->updateDoofinderExport105();
  58.                 case '1.0.5':
  59.                 case '1.0.6':
  60.                 case '1.0.7':
  61.                     $updateHandler->updateDoofinderExport108();
  62.                 case '1.0.8':
  63.                     $updateHandler->updateDoofinderExport109();
  64.                 case '1.0.9':
  65.                 case '1.0.10':
  66.                 case '1.0.11':
  67.                     $updateHandler->updateDoofinderExport110();
  68.                 case '1.1.0':
  69.                 case '1.1.1':
  70.                 case '1.1.2':
  71.                 case '2.0.0':
  72.                     $this->addDoofinderBaseTable();
  73.                     $updateHandler->updateDoofinderTo200();
  74.                 case '2.1.0':
  75.                     $updateHandler->updateDoofinderExport211();
  76.                 case '2.1.1':
  77.                     // Nothing
  78.                 case '2.1.2':
  79.                     // Nothing
  80.                 case '2.1.3':
  81.                     $updateHandler->updateDoofinderExport214();
  82.                 case '2.1.4':
  83.                     // Nothing
  84.                 case '2.1.5':
  85.                     // Nothing
  86.                 case '2.1.6':
  87.                     // Nothing
  88.             }
  89.         } else {
  90.             throw new \Exception('Please activate the Plugin');
  91.         }
  92.     }
  93.     /**
  94.      * @param UninstallContext $uninstallContext
  95.      * @return void
  96.      */
  97.     public function uninstall(UninstallContext $uninstallContext): void
  98.     {
  99.         if (!$uninstallContext->keepUserData()) {
  100.             $updateHandler = new UpdateHandler(
  101.                 $this->container->get'product_export.repository'),
  102.                 new SettingsHandler(
  103.                     $this->container->get('product_export.repository'),
  104.                     $this->container->get('product_stream.repository'),
  105.                     $this->container->get('sales_channel.repository'),
  106.                     $this->container->get('sales_channel_domain.repository'),
  107.                     $this->container->get('language.repository'),
  108.                     $this->container->get('currency.repository')
  109.                 ),
  110.                 $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService'),
  111.                 $this->container->get('translator')
  112.             );
  113.             $connection $this->container->get(Connection::class);
  114.             $connection->executeUpdate('DROP TABLE IF EXISTS `intedia_doofinder_layer`');
  115.             $updateHandler->deleteDooFinderExports();
  116.             $updateHandler->deleteDooFinderStream();
  117.         }
  118.     }
  119.     private function addDoofinderBaseTable()
  120.     {
  121.         $connection $this->container->get(Connection::class);
  122.         $connection->executeUpdate('
  123.                         CREATE TABLE IF NOT EXISTS `intedia_doofinder_layer` (
  124.                           `id` binary(16) NOT NULL,
  125.                           `doofinder_channel_id` binary(16) DEFAULT NULL,
  126.                           `doofinder_hash_id` varchar(32) COLLATE utf8mb4_unicode_ci,
  127.                           `doofinder_store_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  128.                           `domain_id` binary(16) DEFAULT NULL,
  129.                           `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  130.                           `trigger` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  131.                           `status` varchar(255) DEFAULT NULL,
  132.                           `status_message` text collate utf8mb4_unicode_ci,
  133.                           `status_date` datetime DEFAULT NULL,
  134.                           `status_received_date` datetime DEFAULT NULL,
  135.                           `created_at` datetime DEFAULT NULL,
  136.                           `updated_at` datetime DEFAULT NULL,
  137.                           PRIMARY KEY (`id`)
  138.                         ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;');
  139.     }
  140. }