<?php
declare(strict_types=1);
/**
* WBFK
* Copyright © 2023 WBFK - Anselm Ruby
*
* @copyright Copyright (c) 2022, 2023 WBFK - Anselm Ruby (http://www.wbfk.at)
* @author Anselm Ruby <anselm.ruby@wbfk.at>
*/
namespace Wbfk\Jtl;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Wbfk\Jtl\Helper\InstallHelper;
class WbfkJtl extends Plugin
{
public function install(InstallContext $installContext): void
{
parent::install($installContext);
$this->upsertCustomFields($installContext->getContext());
}
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext);
$this->upsertCustomFields($updateContext->getContext());
}
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
return;
}
$this->cleanupDatabase();
$this->removeCustomFields($uninstallContext->getContext());
}
private function upsertCustomFields(Context $context): void
{
/** @var EntityRepository $customFieldSetRepository */
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
InstallHelper::upsertFieldSet($context, $customFieldSetRepository);
}
private function cleanupDatabase(): void
{
$connection = $this->container->get(Connection::class);
$connection->executeStatement('DROP TABLE IF EXISTS wbfk_jtl_order_stash');
}
private function removeCustomFields(Context $context): void
{
/** @var EntityRepository $customFieldSetRepository */
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
InstallHelper::removeFieldSet($context, $customFieldSetRepository);
}
}