<?php declare(strict_types=1);
namespace Neno\VisualMailEditor;
use Doctrine\DBAL\Connection;
use Neno\VisualMailEditor\Core\Content\EditorState\EditorStateEntity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Uuid\Uuid;
class NenoVisualMailEditor extends Plugin
{
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if ($uninstallContext->keepUserData()) {
return;
}
/*
* NOTE:
*
* We don't uninstall the html/plain templates anymore,
* we just wipe the corresponding editor state,
* since otherwise we invalidate any existing
* business event mappings and in turn may cause
* trouble for most users
*
* Uncomment the following method call to also wipe
* the generated templates, if so wanted
*/
// $this->uninstallTemplates($uninstallContext);
$this->dropTables();
}
private function uninstallTemplates(UninstallContext $context): void
{
$connection = $this->container->get(Connection::class);
$editorStateQuerySql = 'SELECT `template_id` FROM neno_vme_editor_state';
$editorStateEntries = $connection->fetchAll($editorStateQuerySql);
if (!count($editorStateEntries)) {
return;
}
/**
* @var EntityRepositoryInterface $mailTemplateRepository
*/
$mailTemplateRepository = $this->container->get('mail_template.repository');
$mailTemplateRepository->delete(
array_map(function ($editorState): array {
return [ 'id' => Uuid::fromBytesToHex($editorState['template_id']) ];
}, $editorStateEntries),
$context->getContext()
);
}
private function dropTables(): void
{
$connection = $this->container->get(Connection::class);
$connection->executeUpdate('DROP TABLE IF EXISTS `neno_vme_editor_state_translation`');
$connection->executeUpdate('DROP TABLE IF EXISTS `neno_vme_editor_state`');
$connection->executeUpdate('DROP TABLE IF EXISTS `neno_vme_custom_preset`');
}
}