Differential D16037 Diff 38603 src/applications/settings/controller/PhabricatorSettingsTimezoneController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/controller/PhabricatorSettingsTimezoneController.php
| Show All 21 Lines | foreach ($timezones as $identifier) { | ||||
| if ($offset == $client_offset) { | if ($offset == $client_offset) { | ||||
| $options[$identifier] = $identifier; | $options[$identifier] = $identifier; | ||||
| } | } | ||||
| } | } | ||||
| $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')) | ||||
| ->appendParagraph( | ->appendParagraph( | ||||
| pht( | pht( | ||||
| 'The conflict between your browser and profile timezone '. | 'The conflict between your browser and profile timezone '. | ||||
| 'settings will be ignored.')) | 'settings will be ignored.')) | ||||
| ->appendParagraph($settings_help) | ->appendParagraph($settings_help) | ||||
| ->addCancelButton('/', pht('Done')); | ->addCancelButton('/', pht('Done')); | ||||
| } | } | ||||
| 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( | ||||
| pht( | pht( | ||||
| 'Your browser timezone and profile timezone are now '. | 'Your browser timezone and profile timezone are now '. | ||||
| 'in agreement (%s).', | 'in agreement (%s).', | ||||
| $this->formatOffset($client_offset))) | $this->formatOffset($client_offset))) | ||||
| ->appendParagraph($settings_help) | ->appendParagraph($settings_help) | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | private function formatOffset($offset) { | ||||
| if ($offset >= 0) { | if ($offset >= 0) { | ||||
| return pht('UTC-%d', $offset); | return pht('UTC-%d', $offset); | ||||
| } else { | } else { | ||||
| return pht('UTC+%d', -$offset); | return pht('UTC+%d', -$offset); | ||||
| } | } | ||||
| } | } | ||||
| 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); | |||||
| } | |||||
| } | } | ||||