1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 05:12:41 +01:00

Resolve timezone conflicts in a modern transactional way

Summary: Ref T4103. Also get rid of the weird cache clear that nothing else uses and which we don't actually need.

Test Plan:
  - Resolved timezone conflict by ignoring it.
  - Resolved timezone conflict by picking a valid timezone.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4103

Differential Revision: https://secure.phabricator.com/D16037
This commit is contained in:
epriestley 2016-06-04 15:08:30 -07:00
parent 9d7c286252
commit d326b239ae
2 changed files with 32 additions and 25 deletions

View file

@ -533,20 +533,6 @@ final class PhabricatorUser
return ($actual == $value); 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) { private function writeUserSettingCache($key, $value) {
$this->settingCacheKeys[$key] = true; $this->settingCacheKeys[$key] = true;
$this->settingCache[$key] = $value; $this->settingCache[$key] = $value;

View file

@ -27,18 +27,18 @@ final class PhabricatorSettingsTimezoneController
$settings_help = pht( $settings_help = pht(
'You can change your date and time preferences in Settings.'); 'You can change your date and time preferences in Settings.');
$did_calibrate = false;
if ($request->isFormPost()) { if ($request->isFormPost()) {
$timezone = $request->getStr('timezone'); $timezone = $request->getStr('timezone');
$pref_ignore = PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY; $pref_ignore = PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY;
$pref_timezone = PhabricatorTimezoneSetting::SETTINGKEY; $pref_timezone = PhabricatorTimezoneSetting::SETTINGKEY;
$preferences = $viewer->loadPreferences();
if ($timezone == 'ignore') { if ($timezone == 'ignore') {
$preferences $this->writeSettings(
->setPreference($pref_ignore, $client_offset) array(
->save(); $pref_ignore => $client_offset,
));
return $this->newDialog() return $this->newDialog()
->setTitle(pht('Conflict Ignored')) ->setTitle(pht('Conflict Ignored'))
@ -51,18 +51,19 @@ final class PhabricatorSettingsTimezoneController
} }
if (isset($options[$timezone])) { if (isset($options[$timezone])) {
$preferences $this->writeSettings(
->setPreference($pref_ignore, null) array(
->setPreference($pref_timezone, $timezone) $pref_ignore => null,
->save(); $pref_timezone => $timezone,
));
$viewer->clearUserSettingCache(); $did_calibrate = true;
} }
} }
$server_offset = $viewer->getTimeZoneOffset(); $server_offset = $viewer->getTimeZoneOffset();
if ($client_offset == $server_offset) { if ($client_offset == $server_offset || $did_calibrate) {
return $this->newDialog() return $this->newDialog()
->setTitle(pht('Timezone Calibrated')) ->setTitle(pht('Timezone Calibrated'))
->appendParagraph( ->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);
}
} }