Save new templates image data to the new columns

[MAILPOET-2686]
This commit is contained in:
Rostislav Wolny
2021-10-15 12:47:47 +02:00
committed by Veljko V
parent f5e4bab40b
commit b51f7b2d0e
3 changed files with 10 additions and 2 deletions

View File

@@ -211,7 +211,7 @@ class NewsletterSend extends React.Component {
saveTemplate = (response, done) => { saveTemplate = (response, done) => {
const thumbnailPromise = this.getThumbnailPromise(response.meta.preview_url); const thumbnailPromise = this.getThumbnailPromise(response.meta.preview_url);
thumbnailPromise thumbnailPromise
.then((thumbnail) => { .then((thumbnailData) => {
MailPoet.Ajax.post({ MailPoet.Ajax.post({
api_version: window.mailpoet_api_version, api_version: window.mailpoet_api_version,
endpoint: 'newsletterTemplates', endpoint: 'newsletterTemplates',
@@ -219,7 +219,7 @@ class NewsletterSend extends React.Component {
data: { data: {
newsletter_id: response.data.id, newsletter_id: response.data.id,
name: response.data.subject, name: response.data.subject,
thumbnail, thumbnail_data: thumbnailData,
body: JSON.stringify(response.data.body), body: JSON.stringify(response.data.body),
categories: '["recent"]', categories: '["recent"]',
}, },

View File

@@ -52,6 +52,10 @@ class NewsletterTemplatesRepository extends Repository {
$template->setThumbnail($data['thumbnail']); $template->setThumbnail($data['thumbnail']);
} }
if (isset($data['thumbnail_data'])) {
$template->setThumbnailData($data['thumbnail_data']);
}
if (isset($data['body'])) { if (isset($data['body'])) {
$template->setBody(json_decode($data['body'], true)); $template->setBody(json_decode($data['body'], true));
} }

View File

@@ -18,17 +18,21 @@ class NewsletterTemplatesRepositoryTest extends \MailPoetTest {
$createdTemplate = $this->newsletterTemplatesRepository->createOrUpdate([ $createdTemplate = $this->newsletterTemplatesRepository->createOrUpdate([
'name' => 'Another template', 'name' => 'Another template',
'body' => '{"content": {}, "globalStyles": {}}', 'body' => '{"content": {}, "globalStyles": {}}',
'thumbnail_data' => 'data:image/gif;base64,R0lGODlhAQABAAAAACw=',
]); ]);
expect($createdTemplate->getName())->equals('Another template'); expect($createdTemplate->getName())->equals('Another template');
expect($createdTemplate->getBody())->equals(['content' => [], 'globalStyles' => []]); expect($createdTemplate->getBody())->equals(['content' => [], 'globalStyles' => []]);
expect($createdTemplate->getThumbnailData())->equals('data:image/gif;base64,R0lGODlhAQABAAAAACw=');
$updatedTemplate = $this->newsletterTemplatesRepository->createOrUpdate([ $updatedTemplate = $this->newsletterTemplatesRepository->createOrUpdate([
'id' => $createdTemplate->getId(), 'id' => $createdTemplate->getId(),
'name' => 'Another template updated', 'name' => 'Another template updated',
'body' => '{"content": "changed"}', 'body' => '{"content": "changed"}',
'thumbnail_data' => 'data:image/gif;base64,R0lGO==',
]); ]);
expect($updatedTemplate->getName())->equals('Another template updated'); expect($updatedTemplate->getName())->equals('Another template updated');
expect($updatedTemplate->getBody())->equals(['content' => 'changed']); expect($updatedTemplate->getBody())->equals(['content' => 'changed']);
expect($updatedTemplate->getThumbnailData())->equals('data:image/gif;base64,R0lGO==');
} }
public function testItCleansRecentlySent() { public function testItCleansRecentlySent() {