@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.

Normalize validation/requried API

Summary: Makes Maniphest look more like standard fields to make the migration easier.

Test Plan: Edited tasks and users with required and invalid fields.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

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

+76 -76
-2
src/__phutil_library_map__.php
··· 1063 1063 'PhabricatorCustomFieldNumericIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldNumericIndexStorage.php', 1064 1064 'PhabricatorCustomFieldStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php', 1065 1065 'PhabricatorCustomFieldStringIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php', 1066 - 'PhabricatorCustomFieldValidationException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldValidationException.php', 1067 1066 'PhabricatorDaemon' => 'infrastructure/daemon/PhabricatorDaemon.php', 1068 1067 'PhabricatorDaemonCombinedLogController' => 'applications/daemon/controller/PhabricatorDaemonCombinedLogController.php', 1069 1068 'PhabricatorDaemonConsoleController' => 'applications/daemon/controller/PhabricatorDaemonConsoleController.php', ··· 3182 3181 'PhabricatorCustomFieldNumericIndexStorage' => 'PhabricatorCustomFieldIndexStorage', 3183 3182 'PhabricatorCustomFieldStorage' => 'PhabricatorLiskDAO', 3184 3183 'PhabricatorCustomFieldStringIndexStorage' => 'PhabricatorCustomFieldIndexStorage', 3185 - 'PhabricatorCustomFieldValidationException' => 'Exception', 3186 3184 'PhabricatorDaemon' => 'PhutilDaemon', 3187 3185 'PhabricatorDaemonCombinedLogController' => 'PhabricatorDaemonController', 3188 3186 'PhabricatorDaemonConsoleController' => 'PhabricatorDaemonController',
+53 -33
src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldDefaultSpecification.php
··· 273 273 return $this->setValue($value); 274 274 } 275 275 276 - public function validate() { 277 - switch ($this->getFieldType()) { 278 - case self::TYPE_INT: 279 - if ($this->getValue() && !is_numeric($this->getValue())) { 280 - throw new PhabricatorCustomFieldValidationException( 281 - pht( 282 - '%s must be an integer value.', 283 - $this->getLabel())); 284 - } 285 - break; 286 - case self::TYPE_BOOL: 287 - return true; 288 - case self::TYPE_STRING: 289 - return true; 290 - case self::TYPE_SELECT: 291 - return true; 292 - case self::TYPE_DATE: 293 - if ((int)$this->getValue() <= 0 && $this->isRequired()) { 294 - throw new PhabricatorCustomFieldValidationException( 295 - pht( 296 - '%s must be a valid date.', 297 - $this->getLabel())); 298 - } 299 - break; 300 - case self::TYPE_USER: 301 - case self::TYPE_USERS: 302 - if (!is_array($this->getValue())) { 303 - throw new PhabricatorCustomFieldValidationException( 304 - pht( 305 - '%s is not a valid list of user PHIDs.', 306 - $this->getLabel())); 307 - } 308 - break; 276 + public function validateApplicationTransactions( 277 + PhabricatorApplicationTransactionEditor $editor, 278 + $type, 279 + array $xactions) { 280 + 281 + $errors = parent::validateApplicationTransactions( 282 + $editor, 283 + $type, 284 + $xactions); 285 + 286 + $has_value = false; 287 + $value = null; 288 + foreach ($xactions as $xaction) { 289 + $has_value = true; 290 + $value = $xaction->getNewValue(); 291 + switch ($this->getFieldType()) { 292 + case self::TYPE_INT: 293 + if ($value && !is_numeric($value)) { 294 + $errors[] = new PhabricatorApplicationTransactionValidationError( 295 + $type, 296 + pht('Invalid'), 297 + pht('%s must be an integer value.', $this->getLabel()), 298 + $xaction); 299 + $this->setError(pht('Invalid')); 300 + } 301 + break; 302 + case self::TYPE_DATE: 303 + if ((int)$value <= 0 && $this->isRequired()) { 304 + $errors[] = new PhabricatorApplicationTransactionValidationError( 305 + $type, 306 + pht('Invalid'), 307 + pht('%s must be a valid date.', $this->getLabel()), 308 + $xaction); 309 + $this->setError(pht('Invalid')); 310 + } 311 + break; 312 + } 309 313 } 314 + 315 + if ($this->isRequired()) { 316 + if (!$has_value) { 317 + $value = $this->getOldValueForApplicationTransactions(); 318 + } 319 + if (!$value) { 320 + $errors[] = new PhabricatorApplicationTransactionValidationError( 321 + $type, 322 + pht('Required'), 323 + pht('%s is required.', $this->getLabel()), 324 + null); 325 + $this->setError(pht('Required')); 326 + } 327 + } 328 + 329 + return $errors; 310 330 } 311 331 312 332 public function setDefaultValue($value) {
+5 -5
src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldSpecification.php
··· 63 63 return $this->value; 64 64 } 65 65 66 - public function validate() { 67 - return true; 68 - } 69 - 70 66 public function isRequired() { 71 67 return false; 72 68 } ··· 173 169 } 174 170 175 171 public function renderPropertyViewValue() { 176 - return $this->renderForDetailView(); 172 + $value = $this->renderForDetailView(); 173 + if (!strlen($value)) { 174 + return null; 175 + } 176 + return $value; 177 177 } 178 178 179 179 public function renderPropertyViewLabel() {
+16 -20
src/applications/maniphest/controller/ManiphestTaskEditController.php
··· 142 142 $aux_field->readValueFromRequest($request); 143 143 $aux_new_value = $aux_field->getNewValueForApplicationTransactions(); 144 144 145 - // TODO: What's going on here? 146 - if ((int)$aux_old_value === $aux_new_value) { 147 - unset($aux_fields[$aux_arr_key]); 148 - continue; 149 - } 145 + // TODO: We're faking a call to the ApplicaitonTransaction validation 146 + // logic here. We need valid objects to pass, but they aren't used 147 + // in a meaningful way. For now, build User objects. Once the Maniphest 148 + // objects exist, this will switch over automatically. This is a big 149 + // hack but shouldn't be long for this world. 150 + $placeholder_editor = new PhabricatorUserProfileEditor(); 150 151 151 - if ($aux_field->isRequired() && !$aux_field->getValue()) { 152 - $errors[] = pht('%s is required.', $aux_field->getLabel()); 153 - $aux_field->setError(pht('Required')); 154 - } 152 + $field_errors = $aux_field->validateApplicationTransactions( 153 + $placeholder_editor, 154 + PhabricatorTransactions::TYPE_CUSTOMFIELD, 155 + array( 156 + id(new PhabricatorUserTransaction()) 157 + ->setOldValue($aux_old_value) 158 + ->setNewValue($aux_new_value), 159 + )); 155 160 156 - try { 157 - $aux_field->validate(); 158 - } catch (Exception $e) { 159 - $errors[] = $e->getMessage(); 160 - $aux_field->setError(pht('Invalid')); 161 + foreach ($field_errors as $error) { 162 + $errors[] = $error->getMessage(); 161 163 } 162 164 163 165 $old_values[$aux_field->getFieldKey()] = $aux_old_value; ··· 490 492 ->setDatasource('/typeahead/common/projects/')); 491 493 492 494 foreach ($aux_fields as $aux_field) { 493 - if ($aux_field->isRequired() && 494 - !$aux_field->getError() && 495 - !$aux_field->getValue()) { 496 - $aux_field->setError(true); 497 - } 498 - 499 495 $aux_control = $aux_field->renderEditControl(); 500 496 $form->appendChild($aux_control); 501 497 }
-8
src/applications/maniphest/field/ManiphestCustomField.php
··· 36 36 public function setHandles(array $handles) { 37 37 } 38 38 39 - public function isRequired() { 40 - return false; 41 - } 42 - 43 - public function validate() { 44 - return true; 45 - } 46 - 47 39 /** 48 40 * Render a verb to appear in email titles when a transaction involving this 49 41 * field occurs. Specifically, Maniphest emails are formatted like this:
-6
src/infrastructure/customfield/exception/PhabricatorCustomFieldValidationException.php
··· 1 - <?php 2 - 3 - final class PhabricatorCustomFieldValidationException 4 - extends Exception { 5 - 6 - }
+1 -1
src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php
··· 271 271 $xactions); 272 272 273 273 if ($this->getRequired()) { 274 - $value = null; 274 + $value = $this->getOldValueForApplicationTransactions(); 275 275 $transaction = null; 276 276 foreach ($xactions as $xaction) { 277 277 $value = $xaction->getNewValue();
+1 -1
src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php
··· 63 63 ->setName($this->getFieldKey()) 64 64 ->setUser($this->getViewer()) 65 65 ->setCaption($this->getCaption()) 66 - ->setAllowNull(true); 66 + ->setAllowNull(!$this->getRequired()); 67 67 68 68 $control->setValue($this->getFieldValue()); 69 69