1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

Fix two bugs with Config's Edit controller.

Summary:
* When we restored to the default value, we did, in fact delete the row from the
  database, but then a few lines later down, we saved it again. This patch causes
  the controller to return early on delete, like it was supposed to do to begin
  with.
* When checking the user's input value for `null` (since PHP's JSON encoder will
  return `null` on failure), check the value that the user gave, not the value
  that we default to (which is often `null` anyway). Oops.

Test Plan:
* Saved an empty text field and saw the delete work properly and NOT get
  re-added.
* Put `null` in the text field, and saved successfully.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4300
This commit is contained in:
Ricky Elrod 2012-12-30 06:15:41 -08:00 committed by epriestley
parent 250fe7fb77
commit 908253f1db

View file

@ -42,7 +42,7 @@ final class PhabricatorConfigEditController
$new_value = $request->getStr('value'); $new_value = $request->getStr('value');
if (strlen($new_value)) { if (strlen($new_value)) {
$json = json_decode($new_value, true); $json = json_decode($new_value, true);
if ($json === null && strtolower($value) != 'null') { if ($json === null && strtolower($new_value) != 'null') {
$e_value = 'Invalid'; $e_value = 'Invalid';
$errors[] = 'The given value must be valid JSON. This means, among '. $errors[] = 'The given value must be valid JSON. This means, among '.
'other things, that you must wrap strings in double-quotes.'; 'other things, that you must wrap strings in double-quotes.';
@ -53,6 +53,8 @@ final class PhabricatorConfigEditController
} else { } else {
// TODO: When we do Transactions, make this just set isDeleted = 1 // TODO: When we do Transactions, make this just set isDeleted = 1
$config_entry->delete(); $config_entry->delete();
return id(new AphrontRedirectResponse())
->setURI($config_entry->getURI());
} }
$config_entry->setValue($value); $config_entry->setValue($value);