Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / resources / sql / autopatches / 20160601.user.02.copyprefs.php
blob9edbc117946b09a6cd6617768e2bef007f7ae391
1 <?php
3 // Move timezone, translation and pronoun from the user object to preferences
4 // so they can be defaulted and edited like other settings.
6 $table = new PhabricatorUser();
7 $conn_w = $table->establishConnection('w');
8 $table_name = $table->getTableName();
9 $prefs_table = new PhabricatorUserPreferences();
11 foreach (new LiskRawMigrationIterator($conn_w, $table_name) as $row) {
12 $phid = $row['phid'];
14 $pref_row = queryfx_one(
15 $conn_w,
16 'SELECT preferences FROM %T WHERE userPHID = %s',
17 $prefs_table->getTableName(),
18 $phid);
20 if ($pref_row) {
21 try {
22 $prefs = phutil_json_decode($pref_row['preferences']);
23 } catch (Exception $ex) {
24 $prefs = array();
26 } else {
27 $prefs = array();
30 $zone = $row['timezoneIdentifier'];
31 if (strlen($zone)) {
32 $prefs[PhabricatorTimezoneSetting::SETTINGKEY] = $zone;
35 $pronoun = $row['sex'];
36 if (strlen($pronoun)) {
37 $prefs[PhabricatorPronounSetting::SETTINGKEY] = $pronoun;
40 $translation = $row['translation'];
41 if (strlen($translation)) {
42 $prefs[PhabricatorTranslationSetting::SETTINGKEY] = $translation;
45 if ($prefs) {
46 queryfx(
47 $conn_w,
48 'INSERT INTO %T (phid, userPHID, preferences, dateModified, dateCreated)
49 VALUES (%s, %s, %s, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
50 ON DUPLICATE KEY UPDATE preferences = VALUES(preferences)',
51 $prefs_table->getTableName(),
52 $prefs_table->generatePHID(),
53 $phid,
54 phutil_json_encode($prefs));
58 $prefs_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES;
59 PhabricatorUserCache::clearCacheForAllUsers($prefs_key);