<?php declare(strict_types=1);
namespace NetInventors\NetiNextAdminTools;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Exception as DbalException;
use NetInventors\NetiNextAdminTools\Components\Setup;
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 Symfony\Component\DependencyInjection\ContainerInterface;
use Throwable;
class NetiNextAdminTools extends Plugin
{
/**
* @param InstallContext $installContext
*
* @throws \Throwable
*/
public function install(InstallContext $installContext): void
{
parent::install($installContext);
(new Setup($installContext, $this->container))->install();
}
/**
* @throws Throwable
*/
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext);
(new Setup($updateContext, $this->container))->update();
}
/**
* @param UninstallContext $uninstallContext
*
* @throws ConnectionException|DbalException
*/
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if ($uninstallContext->keepUserData()) {
return;
}
(new Setup($uninstallContext, $this->container))->uninstall();
/** @var Connection|null $connection */
$connection = $this->container->get(
Connection::class,
ContainerInterface::NULL_ON_INVALID_REFERENCE
);
if (null === $connection) {
return;
}
$connection->beginTransaction();
try {
$connection->executeStatement('SET FOREIGN_KEY_CHECKS=0');
$connection->executeStatement('DROP TABLE IF EXISTS `neti_admin_tools_filter`');
$connection->executeStatement('DROP TABLE IF EXISTS `neti_admin_tools_filter_role`');
$connection->executeStatement('DROP TABLE IF EXISTS `neti_admin_tools_filter_condition`');
$connection->executeStatement('SET FOREIGN_KEY_CHECKS=1');
$connection->commit();
} catch (Throwable $exception) {
$connection->rollBack();
throw $exception;
}
}
}