if (!$this->templates) {
$this->getHeaderFooter();
$this->templates = array();
-
- if ($this->body_text) {
+ if ($this->body_text || $this->header->body_text || $this->footer->body_text) {
$template = array();
- if ($this->header) {
+ if ($this->header->body_text) {
$template[] = $this->header->body_text;
+ } else {
+ $template[] = CRM_Utils_String::htmlToText($this->header->body_html);
}
- $template[] = $this->body_text;
+ if ($this->body_text) {
+ $template[] = $this->body_text;
+ } else {
+ $template[] = CRM_Utils_String::htmlToText($this->body_html);
+ }
- if ($this->footer) {
+ if ($this->footer->body_text) {
$template[] = $this->footer->body_text;
+ } else {
+ $template[] = CRM_Utils_String::htmlToText($this->footer->body_html);
}
$this->templates['text'] = implode("\n", $template);
// this is where we create a text template from the html template if the text template did not exist
// this way we ensure that every recipient will receive an email even if the pref is set to text and the
// user uploads an html email only
- if (!$this->body_text) {
+ if (empty($this->templates['text'])) {
$this->templates['text'] = CRM_Utils_String::htmlToText($this->templates['html']);
}
}
*
* Get mailing object and replaces subscribeInvite, domain and mailing tokens.
*
- * @param array $mailing
+ * @param CRM_Mailing_BAO_Mailing $mailing
*/
public static function tokenReplace(&$mailing) {
$domain = CRM_Core_BAO_Domain::getDomain();
$mailerJobsMax = Civi::settings()->get('mailerJobsMax');
if (is_numeric($mailerJobsMax) && $mailerJobsMax > 0) {
$lockArray = range(1, $mailerJobsMax);
+
+ // Shuffle the array to improve chances of quickly finding an open thread
shuffle($lockArray);
- // check if we are using global locks
+ // Check if we are using global locks
foreach ($lockArray as $lockID) {
$cronLock = Civi::lockManager()->acquire("worker.mailing.send.{$lockID}");
if ($cronLock->isAcquired()) {
}
}
- // exit here since we have enuf cronjobs running
+ // Exit here since we have enough mailing processes running
if (!$gotCronLock) {
- CRM_Core_Error::debug_log_message('Returning early, since max number of cronjobs running');
+ CRM_Core_Error::debug_log_message('Returning early, since the maximum number of mailing processes are running');
return TRUE;
}
}
}
- // load bootstrap to call hooks
-
// Split up the parent jobs into multiple child jobs
$mailerJobSize = Civi::settings()->get('mailerJobSize');
CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize, $mode);
CRM_Mailing_BAO_MailingJob::runJobs(NULL, $mode);
CRM_Mailing_BAO_MailingJob::runJobs_post($mode);
- // lets release the global cron lock if we do have one
+ // Release the global lock if we do have one
if ($gotCronLock) {
$cronLock->release();
}
return $fieldPerms;
}
+ /**
+ * Whitelist of possible values for the entity_table field
+ * @return array
+ */
+ public static function mailingGroupEntityTables() {
+ $tables = array(
+ CRM_Contact_BAO_Group::getTableName(),
+ CRM_Mailing_BAO_Mailing::getTableName(),
+ );
+ // Identical keys & values
+ return array_combine($tables, $tables);
+ }
+
}