<?php declare(strict_types=1);
namespace Moorl\SignIn;
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 MoorlSignIn extends Plugin
{
public const NAME = 'MoorlSignIn';
public const DATA_CREATED_AT = '2000-09-18 00:00:00.000';
public const PLUGIN_TABLES = [
'moorl_si'
];
public const SHOPWARE_TABLES = [
'mail_template_type',
'mail_template_type_translation',
'mail_template',
'mail_template_translation',
'event_action',
'flow',
'custom_field_set'
];
public const INHERITANCES = [];
public const MAIL_TEMPLATE_MAIL_SEND_ACTION = 'moorl_si.action.mail.send';
public const EMPTY_TEXT = "*****";
public const EMPTY_ZIPCODE = "00000";
public const SKIP_CHECK_TOKEN = "skip-check-token";
public const LAST_KNOWN_PAGE = "last-known-page";
public function activate(ActivateContext $activateContext): void
{
parent::activate($activateContext); // TODO: Change the autogenerated stub
/* @var $dataService DataService */
$dataService = $this->container->get(DataService::class);
$dataService->install(self::NAME);
}
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 (array_reverse(self::SHOPWARE_TABLES) as $table) {
$sql = sprintf("DELETE FROM `%s` WHERE `created_at` = '%s';", $table, self::DATA_CREATED_AT);
try {
$connection->executeStatement($sql);
} catch (\Exception $exception) {
continue;
}
}
$sql = "DELETE FROM `snippet` WHERE `translation_key` LIKE 'customFields.moorl_si_%';";
$connection->executeStatement($sql);
}
}