<?php
declare(strict_types=1);
namespace Slash\OrderExport;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Slash\OrderExport\Service\OrderExportFieldService;
class SlashOrderExport extends Plugin
{
public function install(InstallContext $installContext): void
{
/** @var Connection $connection */
$connection = $this->container->get(Connection::class);
$connection->exec("CREATE TABLE IF NOT EXISTS `slash_order_export_fields` (
`id`BINARY(16) NOT NULL,
`unique_name` VARCHAR(255) NOT NULL,
`type` INT NOT NULL,
`child_count` INT,
`parent_id` VARCHAR(255),
`after_id` VARCHAR(255),
`active` TINYINT(1) NOT NULL DEFAULT 0,
`created_at` DATE,
`updated_at` DATE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
$connection->exec("CREATE TABLE IF NOT EXISTS `slash_order_export_fields_list` (
`id`BINARY(16) NOT NULL,
`unique_name` VARCHAR(255) NOT NULL,
`type` INT NOT NULL,
`child_count` INT,
`parent_id` VARCHAR(255),
`after_id` VARCHAR(255),
`active` TINYINT(1) NOT NULL DEFAULT 0,
`created_at` DATE,
`updated_at` DATE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
}
public function activate(ActivateContext $activateContext): void
{
/** @var EntityRepository $orderExportFieldRepository */
$orderExportFieldRepository = $this->container->get('slash_order_export_fields.repository');
/** @var EntityRepository $orderExportFieldListRepository */
$orderExportFieldListRepository = $this->container->get('slash_order_export_fields_list.repository');
$criteria = new Criteria();
if ($orderExportFieldRepository->search($criteria, $activateContext->getContext())->getTotal() == 0) {
$orderExportFieldService = new OrderExportFieldService(
$orderExportFieldRepository
);
$orderExportFieldService->seedData($activateContext->getContext());
}
if ($orderExportFieldListRepository->search($criteria, $activateContext->getContext())->getTotal() == 0) {
$orderExportFieldService = new OrderExportFieldService(
$orderExportFieldListRepository
);
$orderExportFieldService->seedDataList($activateContext->getContext());
}
}
public function uninstall(UninstallContext $uninstallContext): void
{
/** @var Connection $connection */
$connection = $this->container->get(Connection::class);
$connection->exec("DROP TABLE IF EXISTS `slash_order_export_fields`");
$connection->exec("DROP TABLE IF EXISTS `slash_order_export_fields_list`");
}
}