Add BC for importing older exported templates
We allow exporting templates as JSON and templates exported from the older plugin versions use thumbnail key for storing the image data. [MAILPOET-2686]
This commit is contained in:
committed by
Veljko V
parent
5134713c2d
commit
dd0a19a314
@@ -49,7 +49,12 @@ class NewsletterTemplatesRepository extends Repository {
|
||||
}
|
||||
|
||||
if (isset($data['thumbnail'])) {
|
||||
$template->setThumbnail($data['thumbnail']);
|
||||
// Backward compatibility for importing templates exported from older versions
|
||||
if (strpos($data['thumbnail'], 'data:image') === 0) {
|
||||
$data['thumbnail_data'] = $data['thumbnail'];
|
||||
} else {
|
||||
$template->setThumbnail($data['thumbnail']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['thumbnail_data'])) {
|
||||
|
@@ -54,6 +54,17 @@ class NewsletterTemplatesRepositoryTest extends \MailPoetTest {
|
||||
expect($templates[0]->getName())->equals('Testing template 5');
|
||||
}
|
||||
|
||||
public function testItCanCreateFromOldDataFormat() {
|
||||
$createdTemplate = $this->newsletterTemplatesRepository->createOrUpdate([
|
||||
'name' => 'Another template',
|
||||
'body' => '{"content": {}, "globalStyles": {}}',
|
||||
'thumbnail' => 'data:image/gif;base64,R0lGODlhAQABAAAAACw=',
|
||||
]);
|
||||
expect($createdTemplate->getName())->equals('Another template');
|
||||
expect($createdTemplate->getBody())->equals(['content' => [], 'globalStyles' => []]);
|
||||
expect($createdTemplate->getThumbnailData())->equals('data:image/gif;base64,R0lGODlhAQABAAAAACw=');
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
$this->truncateEntity(NewsletterTemplateEntity::class);
|
||||
}
|
||||
|
Reference in New Issue
Block a user