Fixed Mixed language in activity summary emails

Kirby

Well-known member
Affected version
2.2.6
When activity summary emails are being sent to users in multiple languages, sections titles are mixed up if the sections do not use custom titles.

The root cause for this issue seems rather complicated:

Initially, the tile does get set in XF\Job\ActivitySummaryEmail::generateEmailData():
PHP:
$instance->addDisplayValue($handler->getTitle(), $total);

XF\ActivitySummary\AbstractSection::getTitle() does return property title from the entity:
PHP:
public function getTitle()
{
    return $this->section->title;
}

XF\Entity\ActivitySummarySection does use a cached getter for property title:

PHP:
public function getTitle()
{
    $sectionPhrase = \XF::phrase('activity_summary_section.' . $this->section_id);
    $value = $sectionPhrase->render('html', ['nameOnInvalid' => false]);
    if ($value !== '')
    {
        return $value;
    }

    $definition = $this->ActivitySummaryDefinition;
    $handler = $this->handler;
    if ($definition && $handler)
    {
        return $handler->getDefaultTitle($definition);
    }
    else
    {
        return '';
    }
}

So this in turn does go back to the XF\ActivitySummary\AbstractSecion::getDefaultTitle() if no specific title has been set:
PHP:
public function getDefaultTitle(\XF\Entity\ActivitySummaryDefinition $definition)
{
    return $definition->title;
}

Yet again this does return property title from XF\Entity\ActivitySummaryDefinition which again does use a cached getter:
PHP:
public function getTitle()
{
    return \XF::phrase($this->getTitlePhraseName());
}

So finally this does return a phrase, but as the initial code was not run as the receiver, this phrase will be returned for the default language being used by the job.

This also affects other display values set by XF\Job\ActivitySummaryEmail::generateAndSendEmail():
PHP:
$instance->addDisplayValues($this->data['global_display_values']);

To fix this, it seems like several things need to be done:
  • The job must run the relevant part as the receiving user
  • When accessing the title from the entities the result must not be cached as it could change on multiple calls (if recipients are using different languages)
 
Last edited:
Back
Top Bottom