<?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());
}
    $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;
    }
    if ($prefs) {
        queryfx($conn_w, 'INSERT INTO %T (phid, userPHID, preferences, dateModified, dateCreated)
        VALUES (%s, %s, %s, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
        ON DUPLICATE KEY UPDATE preferences = VALUES(preferences)', $prefs_table->getTableName(), $prefs_table->generatePHID(), $phid, phutil_json_encode($prefs));
    }
}
$prefs_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES;
PhabricatorUserCache::clearCacheForAllUsers($prefs_key);