Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/151574
Change subject: WIP Track TY emails in CiviMail
......................................................................
WIP Track TY emails in CiviMail
Change-Id: Id4f19ea94c1db82e838d7dd5439fb28a38c88a1a
---
M sites/all/modules/thank_you/generators/RenderTranslatedPage.php
M sites/all/modules/thank_you/thank_you.module
2 files changed, 68 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/74/151574/1
diff --git a/sites/all/modules/thank_you/generators/RenderTranslatedPage.php
b/sites/all/modules/thank_you/generators/RenderTranslatedPage.php
index 318b0ee..d2961d6 100644
--- a/sites/all/modules/thank_you/generators/RenderTranslatedPage.php
+++ b/sites/all/modules/thank_you/generators/RenderTranslatedPage.php
@@ -36,6 +36,9 @@
if (count($wantedLangs) > 0) {
$languages = array_intersect($wantedLangs, $languages);
}
+
+ $civimail_store = new CiviMailStore();
+
foreach( $languages as $lang ) {
try {
$published_revision =
$this->get_published_revision( $lang );
@@ -52,8 +55,14 @@
// Assert no garbage
FindUnconsumedTokens::renderAndFindTokens(
$page_content, $lang );
+ $template_name = basename( $file );
+
+ $page_content =
$this->add_template_info_comment( $page_content, $template_name,
$published_revision );
+
if (file_put_contents( $file, $page_content )) {
watchdog( 'make-thank-you', "$lang --
Wrote translation into $file", null, WATCHDOG_INFO );
+ $subject = thank_you_get_subject( $lang
);
+ $civimail_store->addMailing(
'thank_you', $template_name, $page_content, $subject, $published_revision );
} else {
watchdog( 'make-thank-you', "$lang --
Could not open $file for writing!", null, WATCHDOG_ERROR );
@@ -68,6 +77,19 @@
}
/**
+ * Add an HTML comment with the file name and revision number to the
bottom of the page
+ *
+ * @param string $page_content HTML content without comment
+ * @param string $template_name name of template
+ * @param int $revision revision number of template
+ *
+ * @returns string Content with revision comment appended
+ */
+ protected function add_template_info_comment( $page_content,
$template_name, $revision ) {
+ $comment = "<!-- template $template_name revision $revision
-->";
+ return $page_content . $comment;
+ }
+ /**
* This function builds a valid MediaWiki API URL by joining the
$base_url
* with a query string that is generated from the passed key, value
pairs.
*
diff --git a/sites/all/modules/thank_you/thank_you.module
b/sites/all/modules/thank_you/thank_you.module
index 1020371..a4fff9a 100644
--- a/sites/all/modules/thank_you/thank_you.module
+++ b/sites/all/modules/thank_you/thank_you.module
@@ -441,12 +441,29 @@
return false;
}
- $subj_msg = "donate_interface-email-subject";
- $email['subject'] = Translation::get_translated_message( $subj_msg,
$params['locale'] );
+ $email['subject'] = thank_you_get_subject( $params['locale'] );
$mailer = Mailer::getDefault();
- $email['reply_to'] = 'bounce-' . str_replace( '@', '=',
$email['to_address'] ) . '@donate.wikimedia.org';
+ //TODO: Inject dependency, use interface
+ $civimail_store = new CiviMailStore();
+
+ //TODO: Handle missing comment
+ $template_info = thank_you_get_template_info( $email['html'] );
+ //TODO: store the 'source' in some constant
+ $civi_mailing = $civimail_store->getMailing( 'thank_you',
$template_info['name'], $template_info['revision'] );
+ if ( !$civi_mailing ) {
+ $civi_mailing = $civimail_store->addMailing( 'thank_you',
$template_info['name'], 'missing body', $email['subject'],
$template_info['revision']);
+ }
+
+ //TODO: handle insert errors and time zone
+ $civi_queue_record = $civimail_store->addQueueRecord( $civi_mailing,
$email, date('Ymd', date() ) );
+
+ if ( $civi_queue_record ) {
+ $email['reply_to'] = $civi_queue_record->getVerp() .
'@donate.wikimedia.org';
+ } else {
+ $email['reply_to'] = 'bounce-' . str_replace( '@', '=',
$email['to_address'] ) . '@donate.wikimedia.org';
+ }
try {
@@ -460,7 +477,7 @@
return $email_success;
} catch (phpmailerException $e) {
//TODO: don't assume phpmailer
-
+ //TODO: something with the CiviMail queue record to indicate it
failed;
$debug = array_merge( $email, array( "html" => '', "plaintext"
=> '' ) );
watchdog('thank_you', 'Sending thank you message failed in
phpmailer for contribution: ' .
'<pre>' . check_plain(print_r($params, TRUE)) . "\n\n" .
@@ -497,6 +514,31 @@
}
}
+/**
+ * Gets the template name and revision number from an html comment
+ *
+ * @param string $html HTML source of the thank you email
+ * @returns array, 'revision' contains rev no, 'name' contains template name
+ */
+function thank_you_get_template_info( $html ) {
+ $matches = preg_match('/<!-- template (.+) revision (\d+) -->/');
+ if ( $matches && $matches->length >=2 ) {
+ return array(
+ 'name' => $matches[1],
+ 'revision' => (int) $matches[2]
+ );
+ }
+ return false;
+}
+
+/**
+ * Get the translated email subject
+ */
+function thank_you_get_subject( $locale ) {
+ $subj_msg = "donate_interface-email-subject";
+ return Translation::get_translated_message( $subj_msg, $locale );
+}
+
function thank_you_settings_form() {
$form = array();
--
To view, visit https://gerrit.wikimedia.org/r/151574
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id4f19ea94c1db82e838d7dd5439fb28a38c88a1a
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits