1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

Simplify value decoding for PHID custom fields

Summary:
Ref T9123. The handling in D14183 didn't deal with new field values properly.

Make all this handling more consistent.

Test Plan: Created a new WorkignCopy build plan with some repos.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9123

Differential Revision: https://secure.phabricator.com/D14184
This commit is contained in:
epriestley 2015-09-28 18:44:40 -07:00
parent bfaa93aa9b
commit efaa8170c3

View file

@ -93,15 +93,8 @@ abstract class PhabricatorStandardCustomFieldPHIDs
public function getApplicationTransactionRequiredHandlePHIDs( public function getApplicationTransactionRequiredHandlePHIDs(
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
$old = json_decode($xaction->getOldValue()); $old = $this->decodeValue($xaction->getOldValue());
if (!is_array($old)) { $new = $this->decodeValue($xaction->getNewValue());
$old = array();
}
$new = json_decode($xaction->getNewValue());
if (!is_array($new)) {
$new = array();
}
$add = array_diff($new, $old); $add = array_diff($new, $old);
$rem = array_diff($old, $new); $rem = array_diff($old, $new);
@ -113,15 +106,8 @@ abstract class PhabricatorStandardCustomFieldPHIDs
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID(); $author_phid = $xaction->getAuthorPHID();
$old = json_decode($xaction->getOldValue()); $old = $this->decodeValue($xaction->getOldValue());
if (!is_array($old)) { $new = $this->decodeValue($xaction->getNewValue());
$old = array();
}
$new = json_decode($xaction->getNewValue());
if (!is_array($new)) {
$new = array();
}
$add = array_diff($new, $old); $add = array_diff($new, $old);
$rem = array_diff($old, $new); $rem = array_diff($old, $new);
@ -167,8 +153,8 @@ abstract class PhabricatorStandardCustomFieldPHIDs
// some invalid or restricted values, but they can't add new ones. // some invalid or restricted values, but they can't add new ones.
foreach ($xactions as $xaction) { foreach ($xactions as $xaction) {
$old = phutil_json_decode($xaction->getOldValue()); $old = $this->decodeValue($xaction->getOldValue());
$new = phutil_json_decode($xaction->getNewValue()); $new = $this->decodeValue($xaction->getNewValue());
$add = array_diff($new, $old); $add = array_diff($new, $old);
@ -231,4 +217,13 @@ abstract class PhabricatorStandardCustomFieldPHIDs
return array(); return array();
} }
private function decodeValue($value) {
$value = json_decode($value);
if (!is_array($value)) {
$value = array();
}
return $value;
}
} }