<?php declare(strict_types=1);
namespace Kilb\KilbShopwareProductDesigner;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
require_once dirname(__DIR__) . '/vendor/autoload.php';
}
class KilbShopwareProductDesigner extends Plugin
{
/**
* @param UninstallContext $uninstallContext
* @throws DBALException
*/
public function uninstall(UninstallContext $uninstallContext): void
{
if (false === $uninstallContext->keepUserData()) {
$this->dropDatabaseTables();
$this->removeConfigurationValues();
}
parent::uninstall($uninstallContext);
}
/**
* @return void
* @throws DBALException
*/
private function dropDatabaseTables(): void
{
$this->getDatabaseConnection()->exec('DROP TABLE IF EXISTS `product_designer_design`');
$this->getDatabaseConnection()->exec('DROP TABLE IF EXISTS `product_designer_design_group`');
$this->getDatabaseConnection()->exec('DROP TABLE IF EXISTS `product_designer_configuration`');
}
/**
* @return void
* @throws DBALException
*/
private function removeConfigurationValues(): void
{
$sql = sprintf(
'DELETE FROM system_config WHERE configuration_key LIKE \'%s.%%\'',
Constants::PLUGIN_NAME
);
$this->getDatabaseConnection()->exec($sql);
}
/**
* @return Connection
*/
private function getDatabaseConnection(): Connection
{
return $this->container->get(Connection::class);
}
}