Change NewsletterCoupon::cleanupSensitiveData signature
This change allows passing body array and retuning body array so that NewsletterEntity instance doesn't need to get passed around [MAILPOET-4678]
This commit is contained in:
@@ -2,28 +2,24 @@
|
||||
|
||||
namespace MailPoet\Newsletter;
|
||||
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Newsletter\Renderer\Blocks\Coupon;
|
||||
|
||||
class NewsletterCoupon {
|
||||
public function cleanupSensitiveData(NewsletterEntity $newsletter): NewsletterEntity {
|
||||
$body = $newsletter->getBody();
|
||||
if (!is_array($body) || empty($body['content'])) {
|
||||
return $newsletter;
|
||||
public function cleanupBodySensitiveData(array $newsletterBody): array {
|
||||
|
||||
if (!is_array($newsletterBody) || empty($newsletterBody['content'])) {
|
||||
return $newsletterBody;
|
||||
}
|
||||
$cleanBlocks = $this->cleanupCouponBlocks($body['content']['blocks']);
|
||||
$updatedBody = array_merge(
|
||||
$body,
|
||||
$cleanBlocks = $this->cleanupCouponBlocks($newsletterBody['content']['blocks']);
|
||||
return array_merge(
|
||||
$newsletterBody,
|
||||
[
|
||||
'content' => array_merge(
|
||||
$body['content'],
|
||||
$newsletterBody['content'],
|
||||
['blocks' => $cleanBlocks]
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
$newsletter->setBody($updatedBody);
|
||||
return $newsletter;
|
||||
}
|
||||
|
||||
private function cleanupCouponBlocks(array &$blocks): array {
|
||||
|
@@ -187,7 +187,10 @@ class NewsletterSaveController {
|
||||
// reset sent at date
|
||||
$duplicate->setSentAt(null);
|
||||
|
||||
$duplicate = $this->newsletterCoupon->cleanupSensitiveData($duplicate);
|
||||
$body = $duplicate->getBody();
|
||||
if ($body) {
|
||||
$duplicate->setBody($this->newsletterCoupon->cleanupBodySensitiveData($body));
|
||||
}
|
||||
$this->newslettersRepository->persist($duplicate);
|
||||
$this->newslettersRepository->flush();
|
||||
|
||||
|
@@ -37,12 +37,10 @@ class NewsletterCouponTest extends \MailPoetUnitTest {
|
||||
'code' => 'asdasjdkkjaskljdasd',
|
||||
],
|
||||
];
|
||||
$newsletter->setBody(['content' => ['blocks' => $blocks]]);
|
||||
$result = $newsletterCoupon->cleanupSensitiveData($newsletter);
|
||||
$body = (array)$result->getBody();
|
||||
$updatedBody = $newsletterCoupon->cleanupBodySensitiveData(['content' => ['blocks' => $blocks]]);
|
||||
$cleanBlock = ['type' => Coupon::TYPE, 'code' => Coupon::CODE_PLACEHOLDER];
|
||||
expect($body['content']['blocks'][0]['blocks'][0])->equals($cleanBlock);
|
||||
expect($body['content']['blocks'][0]['blocks'][1]['blocks'][0])->equals($cleanBlock);
|
||||
expect($body['content']['blocks'][1])->equals($cleanBlock);
|
||||
expect($updatedBody['content']['blocks'][0]['blocks'][0])->equals($cleanBlock);
|
||||
expect($updatedBody['content']['blocks'][0]['blocks'][1]['blocks'][0])->equals($cleanBlock);
|
||||
expect($updatedBody['content']['blocks'][1])->equals($cleanBlock);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user