1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 20:10:55 +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(
PhabricatorApplicationTransaction $xaction) {
$old = json_decode($xaction->getOldValue());
if (!is_array($old)) {
$old = array();
}
$new = json_decode($xaction->getNewValue());
if (!is_array($new)) {
$new = array();
}
$old = $this->decodeValue($xaction->getOldValue());
$new = $this->decodeValue($xaction->getNewValue());
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
@ -113,15 +106,8 @@ abstract class PhabricatorStandardCustomFieldPHIDs
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
$old = json_decode($xaction->getOldValue());
if (!is_array($old)) {
$old = array();
}
$new = json_decode($xaction->getNewValue());
if (!is_array($new)) {
$new = array();
}
$old = $this->decodeValue($xaction->getOldValue());
$new = $this->decodeValue($xaction->getNewValue());
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
@ -167,8 +153,8 @@ abstract class PhabricatorStandardCustomFieldPHIDs
// some invalid or restricted values, but they can't add new ones.
foreach ($xactions as $xaction) {
$old = phutil_json_decode($xaction->getOldValue());
$new = phutil_json_decode($xaction->getNewValue());
$old = $this->decodeValue($xaction->getOldValue());
$new = $this->decodeValue($xaction->getNewValue());
$add = array_diff($new, $old);
@ -231,4 +217,13 @@ abstract class PhabricatorStandardCustomFieldPHIDs
return array();
}
private function decodeValue($value) {
$value = json_decode($value);
if (!is_array($value)) {
$value = array();
}
return $value;
}
}