<?php
declare(strict_types=1);
namespace BartCPreemiumArticle\PremiumArticle;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
class BartCPreemiumArticle extends Plugin
{
public function uninstall(UninstallContext $context): void
{
if (!$context->keepUserData()) {
parent::uninstall($context);
$connection = $this->container->get(Connection::class);
$sql = 'DROP TABLE IF EXISTS `bartc_premium`';
if (method_exists($connection, 'executeStatement')) {
$connection->executeStatement($sql);
} else {
$connection->executeQuery($sql);
}
$this->removeConfiguration($context->getContext());
return;
}
}
private function removeConfiguration(Context $context): void
{
/** @var EntityRepositoryInterface $systemConfigRepository */
$systemConfigRepository = $this->container->get('system_config.repository');
$criteria = (new Criteria())->addFilter(new ContainsFilter('configurationKey', $this->getName() . '.config.'));
$idSearchResult = $systemConfigRepository->searchIds($criteria, $context);
$ids = array_map(static fn ($id) => ['id' => $id], $idSearchResult->getIds());
if ($ids === []) {
return;
}
$systemConfigRepository->delete($ids, $context);
}
}