]> git.mxchange.org Git - friendica.git/blobdiff - update.php
Updated towards code review
[friendica.git] / update.php
index 22d1809fea8ef75e4cc8af9f96043c255e420dbf..2b1bd2bbe89156f019161f1cc411401e095816a7 100644 (file)
@@ -254,3 +254,49 @@ function update_1288() {
 
        return Update::SUCCESS;
 }
+
+       
+// Post-update script of PR 5751
+function update_1293() {
+       $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");
+       return Update::SUCCESS;
+}
\ No newline at end of file