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:
parent
9d7c286252
commit
d326b239ae
2 changed files with 32 additions and 25 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue