1 update to rule them all

This commit is contained in:
Jeroen De Meerleer 2018-12-24 11:15:32 +01:00 committed by Hypolite Petovan
parent 5cb56a6b12
commit 1bdd0bcbb2

View file

@ -291,160 +291,57 @@ function update_1288()
return Update::SUCCESS; return Update::SUCCESS;
} }
// Post-update script of PR 5751
function update_1296()
{
$translateKey = 'gender';
$allData = DBA::select('profile', ['id', $translateKey]);
$allLangs = L10n::getAvailableLanguages();
$success = 0;
$fail = 0;
foreach ($allData as $key => $data) {
$toTranslate = $data[$translateKey];
if ($toTranslate != '') {
foreach ($allLangs as $key => $lang) {
$a = new \stdClass();
$a->strings = [];
// First we get the the localizations
if (file_exists("view/lang/$lang/strings.php")) {
include "view/lang/$lang/strings.php";
}
if (file_exists("addon/morechoice/lang/$lang/strings.php")) {
include "addon/morechoice/lang/$lang/strings.php";
}
$localizedStrings = $a->strings;
unset($a);
$key = array_search($toTranslate, $localizedStrings);
if ($key !== false) {
break;
}
// defaulting to empty string
$key = '';
}
if ($key == '') {
$fail++;
} else {
DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
logger::log('Updated contact ' . $data['id'] . " to $translateKey " . $key .
' (was: ' . $data[$translateKey] . ')');
Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
Contact::updateSelfFromUserID($data['id']);
GContact::updateForUser($data['id']);
$success++;
}
}
}
Logger::log($translateKey . " fix completed. Success: $success. Fail: $fail");
return Update::SUCCESS;
}
// Post-update script of PR 5751
function update_1297()
{
$translateKey = 'marital';
$allData = DBA::select('profile', ['id', $translateKey]);
$allLangs = L10n::getAvailableLanguages();
$success = 0;
$fail = 0;
foreach ($allData as $key => $data) {
$toTranslate = $data[$translateKey];
if ($toTranslate != '') {
foreach ($allLangs as $key => $lang) {
$a = new \stdClass();
$a->strings = [];
// First we get the the localizations
if (file_exists("view/lang/$lang/strings.php")) {
include "view/lang/$lang/strings.php";
}
if (file_exists("addon/morechoice/lang/$lang/strings.php")) {
include "addon/morechoice/lang/$lang/strings.php";
}
$localizedStrings = $a->strings;
unset($a);
$key = array_search($toTranslate, $localizedStrings);
if ($key !== false) {
break;
}
// defaulting to empty string
$key = '';
}
if ($key == '') {
$fail++;
} else {
DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
logger::log('Updated contact ' . $data['id'] . " to $translateKey " . $key .
' (was: ' . $data[$translateKey] . ')');
Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
Contact::updateSelfFromUserID($data['id']);
GContact::updateForUser($data['id']);
$success++;
}
}
}
Logger::log($translateKey . " fix completed. Success: $success. Fail: $fail");
return Update::SUCCESS;
}
// Post-update script of PR 5751 // Post-update script of PR 5751
function update_1298() function update_1298()
{ {
$translateKey = 'sexual'; $keys = ['gender', 'marital', 'sexual'];
$allData = DBA::select('profile', ['id', $translateKey]); foreach ($keys as $translateKey) {
$allLangs = L10n::getAvailableLanguages(); $allData = DBA::select('profile', ['id', $translateKey]);
$success = 0; $allLangs = L10n::getAvailableLanguages();
$fail = 0; $success = 0;
foreach ($allData as $key => $data) { $fail = 0;
$toTranslate = $data[$translateKey]; foreach ($allData as $key => $data) {
if ($toTranslate != '') { $toTranslate = $data[$translateKey];
foreach ($allLangs as $key => $lang) { if ($toTranslate != '') {
$a = new \stdClass(); foreach ($allLangs as $key => $lang) {
$a->strings = []; $a = new \stdClass();
$a->strings = [];
// First we get the the localizations // First we get the the localizations
if (file_exists("view/lang/$lang/strings.php")) { if (file_exists("view/lang/$lang/strings.php")) {
include "view/lang/$lang/strings.php"; include "view/lang/$lang/strings.php";
} }
if (file_exists("addon/morechoice/lang/$lang/strings.php")) { if (file_exists("addon/morechoice/lang/$lang/strings.php")) {
include "addon/morechoice/lang/$lang/strings.php"; include "addon/morechoice/lang/$lang/strings.php";
}
$localizedStrings = $a->strings;
unset($a);
$key = array_search($toTranslate, $localizedStrings);
if ($key !== false) {
break;
}
// defaulting to empty string
$key = '';
} }
$localizedStrings = $a->strings; if ($key == '') {
unset($a); $fail++;
} else {
$key = array_search($toTranslate, $localizedStrings); DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
if ($key !== false) { logger::log('Updated contact ' . $data['id'] . " to $translateKey " . $key .
break; ' (was: ' . $data[$translateKey] . ')');
Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
Contact::updateSelfFromUserID($data['id']);
GContact::updateForUser($data['id']);
$success++;
} }
// defaulting to empty string
$key = '';
}
if ($key == '') {
$fail++;
} else {
DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
logger::log('Updated contact ' . $data['id'] . " to $translateKey " . $key .
' (was: ' . $data[$translateKey] . ')');
Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
Contact::updateSelfFromUserID($data['id']);
GContact::updateForUser($data['id']);
$success++;
} }
} }
}
Logger::log($translateKey . " fix completed. Success: $success. Fail: $fail"); Logger::log($translateKey . " fix completed. Success: $success. Fail: $fail");
}
return Update::SUCCESS; return Update::SUCCESS;
} }