From: Jeroen De Meerleer Date: Tue, 18 Dec 2018 13:42:02 +0000 (+0100) Subject: Added post-update script X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0906c3532ca49a232418c80f6510788bc91cbec6;p=friendica.git Added post-update script Please review first. I don't want to test changes that are not going pass the review. --- diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 9329e31cac..59b6964084 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -7,6 +7,7 @@ namespace Friendica\Database; use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Protocol; +use Friendica\Core\L10n; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\ItemURI; @@ -373,4 +374,49 @@ class PostUpdate return false; } + + // Post-update script of PR 5596 + function fixGenderStrings() { + $allGenders = DBA::select('contact', ['id', 'gender']); + $allLangs = L10n::getAvailableLanguages(); + $success = 0; + $fail = 0; + foreach($allGenders as $key=>$gender) { + 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($gender['gender'], $localizedStrings); + if($key !== false) { + break; + } + + // defaulting to empty string + $key = ''; + } + DBA::update('contact', ['gender' => $key], ['id' => $gender['id']]); + logger::log('Updated contact ' . $gender['id'] . ' to gender ' . $key . ' (was: ' . $gender['gender'] . ')'); + + if ($key == '') { + $fail++; + } + else { + $success++; + } + } + + Logger::log("Gender fix completed. Success: $success. Fail: $fail"); + } }