Skip to content

Commit

Permalink
[Mailchimp] add template export naming scheme as mailchimp max. suppo…
Browse files Browse the repository at this point in the history
…rts 50 chars
  • Loading branch information
markus-moser committed Oct 6, 2017
1 parent 0ee2b15 commit 07a23ca
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Newsletter/ProviderHandler/Mailchimp/TemplateExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
]);
}
Expand All @@ -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']
),
Expand Down

0 comments on commit 07a23ca

Please sign in to comment.