From ec33912ff89def790deb5ff33537572916f91f5b Mon Sep 17 00:00:00 2001 From: pezcurrel Date: Wed, 28 Dec 2022 23:47:23 +0100 Subject: [PATCH] Restructured a bit the language management code --- web/clitools/getinstinfo.php | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/web/clitools/getinstinfo.php b/web/clitools/getinstinfo.php index f32df63..8f54e8e 100755 --- a/web/clitools/getinstinfo.php +++ b/web/clitools/getinstinfo.php @@ -630,7 +630,6 @@ if (is_null($oidata)) { if (!$opts['dryrun']) myq($link,'INSERT INTO InstChecks (InstID, Time, Status) VALUES ('.$instid.', '.$now.', '.$idata['WasLastCheckOk'].')',__LINE__); -// yes: we don't do anything on InstLangs and InstOurLangs otherwise if ($instanswered && isset($idata['languages']) && is_array($idata['languages']) && count($idata['languages'])>0) { eecho(1,'«'.$opts['hostname'].'»: declared languages: '.implode(', ',$idata['languages']).N); if (!$opts['dryrun']) { @@ -642,27 +641,30 @@ if ($instanswered && isset($idata['languages']) && is_array($idata['languages']) myq($link,'INSERT INTO InstLangs SET InstID='.$instid.', LangID='.$langid.', Pos='.$pos,__LINE__); } } - // we try to detect languages only if it's set to the default "en", otherwise it has been explicitly set by admin and we assume it's the mostly used language - $dool=true; if (!is_null($oidata) && $oidata['OurLangsLock']==1) { - $dool=false; - } elseif ($idata['languages'][0]=='en') { - $idata['ourlanguages']=get_instance_langs($opts['hostname']); - while (count($idata['ourlanguages'])>5) - array_pop($languages); - foreach ($idata['ourlanguages'] as $key=>$lang) - $idata['ourlanguages'][$key]=str_replace('-','_',$lang); - eecho(1,'«'.$opts['hostname'].'»: detected languages: '.implode(', ',$idata['ourlanguages']).N); + eecho(1,'«'.$opts['hostname'].'»: won’t touch “our languages” because they are locked.'.N); } else { - $idata['ourlanguages']=$idata['languages']; - } - if ($dool && !$opts['dryrun']) { - myq($link,'DELETE FROM InstOurLangs WHERE InstID='.$instid,__LINE__); - $pos=0; - foreach ($idata['ourlanguages'] as $lang) { - $langid=getlangid($link,$lang,$opts['hostname'],__LINE__); - $pos++; - myq($link,'INSERT INTO InstOurLangs SET InstID='.$instid.', OurLangID='.$langid.', Pos='.$pos,__LINE__); + // we try to detect languages only if first declared language (the only one currently definable by admins) + // is different from the default "en", assuming it's been set to the mostly used language on the instance + if ($idata['languages'][0]=='en') { + $idata['ourlanguages']=get_instance_langs($opts['hostname']); + while (count($idata['ourlanguages'])>5) + array_pop($languages); + foreach ($idata['ourlanguages'] as $key=>$lang) + $idata['ourlanguages'][$key]=str_replace('-','_',$lang); + eecho(1,'«'.$opts['hostname'].'»: detected languages: '.implode(', ',$idata['ourlanguages']).N); + } else { + $idata['ourlanguages']=$idata['languages']; + eecho(1,'«'.$opts['hostname'].'»: copied declared languages to detected languages.'.N); + } + if (!$opts['dryrun']) { + myq($link,'DELETE FROM InstOurLangs WHERE InstID='.$instid,__LINE__); + $pos=0; + foreach ($idata['ourlanguages'] as $lang) { + $langid=getlangid($link,$lang,$opts['hostname'],__LINE__); + $pos++; + myq($link,'INSERT INTO InstOurLangs SET InstID='.$instid.', OurLangID='.$langid.', Pos='.$pos,__LINE__); + } } } }