Periodic notifications don't seem to work

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Periodic notifications don't seem to work
« Reply #30, on September 23rd, 2013, 07:38 PM »
Quote from live627 on September 23rd, 2013, 01:47 AM
Quote from Nao on September 21st, 2013, 01:35 AM
How about triggering scheduled tasks only if the current user's language is the default..? Then at least we can avoid what happened last time.
I don't know what to say, sorry.
Well, technically I think it's a problem that's always been there; it's probably already in SMF. To tell the truth, though, I don't remember seeing it on my websites, but that's probably because I don't have a scheduled task that sends e-mails around... Not that I can think of, at least.

I think that it would be best to test for scheduled task triggers only if the current visitor is using the default forum language; otherwise, we'll be risking what happened the other day, when everyone received an e-mail in French...
And frankly, I don't think it's realistic to expect the scheduler to 'know' what language files need to be reloaded specifically for this task.
Of course, I could 'quite simply' do some magic trick to loadLanguage...

Code: [Select]
function loadLanguage($template_name, $lang = '', $fatal = true, $force_reload = false, $fallback = false, $force_reload_all = false)
{
global $theme, $context, $settings, $boarddir, $db_show_debug, $txt, $helptxt, $cachedir;
static $already_loaded = array(), $folder_date = array();

if ($force_reload_all)
{
loadLanguage(array_keys($already_loaded), $lang, $fatal, true, $fallback);
return '';
}

There you go, this adds a trigger to force a mass-reload of all existing language files loaded so far.
Of course, that's going to be relatively expensive, but if we don't have more than a couple of active language files, it's just a matter of gathering all users that are on the same language as the current user, then send the e-mails, then gather the other users by language, and for them, call $force_reload_all, and send the e-mails to them. Then, restore $txt (which, of course, we'll have saved in the first place.)

Dunno which solution is the best, really... What do you think of this function hack, though?