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

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