Skip to content

Commit

Permalink
fix: Disable locale filter in Member admin. DOC003-35
Browse files Browse the repository at this point in the history
When creating a user the locale is temporarily changed which interferes with
subsite retrieval.

If subsites are in use, if translatable is enabled and the current controller
is the member admin, then disable the locale filter when retrieving the root
subsite.
  • Loading branch information
sig-steve committed Feb 12, 2021
1 parent 2f8ae85 commit 6a4a5d7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion code/email/MailblockMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ public function sendHTML($to, $from, $subject, $htmlContent,
protected function mailblockRewrite($recipients, $subject, $customHeaders) {
// Get the correct mailblock config.
if (class_exists('Subsite')) {
// Disable the locale filter if Translatable uses the wrong locale.
$badTranslatable = $this->hasBadTranslatable();
if ($badTranslatable) {
$enabled = Translatable::disable_locale_filter();
}
$mainSiteConfig = SiteConfig::get()->filter('SubsiteID', 0)->first();
// Re-enable the locale filter if it was disabled.
if ($badTranslatable) {
Translatable::enable_locale_filter($enabled);
}
}
else {
$mainSiteConfig = SiteConfig::current_site_config();
Expand Down Expand Up @@ -101,7 +110,7 @@ protected function mailblockRewrite($recipients, $subject, $customHeaders) {
$newRecipients = implode(', ', preg_split("/\r\n|\n|\r/",
$mailblockRecipients
));
// If one of the orignial recipients is in the whitelist, add them
// If one of the original recipients is in the whitelist, add them
// to the new recipients list.
$mailblockWhitelist = $siteConfig->getField('MailblockWhitelist');
$whitelist = preg_split("/\r\n|\n|\r/", $mailblockWhitelist);
Expand Down Expand Up @@ -132,4 +141,17 @@ protected function mailblockRewrite($recipients, $subject, $customHeaders) {
);
return $rewrites;
}

/**
* Is Translatable installed, and does it misbehave in the current scenario.
*
* When creating a member the locale is temporarily changed which
* interferes with subsite retrieval.
*
* @return boolean
*/
private function hasBadTranslatable() {
return class_exists('Translatable')
&& Director::get_current_page() instanceof SecurityAdmin;
}
}

0 comments on commit 6a4a5d7

Please sign in to comment.