Fixed  Emails not sent to users attached to a deleted language

Mike

XenForo developer
Staff member
If you delete a language while users are using it, it can cause them to not get emails. There are 2 parts to this fix.

This part updates the users when the language is deleted. In library/XenForo/DataWriter/Language.php, add the code in green: (code is within the _postDelete function)

Rich (BB code):
        $db->delete('xf_email_template_compiled', 'language_id = ' . $db->quote($languageId));

        $db->update('xf_user',
            array('language_id' => XenForo_Application::get('options')->defaultLanguageId),
            'language_id = ' . $db->quote($languageId)
        );

        $this->_getLanguageModel()->rebuildLanguageCaches();

This part ensures that users in that situation will receive emails correctly. In library/XenForo/Mail.php, add the code in green and remove the code in red: (code is in the __construct function)

Rich (BB code):
    public function __construct($emailTitle, array $params, $languageId = null)
    {
        if (!XenForo_Application::isRegistered('languages'))
        {
            XenForo_Application::set('languages', XenForo_Model::create('XenForo_Model_Language')->getAllLanguagesForCache());
        }

        if ($languageId === null)
        {
            $languageId = XenForo_Phrase::getLanguageId();
        }
        else if (!$languageId)
        {
            $languageId = XenForo_Application::get('options')->defaultLanguageId;
        }
        else
        {
            $languages = XenForo_Application::get('languages');
            if (!isset($languages[$languageId]))
            {
                $languageId = XenForo_Application::get('options')->defaultLanguageId;
            }
        }

        $this->_emailTitle = $emailTitle;
        $this->_params = $params;
        $this->_languageId = $languageId;

        if (!isset(self::$_emailCache[$emailTitle][$languageId]))
        {
            self::$_preCache[$emailTitle] = true;
        }

        if (!XenForo_Application::isRegistered('languages'))
        {
            XenForo_Application::set('languages', XenForo_Model::create('XenForo_Model_Language')->getAllLanguagesForCache());
        }
    }
 
Top Bottom