Page MenuHomePhorge

No OneTemporary

diff --git a/src/applications/settings/editor/PhabricatorUserPreferencesEditor.php b/src/applications/settings/editor/PhabricatorUserPreferencesEditor.php
index d320391091..918142f95c 100644
--- a/src/applications/settings/editor/PhabricatorUserPreferencesEditor.php
+++ b/src/applications/settings/editor/PhabricatorUserPreferencesEditor.php
@@ -1,160 +1,182 @@
<?php
final class PhabricatorUserPreferencesEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorSettingsApplication';
}
public function getEditorObjectsDescription() {
return pht('Settings');
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorUserPreferencesTransaction::TYPE_SETTING;
return $types;
}
+ protected function expandTransaction(
+ PhabricatorLiskDAO $object,
+ PhabricatorApplicationTransaction $xaction) {
+
+ $setting_key = $xaction->getMetadataValue(
+ PhabricatorUserPreferencesTransaction::PROPERTY_SETTING);
+
+ $settings = $this->getSettings();
+ $setting = idx($settings, $setting_key);
+ if ($setting) {
+ return $setting->expandSettingTransaction($object, $xaction);
+ }
+
+ return parent::expandTransaction($object, $xaction);
+ }
+
+
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
$setting_key = $xaction->getMetadataValue(
PhabricatorUserPreferencesTransaction::PROPERTY_SETTING);
switch ($xaction->getTransactionType()) {
case PhabricatorUserPreferencesTransaction::TYPE_SETTING:
return $object->getPreference($setting_key);
}
return parent::getCustomTransactionOldValue($object, $xaction);
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
$actor = $this->getActor();
$setting_key = $xaction->getMetadataValue(
PhabricatorUserPreferencesTransaction::PROPERTY_SETTING);
$settings = PhabricatorSetting::getAllEnabledSettings($actor);
$setting = $settings[$setting_key];
switch ($xaction->getTransactionType()) {
case PhabricatorUserPreferencesTransaction::TYPE_SETTING:
$value = $xaction->getNewValue();
$value = $setting->getTransactionNewValue($value);
return $value;
}
return parent::getCustomTransactionNewValue($object, $xaction);
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
$setting_key = $xaction->getMetadataValue(
PhabricatorUserPreferencesTransaction::PROPERTY_SETTING);
switch ($xaction->getTransactionType()) {
case PhabricatorUserPreferencesTransaction::TYPE_SETTING:
$new_value = $xaction->getNewValue();
if ($new_value === null) {
$object->unsetPreference($setting_key);
} else {
$object->setPreference($setting_key, $new_value);
}
return;
}
return parent::applyCustomInternalTransaction($object, $xaction);
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorUserPreferencesTransaction::TYPE_SETTING:
return;
}
return parent::applyCustomExternalTransaction($object, $xaction);
}
protected function validateTransaction(
PhabricatorLiskDAO $object,
$type,
array $xactions) {
$errors = parent::validateTransaction($object, $type, $xactions);
-
- $actor = $this->getActor();
- $settings = PhabricatorSetting::getAllEnabledSettings($actor);
-
- foreach ($settings as $key => $setting) {
- $setting = clone $setting;
- $setting->setViewer($actor);
- $settings[$key] = $setting;
- }
+ $settings = $this->getSettings();
switch ($type) {
case PhabricatorUserPreferencesTransaction::TYPE_SETTING:
foreach ($xactions as $xaction) {
$setting_key = $xaction->getMetadataValue(
PhabricatorUserPreferencesTransaction::PROPERTY_SETTING);
$setting = idx($settings, $setting_key);
if (!$setting) {
$errors[] = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Invalid'),
pht(
'There is no known application setting with key "%s".',
$setting_key),
$xaction);
continue;
}
try {
$setting->validateTransactionValue($xaction->getNewValue());
} catch (Exception $ex) {
$errors[] = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Invalid'),
$ex->getMessage(),
$xaction);
}
}
break;
}
return $errors;
}
protected function applyFinalEffects(
PhabricatorLiskDAO $object,
array $xactions) {
$user_phid = $object->getUserPHID();
if ($user_phid) {
PhabricatorUserCache::clearCache(
PhabricatorUserPreferencesCacheType::KEY_PREFERENCES,
$user_phid);
} else {
PhabricatorUserCache::clearCacheForAllUsers(
PhabricatorUserPreferencesCacheType::KEY_PREFERENCES);
}
return $xactions;
}
+ private function getSettings() {
+ $actor = $this->getActor();
+ $settings = PhabricatorSetting::getAllEnabledSettings($actor);
+
+ foreach ($settings as $key => $setting) {
+ $setting = clone $setting;
+ $setting->setViewer($actor);
+ $settings[$key] = $setting;
+ }
+
+ return $settings;
+ }
+
}
diff --git a/src/applications/settings/setting/PhabricatorSetting.php b/src/applications/settings/setting/PhabricatorSetting.php
index 517cc67317..8307d17082 100644
--- a/src/applications/settings/setting/PhabricatorSetting.php
+++ b/src/applications/settings/setting/PhabricatorSetting.php
@@ -1,114 +1,128 @@
<?php
abstract class PhabricatorSetting extends Phobject {
private $viewer;
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
abstract public function getSettingName();
public function getSettingPanelKey() {
return null;
}
protected function getSettingOrder() {
return 1000;
}
public function getSettingOrderVector() {
return id(new PhutilSortVector())
->addInt($this->getSettingOrder())
->addString($this->getSettingName());
}
protected function getControlInstructions() {
return null;
}
protected function isEnabledForViewer(PhabricatorUser $viewer) {
return true;
}
public function getSettingDefaultValue() {
return null;
}
final public function getSettingKey() {
return $this->getPhobjectClassConstant('SETTINGKEY');
}
public static function getAllSettings() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getSettingKey')
->execute();
}
public static function getAllEnabledSettings(PhabricatorUser $viewer) {
$settings = self::getAllSettings();
foreach ($settings as $key => $setting) {
if (!$setting->isEnabledForViewer($viewer)) {
unset($settings[$key]);
}
}
return $settings;
}
final public function newCustomEditFields($object) {
$fields = array();
$field = $this->newCustomEditField($object);
if ($field) {
$fields[] = $field;
}
return $fields;
}
protected function newCustomEditField($object) {
return null;
}
protected function newEditField($object, PhabricatorEditField $template) {
$setting_property = PhabricatorUserPreferencesTransaction::PROPERTY_SETTING;
$setting_key = $this->getSettingKey();
$value = $object->getPreference($setting_key);
$xaction_type = PhabricatorUserPreferencesTransaction::TYPE_SETTING;
$label = $this->getSettingName();
$template
->setKey($setting_key)
->setLabel($label)
->setValue($value)
->setTransactionType($xaction_type)
->setMetadataValue($setting_property, $setting_key);
$instructions = $this->getControlInstructions();
if (strlen($instructions)) {
$template->setControlInstructions($instructions);
}
return $template;
}
public function validateTransactionValue($value) {
return;
}
public function assertValidValue($value) {
$this->validateTransactionValue($value);
}
public function getTransactionNewValue($value) {
return $value;
}
+ public function expandSettingTransaction($object, $xaction) {
+ return array($xaction);
+ }
+
+ protected function newSettingTransaction($object, $key, $value) {
+ $setting_property = PhabricatorUserPreferencesTransaction::PROPERTY_SETTING;
+ $xaction_type = PhabricatorUserPreferencesTransaction::TYPE_SETTING;
+
+ return id(clone $object->getApplicationTransactionTemplate())
+ ->setTransactionType($xaction_type)
+ ->setMetadataValue($setting_property, $key)
+ ->setNewValue($value);
+ }
+
}
diff --git a/src/applications/settings/setting/PhabricatorTimezoneSetting.php b/src/applications/settings/setting/PhabricatorTimezoneSetting.php
index e68849e2ae..b7a6b94e30 100644
--- a/src/applications/settings/setting/PhabricatorTimezoneSetting.php
+++ b/src/applications/settings/setting/PhabricatorTimezoneSetting.php
@@ -1,90 +1,102 @@
<?php
final class PhabricatorTimezoneSetting
extends PhabricatorOptionGroupSetting {
const SETTINGKEY = 'timezone';
public function getSettingName() {
return pht('Timezone');
}
public function getSettingPanelKey() {
return PhabricatorDateTimeSettingsPanel::PANELKEY;
}
protected function getSettingOrder() {
return 100;
}
protected function getControlInstructions() {
return pht('Select your local timezone.');
}
public function getSettingDefaultValue() {
return date_default_timezone_get();
}
public function assertValidValue($value) {
// NOTE: This isn't doing anything fancy, it's just a much faster
// validator than doing all the timezone calculations to build the full
// list of options.
if (!$value) {
return;
}
static $identifiers;
if ($identifiers === null) {
$identifiers = DateTimeZone::listIdentifiers();
$identifiers = array_fuse($identifiers);
}
if (isset($identifiers[$value])) {
return;
}
throw new Exception(
pht(
'Timezone "%s" is not a valid timezone identiifer.',
$value));
}
protected function getSelectOptionGroups() {
$timezones = DateTimeZone::listIdentifiers();
$now = new DateTime('@'.PhabricatorTime::getNow());
$groups = array();
foreach ($timezones as $timezone) {
$zone = new DateTimeZone($timezone);
$offset = -($zone->getOffset($now) / (60 * 60));
$groups[$offset][] = $timezone;
}
krsort($groups);
$option_groups = array(
array(
'label' => pht('Default'),
'options' => array(),
),
);
foreach ($groups as $offset => $group) {
if ($offset >= 0) {
$label = pht('UTC-%d', $offset);
} else {
$label = pht('UTC+%d', -$offset);
}
sort($group);
$option_groups[] = array(
'label' => $label,
'options' => array_fuse($group),
);
}
return $option_groups;
}
+ public function expandSettingTransaction($object, $xaction) {
+ // When the user changes their timezone, we also clear any ignored
+ // timezone offset.
+ return array(
+ $xaction,
+ $this->newSettingTransaction(
+ $object,
+ PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY,
+ null),
+ );
+ }
+
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 18:58 (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1127621
Default Alt Text
(12 KB)

Event Timeline