<?php declare(strict_types=1);
namespace DreiscSet;
use DreiscSet\Core\Setup\Installer;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Doctrine\DBAL\Connection;
class DreiscSet extends Plugin
{
/**
* @param ContainerBuilder $container
* @throws \Exception
*/
public function build(ContainerBuilder $container): void
{
parent::build($container);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/Resources/config/'));
$loader->load('dependency.injection.xml');
}
public function uninstall(UninstallContext $context): void
{
parent::uninstall($context);
if ($context->keepUserData()) {
return;
}
/** Drop the database tables */
$this->dropDatabase();
}
private function dropDatabase(): void
{
$connection = $this->container->get(Connection::class);
$connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_order`');
$connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_group_item`');
$connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_group_mapping`');
$connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_product_group`');
$connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_group_translation`');
$connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_group`');
$connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set_product_extension`');
$connection->executeStatement('DROP TABLE IF EXISTS `dreisc_set`');
}
public function activate(ActivateContext $activateContext): void
{
parent::activate($activateContext);
/** Install the demo data, if the environment varianble DREISCHILD_TEST_SYSTEM is set */
if(!empty(getenv('DREISCHILD_TEST_SYSTEM'))) {
/** @var Installer $installer */
$installer = $this->container->get(Installer::class);
$installer->install(true);
}
}
}