From 07a23ca9a8a1a0c7d2789d45f41b78080d8e8b5a Mon Sep 17 00:00:00 2001 From: markus-moser Date: Fri, 6 Oct 2017 16:06:10 +0200 Subject: [PATCH] [Mailchimp] add template export naming scheme as mailchimp max. supports 50 chars --- .../Mailchimp/TemplateExporter.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Newsletter/ProviderHandler/Mailchimp/TemplateExporter.php b/src/Newsletter/ProviderHandler/Mailchimp/TemplateExporter.php index d71bf98e..d7d0270e 100644 --- a/src/Newsletter/ProviderHandler/Mailchimp/TemplateExporter.php +++ b/src/Newsletter/ProviderHandler/Mailchimp/TemplateExporter.php @@ -57,8 +57,8 @@ public function exportTemplate(Document\PageSnippet $document) $html = Mail::setAbsolutePaths($html, $document); //dirty hack to make sure mailchimp merge tags are not url-encoded - $html = str_replace('*%7C', '*|', $html); - $html = str_replace('%7C*', '|*', $html); + $html = str_replace("*%7C", "*|", $html); + $html = str_replace("%7C*", "|*", $html); $templateExists = false; @@ -70,30 +70,32 @@ public function exportTemplate(Document\PageSnippet $document) } } + $templateName = substr($document->getKey(), 0, 35) . ' [ID ' . $document->getID() . ']'; + if ($remoteId && $templateExists) { $this->getLogger()->info( sprintf( '[MailChimp] Updating new Template with name %s based on document id %s', - $document->getFullPath(), + $templateName, $document->getId() ) ); $result = $apiClient->patch("templates/$remoteId", [ - 'name' => $document->getFullPath(), + 'name' => $templateName, 'html' => $html ]); } else { $this->getLogger()->info( sprintf( '[MailChimp][Template] Creating new template with name %s based on document id %s', - $document->getFullPath(), + $templateName, $document->getId() ) ); $result = $apiClient->post('templates', [ - 'name' => $document->getFullPath(), + 'name' => $templateName, 'html' => $html ]); } @@ -106,7 +108,7 @@ public function exportTemplate(Document\PageSnippet $document) $this->getLogger()->error( sprintf( '[MailChimp][Template] Failed to export template %s: %s %s', - $document->getFullPath(), + $templateName, json_encode($apiClient->getLastError()), $apiClient->getLastResponse()['body'] ),