<?php $table = new PhabricatorUserPreferences(); $conn_w = $table->establishConnection('w'); foreach (new LiskMigrationIterator($table) as $row) { if ($row->getPHID() !== '') { continue; } queryfx($conn_w, 'UPDATE %T SET phid = %s WHERE id = %d', $table->getTableName(), $table->generatePHID(), $row->getID()); }
<?php $table = new PhabricatorUserPreferences(); $conn_w = $table->establishConnection('w'); // Convert "Mail Format", "Re Prefix" and "Vary Subjects" mail settings to // string constants to avoid weird stuff where we store "true" and "false" as // strings in the database. // Each of these keys will be converted to the first value if present and // truthy, or the second value if present and falsey. $remap = array('html-emails' => array('html', 'text'), 're-prefix' => array('re', 'none'), 'vary-subject' => array('vary', 'static')); foreach (new LiskMigrationIterator($table) as $row) { $dict = $row->getPreferences(); $should_update = false; foreach ($remap as $key => $value) { if (isset($dict[$key])) { if ($dict[$key]) { $dict[$key] = $value[0]; } else { $dict[$key] = $value[1]; } $should_update = true; } } if (!$should_update) { continue; } queryfx($conn_w, 'UPDATE %T SET preferences = %s WHERE id = %d', $table->getTableName(), phutil_json_encode($dict), $row->getID()); } $prefs_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES; PhabricatorUserCache::clearCacheForAllUsers($prefs_key);
<?php // Move timezone, translation and pronoun from the user object to preferences // so they can be defaulted and edited like other settings. $table = new PhabricatorUser(); $conn_w = $table->establishConnection('w'); $table_name = $table->getTableName(); $prefs_table = new PhabricatorUserPreferences(); foreach (new LiskRawMigrationIterator($conn_w, $table_name) as $row) { $phid = $row['phid']; $pref_row = queryfx_one($conn_w, 'SELECT preferences FROM %T WHERE userPHID = %s', $prefs_table->getTableName(), $phid); if ($pref_row) { try { $prefs = phutil_json_decode($pref_row['preferences']); } catch (Exception $ex) { $prefs = array(); } } else { $prefs = array(); } $zone = $row['timezoneIdentifier']; if (strlen($zone)) { $prefs[PhabricatorTimezoneSetting::SETTINGKEY] = $zone; } $pronoun = $row['sex']; if (strlen($pronoun)) { $prefs[PhabricatorPronounSetting::SETTINGKEY] = $pronoun; } $translation = $row['translation']; if (strlen($translation)) { $prefs[PhabricatorTranslationSetting::SETTINGKEY] = $translation;