3 final class PhabricatorUserPreferencesEditor
4 extends PhabricatorApplicationTransactionEditor
{
6 public function getEditorApplicationClass() {
7 return 'PhabricatorSettingsApplication';
10 public function getEditorObjectsDescription() {
11 return pht('Settings');
14 public function getTransactionTypes() {
15 $types = parent
::getTransactionTypes();
17 $types[] = PhabricatorUserPreferencesTransaction
::TYPE_SETTING
;
22 protected function expandTransaction(
23 PhabricatorLiskDAO
$object,
24 PhabricatorApplicationTransaction
$xaction) {
26 $setting_key = $xaction->getMetadataValue(
27 PhabricatorUserPreferencesTransaction
::PROPERTY_SETTING
);
29 $settings = $this->getSettings();
30 $setting = idx($settings, $setting_key);
32 return $setting->expandSettingTransaction($object, $xaction);
35 return parent
::expandTransaction($object, $xaction);
39 protected function getCustomTransactionOldValue(
40 PhabricatorLiskDAO
$object,
41 PhabricatorApplicationTransaction
$xaction) {
43 $setting_key = $xaction->getMetadataValue(
44 PhabricatorUserPreferencesTransaction
::PROPERTY_SETTING
);
46 switch ($xaction->getTransactionType()) {
47 case PhabricatorUserPreferencesTransaction
::TYPE_SETTING
:
48 return $object->getPreference($setting_key);
51 return parent
::getCustomTransactionOldValue($object, $xaction);
54 protected function getCustomTransactionNewValue(
55 PhabricatorLiskDAO
$object,
56 PhabricatorApplicationTransaction
$xaction) {
58 $actor = $this->getActor();
60 $setting_key = $xaction->getMetadataValue(
61 PhabricatorUserPreferencesTransaction
::PROPERTY_SETTING
);
63 $settings = PhabricatorSetting
::getAllEnabledSettings($actor);
64 $setting = $settings[$setting_key];
66 switch ($xaction->getTransactionType()) {
67 case PhabricatorUserPreferencesTransaction
::TYPE_SETTING
:
68 $value = $xaction->getNewValue();
69 $value = $setting->getTransactionNewValue($value);
73 return parent
::getCustomTransactionNewValue($object, $xaction);
76 protected function applyCustomInternalTransaction(
77 PhabricatorLiskDAO
$object,
78 PhabricatorApplicationTransaction
$xaction) {
80 $setting_key = $xaction->getMetadataValue(
81 PhabricatorUserPreferencesTransaction
::PROPERTY_SETTING
);
83 switch ($xaction->getTransactionType()) {
84 case PhabricatorUserPreferencesTransaction
::TYPE_SETTING
:
85 $new_value = $xaction->getNewValue();
86 if ($new_value === null) {
87 $object->unsetPreference($setting_key);
89 $object->setPreference($setting_key, $new_value);
94 return parent
::applyCustomInternalTransaction($object, $xaction);
97 protected function applyCustomExternalTransaction(
98 PhabricatorLiskDAO
$object,
99 PhabricatorApplicationTransaction
$xaction) {
101 switch ($xaction->getTransactionType()) {
102 case PhabricatorUserPreferencesTransaction
::TYPE_SETTING
:
106 return parent
::applyCustomExternalTransaction($object, $xaction);
109 protected function validateTransaction(
110 PhabricatorLiskDAO
$object,
114 $errors = parent
::validateTransaction($object, $type, $xactions);
115 $settings = $this->getSettings();
118 case PhabricatorUserPreferencesTransaction
::TYPE_SETTING
:
119 foreach ($xactions as $xaction) {
120 $setting_key = $xaction->getMetadataValue(
121 PhabricatorUserPreferencesTransaction
::PROPERTY_SETTING
);
123 $setting = idx($settings, $setting_key);
125 $errors[] = new PhabricatorApplicationTransactionValidationError(
129 'There is no known application setting with key "%s".',
136 $setting->validateTransactionValue($xaction->getNewValue());
137 } catch (Exception
$ex) {
138 $errors[] = new PhabricatorApplicationTransactionValidationError(
151 protected function applyFinalEffects(
152 PhabricatorLiskDAO
$object,
155 $user_phid = $object->getUserPHID();
157 PhabricatorUserCache
::clearCache(
158 PhabricatorUserPreferencesCacheType
::KEY_PREFERENCES
,
161 $cache = PhabricatorCaches
::getMutableStructureCache();
162 $cache->deleteKey(PhabricatorUser
::getGlobalSettingsCacheKey());
164 PhabricatorUserCache
::clearCacheForAllUsers(
165 PhabricatorUserPreferencesCacheType
::KEY_PREFERENCES
);
171 private function getSettings() {
172 $actor = $this->getActor();
173 $settings = PhabricatorSetting
::getAllEnabledSettings($actor);
175 foreach ($settings as $key => $setting) {
176 $setting = clone $setting;
177 $setting->setViewer($actor);
178 $settings[$key] = $setting;