diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index 0640f3c1b2..3cfa7bd2bc 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -533,20 +533,6 @@ final class PhabricatorUser return ($actual == $value); } - - /** - * @task settings - */ - public function clearUserSettingCache() { - $this->settingCacheKeys = array(); - $this->settingCache = array(); - - $settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES; - $this->clearCacheData($settings_key); - - return $this; - } - private function writeUserSettingCache($key, $value) { $this->settingCacheKeys[$key] = true; $this->settingCache[$key] = $value; diff --git a/src/applications/settings/controller/PhabricatorSettingsTimezoneController.php b/src/applications/settings/controller/PhabricatorSettingsTimezoneController.php index 4f34c39fa0..2e2e174e0f 100644 --- a/src/applications/settings/controller/PhabricatorSettingsTimezoneController.php +++ b/src/applications/settings/controller/PhabricatorSettingsTimezoneController.php @@ -27,18 +27,18 @@ final class PhabricatorSettingsTimezoneController $settings_help = pht( 'You can change your date and time preferences in Settings.'); + $did_calibrate = false; if ($request->isFormPost()) { $timezone = $request->getStr('timezone'); $pref_ignore = PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY; $pref_timezone = PhabricatorTimezoneSetting::SETTINGKEY; - $preferences = $viewer->loadPreferences(); - if ($timezone == 'ignore') { - $preferences - ->setPreference($pref_ignore, $client_offset) - ->save(); + $this->writeSettings( + array( + $pref_ignore => $client_offset, + )); return $this->newDialog() ->setTitle(pht('Conflict Ignored')) @@ -51,18 +51,19 @@ final class PhabricatorSettingsTimezoneController } if (isset($options[$timezone])) { - $preferences - ->setPreference($pref_ignore, null) - ->setPreference($pref_timezone, $timezone) - ->save(); + $this->writeSettings( + array( + $pref_ignore => null, + $pref_timezone => $timezone, + )); - $viewer->clearUserSettingCache(); + $did_calibrate = true; } } $server_offset = $viewer->getTimeZoneOffset(); - if ($client_offset == $server_offset) { + if ($client_offset == $server_offset || $did_calibrate) { return $this->newDialog() ->setTitle(pht('Timezone Calibrated')) ->appendParagraph( @@ -121,4 +122,24 @@ final class PhabricatorSettingsTimezoneController } } + private function writeSettings(array $map) { + $request = $this->getRequest(); + $viewer = $this->getViewer(); + + $preferences = PhabricatorUserPreferences::loadUserPreferences($viewer); + + $editor = id(new PhabricatorUserPreferencesEditor()) + ->setActor($viewer) + ->setContentSourceFromRequest($request) + ->setContinueOnNoEffect(true) + ->setContinueOnMissingFields(true); + + $xactions = array(); + foreach ($map as $key => $value) { + $xactions[] = $preferences->newTransaction($key, $value); + } + + $editor->applyTransactions($preferences, $xactions); + } + }