<?php declare(strict_types=1);
namespace MoorlFormsClassic;
use Doctrine\DBAL\Connection;
use MoorlFoundation\Core\Service\DataService;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
class MoorlFormsClassic extends Plugin
{
public const NAME = 'MoorlFormsClassic';
public const DATA_CREATED_AT = '2003-03-03 03:02:22.000';
public const PLUGIN_TABLES = [
'moorl_fb_history',
'moorl_fb_appointment',
];
public const SHOPWARE_TABLES = [
'moorl_fb_form',
'moorl_fb_form_translation',
'moorl_fb_form_product',
'moorl_fb_element',
'moorl_fb_element_translation',
'cms_page',
'cms_page_translation',
'cms_section',
'cms_block',
'category',
'category_translation',
'mail_template_type',
'mail_template_type_translation',
'mail_template',
'mail_template_translation',
'event_action',
'custom_field_set'
];
public const INHERITANCES = [];
public function activate(ActivateContext $activateContext): void
{
parent::activate($activateContext); // TODO: Change the autogenerated stub
try {
/* @var $dataService DataService */
$dataService = $this->container->get(DataService::class);
$dataService->install(self::NAME);
} catch (\Exception $exception) {
}
}
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext); // TODO: Change the autogenerated stub
try {
/* @var $dataService DataService */
$dataService = $this->container->get(DataService::class);
$dataService->install(self::NAME);
} catch (\Exception $exception) {
}
}
public function uninstall(UninstallContext $context): void
{
parent::uninstall($context);
if ($context->keepUserData()) {
return;
}
$this->uninstallTrait();
}
private function uninstallTrait(): void
{
$connection = $this->container->get(Connection::class);
foreach (array_reverse(self::PLUGIN_TABLES) as $table) {
$sql = sprintf('DROP TABLE IF EXISTS `%s`;', $table);
$connection->executeStatement($sql);
}
foreach (self::INHERITANCES as $table => $propertyNames) {
foreach ($propertyNames as $propertyName) {
$sql = sprintf("ALTER TABLE `%s` DROP `%s`;", $table, $propertyName);
try {
$connection->executeStatement($sql);
} catch (\Exception $exception) {
continue;
}
}
}
}
}