mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-04 12:42:43 +01:00
ebd8f3c987
Summary: Ref T4103. These are currently stored on the user, for historic/performance reasons. Since I want administrators to be able to set defaults for translations and timezones at a minimum and there's no longer a meaningful performance penalty for moving them off the user record, turn them into real preferences and then nuke the columns. Test Plan: - Set settings to unusual values. - Ran migrations. - Verified my unusual settings survived. - Created a new user. - Edited all settings with old and new UIs. - Reconciled client/server timezone disagreement. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4103 Differential Revision: https://secure.phabricator.com/D16005
73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
abstract class PhabricatorOptionGroupSetting
|
|
extends PhabricatorSetting {
|
|
|
|
abstract protected function getSelectOptionGroups();
|
|
|
|
final protected function getSelectOptionMap() {
|
|
$groups = $this->getSelectOptionGroups();
|
|
|
|
$map = array();
|
|
foreach ($groups as $group) {
|
|
$map += $group['options'];
|
|
}
|
|
|
|
return $map;
|
|
}
|
|
|
|
final protected function newCustomEditField($object) {
|
|
$setting_key = $this->getSettingKey();
|
|
$default_value = $object->getDefaultValue($setting_key);
|
|
|
|
$options = $this->getSelectOptionGroups();
|
|
|
|
$map = $this->getSelectOptionMap();
|
|
if (isset($map[$default_value])) {
|
|
$default_label = pht('Default (%s)', $map[$default_value]);
|
|
} else {
|
|
$default_label = pht('Default (Unknown, "%s")', $default_value);
|
|
}
|
|
|
|
$head_key = head_key($options);
|
|
$options[$head_key]['options'] = array(
|
|
'' => $default_label,
|
|
) + $options[$head_key]['options'];
|
|
|
|
$flat_options = array();
|
|
foreach ($options as $group) {
|
|
$flat_options[$group['label']] = $group['options'];
|
|
}
|
|
|
|
return $this->newEditField($object, new PhabricatorSelectEditField())
|
|
->setOptions($flat_options);
|
|
}
|
|
|
|
final public function validateTransactionValue($value) {
|
|
if (!strlen($value)) {
|
|
return;
|
|
}
|
|
|
|
$map = $this->getSelectOptionMap();
|
|
|
|
if (!isset($map[$value])) {
|
|
throw new Exception(
|
|
pht(
|
|
'Value "%s" is not valid for setting "%s": valid values are %s.',
|
|
$value,
|
|
$this->getSettingName(),
|
|
implode(', ', array_keys($map))));
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
public function getTransactionNewValue($value) {
|
|
if (!strlen($value)) {
|
|
return null;
|
|
}
|
|
|
|
return (string)$value;
|
|
}
|
|
|
|
}
|