custom/plugins/NenoVisualMailEditor/src/NenoVisualMailEditor.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Neno\VisualMailEditor;
  3. use Doctrine\DBAL\Connection;
  4. use Neno\VisualMailEditor\Core\Content\EditorState\EditorStateEntity;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\Plugin;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. use Shopware\Core\Framework\Uuid\Uuid;
  10. class NenoVisualMailEditor extends Plugin
  11. {
  12.     public function uninstall(UninstallContext $uninstallContext): void
  13.     {
  14.         parent::uninstall($uninstallContext);
  15.         if ($uninstallContext->keepUserData()) {
  16.             return;
  17.         }
  18.         /*
  19.          * NOTE:
  20.          *
  21.          * We don't uninstall the html/plain templates anymore,
  22.          * we just wipe the corresponding editor state,
  23.          * since otherwise we invalidate any existing
  24.          * business event mappings and in turn may cause
  25.          * trouble for most users
  26.          *
  27.          * Uncomment the following method call to also wipe
  28.          * the generated templates, if so wanted
  29.          */
  30.         // $this->uninstallTemplates($uninstallContext);
  31.         $this->dropTables();
  32.     }
  33.     private function uninstallTemplates(UninstallContext $context): void
  34.     {
  35.         $connection $this->container->get(Connection::class);
  36.         $editorStateQuerySql 'SELECT `template_id` FROM neno_vme_editor_state';
  37.         $editorStateEntries $connection->fetchAll($editorStateQuerySql);
  38.         if (!count($editorStateEntries)) {
  39.             return;
  40.         }
  41.         /**
  42.          * @var EntityRepositoryInterface $mailTemplateRepository
  43.          */
  44.         $mailTemplateRepository $this->container->get('mail_template.repository');
  45.         $mailTemplateRepository->delete(
  46.             array_map(function ($editorState): array {
  47.                 return [ 'id' => Uuid::fromBytesToHex($editorState['template_id']) ];
  48.             }, $editorStateEntries),
  49.             $context->getContext()
  50.         );
  51.     }
  52.     private function dropTables(): void
  53.     {
  54.         $connection $this->container->get(Connection::class);
  55.         $connection->executeUpdate('DROP TABLE IF EXISTS `neno_vme_editor_state_translation`');
  56.         $connection->executeUpdate('DROP TABLE IF EXISTS `neno_vme_editor_state`');
  57.         $connection->executeUpdate('DROP TABLE IF EXISTS `neno_vme_custom_preset`');
  58.     }
  59. }