-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";
+function update_1298()
+{
+ $keys = ['gender', 'marital', 'sexual'];
+ foreach ($keys as $translateKey) {
+ $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::notice('Updated contact', ['action' => 'update', 'contact' => $data['id'], "$translateKey" => $key,
+ 'was' => $data[$translateKey]]);
+ Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
+ Contact::updateSelfFromUserID($data['id']);
+ GContact::updateForUser($data['id']);
+ $success++;
+ }