@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move 'set' config option type to new structure

Summary: Ref T12845. This move 'set' options (a set of values).

Test Plan: Set, deleted and mangled 'set' options from CLI and web UI.

Reviewers: chad, amckinley

Reviewed By: amckinley

Maniphest Tasks: T12845

Differential Revision: https://secure.phabricator.com/D18160

+94 -42
+2
src/__phutil_library_map__.php
··· 3943 3943 'PhabricatorSelectSetting' => 'applications/settings/setting/PhabricatorSelectSetting.php', 3944 3944 'PhabricatorSendGridConfigOptions' => 'applications/config/option/PhabricatorSendGridConfigOptions.php', 3945 3945 'PhabricatorSessionsSettingsPanel' => 'applications/settings/panel/PhabricatorSessionsSettingsPanel.php', 3946 + 'PhabricatorSetConfigType' => 'applications/config/type/PhabricatorSetConfigType.php', 3946 3947 'PhabricatorSetting' => 'applications/settings/setting/PhabricatorSetting.php', 3947 3948 'PhabricatorSettingsAccountPanelGroup' => 'applications/settings/panelgroup/PhabricatorSettingsAccountPanelGroup.php', 3948 3949 'PhabricatorSettingsAddEmailAction' => 'applications/settings/action/PhabricatorSettingsAddEmailAction.php', ··· 9469 9470 'PhabricatorSelectSetting' => 'PhabricatorSetting', 9470 9471 'PhabricatorSendGridConfigOptions' => 'PhabricatorApplicationConfigOptions', 9471 9472 'PhabricatorSessionsSettingsPanel' => 'PhabricatorSettingsPanel', 9473 + 'PhabricatorSetConfigType' => 'PhabricatorTextConfigType', 9472 9474 'PhabricatorSetting' => 'Phobject', 9473 9475 'PhabricatorSettingsAccountPanelGroup' => 'PhabricatorSettingsPanelGroup', 9474 9476 'PhabricatorSettingsAddEmailAction' => 'PhabricatorSystemAction',
-9
src/applications/config/controller/PhabricatorConfigEditController.php
··· 347 347 $set_value = null; 348 348 349 349 switch ($type) { 350 - case 'set': 351 - $set_value = array_fill_keys($request->getStrList('value'), true); 352 - break; 353 350 default: 354 351 $json = json_decode($value, true); 355 352 if ($json === null && strtolower($value) != 'null') { ··· 395 392 } else { 396 393 $type = $option->getType(); 397 394 switch ($type) { 398 - case 'set': 399 - return implode("\n", nonempty(array_keys($value), array())); 400 395 default: 401 396 return PhabricatorConfigJSON::prettyPrintJSON($value); 402 397 } ··· 424 419 } else { 425 420 $type = $option->getType(); 426 421 switch ($type) { 427 - case 'set': 428 - $control = id(new AphrontFormTextAreaControl()) 429 - ->setCaption(pht('Separate values with newlines or commas.')); 430 - break; 431 422 default: 432 423 $control = id(new AphrontFormTextAreaControl()) 433 424 ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
-15
src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
··· 76 76 $value = json_decode($value, true); 77 77 if (!is_array($value)) { 78 78 switch ($type) { 79 - case 'set': 80 - $command = csprintf( 81 - './bin/config set %R %s', 82 - $key, 83 - '{"value1": true, "value2": true}'); 84 - 85 - $message = sprintf( 86 - "%s\n\n %s\n", 87 - pht( 88 - 'Config key "%s" is of type "%s". Specify it in JSON. '. 89 - 'For example:', 90 - $key, 91 - $type), 92 - $command); 93 - break; 94 79 default: 95 80 $message = pht( 96 81 'Config key "%s" is of type "%s". Specify it in JSON.',
-18
src/applications/config/option/PhabricatorApplicationConfigOptions.php
··· 43 43 } 44 44 45 45 switch ($option->getType()) { 46 - case 'set': 47 - $valid = true; 48 - if (!is_array($value)) { 49 - throw new PhabricatorConfigValidationException( 50 - pht( 51 - "Option '%s' must be a set, but value is not an array.", 52 - $option->getKey())); 53 - } 54 - foreach ($value as $v) { 55 - if ($v !== true) { 56 - throw new PhabricatorConfigValidationException( 57 - pht( 58 - "Option '%s' must be a set, but array contains values other ". 59 - "than 'true'.", 60 - $option->getKey())); 61 - } 62 - } 63 - break; 64 46 case 'wild': 65 47 default: 66 48 break;
+92
src/applications/config/type/PhabricatorSetConfigType.php
··· 1 + <?php 2 + 3 + final class PhabricatorSetConfigType 4 + extends PhabricatorTextConfigType { 5 + 6 + const TYPEKEY = 'set'; 7 + 8 + protected function newControl(PhabricatorConfigOption $option) { 9 + return id(new AphrontFormTextAreaControl()) 10 + ->setCaption(pht('Separate values with newlines or commas.')); 11 + } 12 + 13 + protected function newCanonicalValue( 14 + PhabricatorConfigOption $option, 15 + $value) { 16 + 17 + $value = preg_split('/[\n,]+/', $value); 18 + foreach ($value as $k => $v) { 19 + if (!strlen($v)) { 20 + unset($value[$k]); 21 + } 22 + $value[$k] = trim($v); 23 + } 24 + 25 + return array_fill_keys($value, true); 26 + } 27 + 28 + public function newValueFromCommandLineValue( 29 + PhabricatorConfigOption $option, 30 + $value) { 31 + 32 + try { 33 + $value = phutil_json_decode($value); 34 + } catch (Exception $ex) { 35 + throw $this->newException( 36 + pht( 37 + 'Option "%s" is of type "%s", but the value you provided is not a '. 38 + 'valid JSON list: when providing a set from the command line, '. 39 + 'specify it as a list of values in JSON. You may need to quote the '. 40 + 'value for your shell (for example: \'["a", "b", ...]\').', 41 + $option->getKey(), 42 + $this->getTypeKey())); 43 + } 44 + 45 + if ($value) { 46 + if (array_keys($value) !== range(0, count($value) - 1)) { 47 + throw $this->newException( 48 + pht( 49 + 'Option "%s" is of type "%s", and should be specified on the '. 50 + 'command line as a JSON list of values. You may need to quote '. 51 + 'the value for your shell (for example: \'["a", "b", ...]\').', 52 + $option->getKey(), 53 + $this->getTypeKey())); 54 + } 55 + } 56 + 57 + return array_fill_keys($value, true); 58 + } 59 + 60 + public function newDisplayValue( 61 + PhabricatorConfigOption $option, 62 + $value) { 63 + return implode("\n", array_keys($value)); 64 + } 65 + 66 + public function validateStoredValue( 67 + PhabricatorConfigOption $option, 68 + $value) { 69 + 70 + if (!is_array($value)) { 71 + throw $this->newException( 72 + pht( 73 + 'Option "%s" is of type "%s", but the configured value is not '. 74 + 'a list.', 75 + $option->getKey(), 76 + $this->getTypeKey())); 77 + } 78 + 79 + foreach ($value as $k => $v) { 80 + if ($v !== true) { 81 + throw $this->newException( 82 + pht( 83 + 'Option "%s" is of type "%s", but the value at index "%s" of the '. 84 + 'list is not "true".', 85 + $option->getKey(), 86 + $this->getTypeKey(), 87 + $k)); 88 + } 89 + } 90 + } 91 + 92 + }