Add setting updatedAt to Subscriber factory

[MAILPOET-4716]
This commit is contained in:
Jan Lysý
2022-10-10 20:04:29 +02:00
committed by Rostislav Wolný
parent d2247a1c76
commit 879befcc76

View File

@@ -183,6 +183,15 @@ class Subscriber {
return $this;
}
/**
* @return $this
*/
public function withUpdatedAt(DateTimeInterface $updatedAt) {
$this->data['updatedAt'] = $updatedAt;
return $this;
}
/**
* @throws \Exception
*/
@@ -226,6 +235,18 @@ class Subscriber {
}
$entityManager->flush();
// workaround for storing updatedAt because it's set in TimestampListener
if (isset($this->data['updatedAt'])) {
$subscribersTable = $entityManager->getClassMetadata(SubscriberEntity::class)->getTableName();
$entityManager->getConnection()->executeQuery("
UPDATE $subscribersTable
SET updated_at = '{$this->data['updatedAt']->format('Y-m-d H:i:s')}'
WHERE id = {$subscriber->getId()}
");
$entityManager->refresh($subscriber);
}
return $subscriber;
}
}