1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed Emails not sent to users attached to a deleted language

Discussion in 'Resolved Bug Reports' started by Mike, Aug 23, 2011.

  1. Mike

    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)

    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)

    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());
            }
        }
     
    JulianD likes this.
  2. JulianD

    JulianD Well-Known Member

    Thank you Mike!
     

Share This Page