From 8e263a2f6482203322de9ee5c0ec5664afa260c5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 31 Jul 2019 12:40:56 -0700 Subject: [PATCH] Support "date" custom fields in "*.edit" endpoints Summary: Fixes T13355. This didn't appear to be a ton of extra work, we just didn't get it for free in the original implementation in D14635. Test Plan: - Saw "date" custom fields appear in Conduit API documentation for "maniphest.edit". - Set custom "date" field to null and non-null values via the API. {F6666582} Maniphest Tasks: T13355 Differential Revision: https://secure.phabricator.com/D20690 --- .../parametertype/ConduitEpochParameterType.php | 16 ++++++++++++++++ .../editfield/PhabricatorEpochEditField.php | 3 ++- .../PhabricatorStandardCustomFieldDate.php | 10 ++-------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/applications/conduit/parametertype/ConduitEpochParameterType.php b/src/applications/conduit/parametertype/ConduitEpochParameterType.php index e8fe095c50..8f2ca2c98a 100644 --- a/src/applications/conduit/parametertype/ConduitEpochParameterType.php +++ b/src/applications/conduit/parametertype/ConduitEpochParameterType.php @@ -3,8 +3,24 @@ final class ConduitEpochParameterType extends ConduitParameterType { + private $allowNull; + + public function setAllowNull($allow_null) { + $this->allowNull = $allow_null; + return $this; + } + + public function getAllowNull() { + return $this->allowNull; + } + protected function getParameterValue(array $request, $key, $strict) { $value = parent::getParameterValue($request, $key, $strict); + + if ($this->allowNull && ($value === null)) { + return $value; + } + $value = $this->parseIntValue($request, $key, $value, $strict); if ($value <= 0) { diff --git a/src/applications/transactions/editfield/PhabricatorEpochEditField.php b/src/applications/transactions/editfield/PhabricatorEpochEditField.php index 9ac9726593..b50f013177 100644 --- a/src/applications/transactions/editfield/PhabricatorEpochEditField.php +++ b/src/applications/transactions/editfield/PhabricatorEpochEditField.php @@ -37,7 +37,8 @@ final class PhabricatorEpochEditField } protected function newConduitParameterType() { - return new ConduitEpochParameterType(); + return id(new ConduitEpochParameterType()) + ->setAllowNull($this->getAllowNull()); } } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php index 994bb99403..4aba7543e7 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php @@ -226,20 +226,14 @@ final class PhabricatorStandardCustomFieldDate } } - - public function shouldAppearInConduitTransactions() { - // TODO: Dates are complicated and we don't yet support handling them from - // Conduit. - return false; - } - protected function newConduitSearchParameterType() { // TODO: Build a new "pair" type or similar. return null; } protected function newConduitEditParameterType() { - return new ConduitEpochParameterType(); + return id(new ConduitEpochParameterType()) + ->setAllowNull(!$this->getRequired()); } protected function newExportFieldType() {