Add entity lifecycle listener for emoji sanitisation

[MAILPOET-3196]
This commit is contained in:
Rostislav Wolny
2020-10-06 11:47:23 +02:00
committed by Veljko V
parent 7449d3df3e
commit 96f2bfaa20
8 changed files with 115 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
namespace MailPoet\Doctrine;
use MailPoet\Doctrine\EventListeners\EmojiEncodingListener;
use MailPoet\Doctrine\EventListeners\TimestampListener;
use MailPoet\Doctrine\EventListeners\ValidationListener;
use MailPoet\Tracy\DoctrinePanel\DoctrinePanel;
@@ -25,16 +26,21 @@ class EntityManagerFactory {
/** @var ValidationListener */
private $validationListener;
/** @var EmojiEncodingListener */
private $emojiEncodingListener;
public function __construct(
Connection $connection,
Configuration $configuration,
TimestampListener $timestampListener,
ValidationListener $validationListener
ValidationListener $validationListener,
EmojiEncodingListener $emojiEncodingListener
) {
$this->connection = $connection;
$this->configuration = $configuration;
$this->timestampListener = $timestampListener;
$this->validationListener = $validationListener;
$this->emojiEncodingListener = $emojiEncodingListener;
}
public function createEntityManager() {
@@ -56,5 +62,10 @@ class EntityManagerFactory {
[Events::onFlush],
$this->validationListener
);
$entityManager->getEventManager()->addEventListener(
[Events::prePersist, Events::preUpdate],
$this->emojiEncodingListener
);
}
}