Restructured a bit the language management code

This commit is contained in:
pezcurrel 2022-12-28 23:47:23 +01:00
parent db749d2e7d
commit ec33912ff8

View file

@ -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,11 +641,12 @@ 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') {
eecho(1,'«'.$opts['hostname'].'»: wont touch “our languages” because they are locked.'.N);
} else {
// 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);
@ -655,8 +655,9 @@ if ($instanswered && isset($idata['languages']) && is_array($idata['languages'])
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 ($dool && !$opts['dryrun']) {
if (!$opts['dryrun']) {
myq($link,'DELETE FROM InstOurLangs WHERE InstID='.$instid,__LINE__);
$pos=0;
foreach ($idata['ourlanguages'] as $lang) {
@ -666,6 +667,7 @@ if ($instanswered && isset($idata['languages']) && is_array($idata['languages'])
}
}
}
}
if (isset($idata['activity']) && is_array($idata['activity'])) {
if (!$opts['dryrun']) {