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

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Slash\OrderExport;
  4. use Doctrine\DBAL\Connection;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  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 Slash\OrderExport\Service\OrderExportFieldService;
  12. class SlashOrderExport extends Plugin
  13. {
  14.     public function install(InstallContext $installContext): void
  15.     {
  16.         /** @var Connection $connection */
  17.         $connection $this->container->get(Connection::class);
  18.         $connection->exec("CREATE TABLE IF NOT EXISTS `slash_order_export_fields` (
  19.         `id`BINARY(16)  NOT NULL,
  20.         `unique_name`  VARCHAR(255)    NOT NULL,
  21.         `type`  INT NOT NULL,
  22.         `child_count`   INT,
  23.         `parent_id` VARCHAR(255),
  24.         `after_id`  VARCHAR(255),
  25.         `active`    TINYINT(1)  NOT NULL    DEFAULT 0,
  26.         `created_at` DATE,
  27.         `updated_at` DATE
  28.         ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
  29.         $connection->exec("CREATE TABLE IF NOT EXISTS `slash_order_export_fields_list` (
  30.         `id`BINARY(16)  NOT NULL,
  31.         `unique_name`  VARCHAR(255)    NOT NULL,
  32.         `type`  INT NOT NULL,
  33.         `child_count`   INT,
  34.         `parent_id` VARCHAR(255),
  35.         `after_id`  VARCHAR(255),
  36.         `active`    TINYINT(1)  NOT NULL    DEFAULT 0,
  37.         `created_at` DATE,
  38.         `updated_at` DATE
  39.         ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
  40.     }
  41.     public function activate(ActivateContext $activateContext): void
  42.     {
  43.         /** @var EntityRepository $orderExportFieldRepository */
  44.         $orderExportFieldRepository $this->container->get('slash_order_export_fields.repository');
  45.         /** @var EntityRepository $orderExportFieldListRepository */
  46.         $orderExportFieldListRepository $this->container->get('slash_order_export_fields_list.repository');
  47.         $criteria = new Criteria();
  48.         if ($orderExportFieldRepository->search($criteria$activateContext->getContext())->getTotal() == 0) {
  49.             $orderExportFieldService = new OrderExportFieldService(
  50.                 $orderExportFieldRepository
  51.             );
  52.             $orderExportFieldService->seedData($activateContext->getContext());
  53.         }
  54.         if ($orderExportFieldListRepository->search($criteria$activateContext->getContext())->getTotal() == 0) {
  55.             $orderExportFieldService = new OrderExportFieldService(
  56.                 $orderExportFieldListRepository
  57.             );
  58.             $orderExportFieldService->seedDataList($activateContext->getContext());
  59.         }
  60.     }
  61.     public function uninstall(UninstallContext $uninstallContext): void
  62.     {
  63.         /** @var Connection $connection */
  64.         $connection $this->container->get(Connection::class);
  65.         $connection->exec("DROP TABLE IF EXISTS `slash_order_export_fields`");
  66.         $connection->exec("DROP TABLE IF EXISTS `slash_order_export_fields_list`");
  67.     }
  68. }