From c7178b7e7b39539a946aa839e190375858d1cf4e Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 23 Mar 2015 09:10:42 -0700 Subject: [PATCH] Move property transaction construction to Almanac Summary: Ref T7627. This centralizes this transaction construction code so the unit tests and Instances can both use it. Test Plan: See D12116. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7627 Differential Revision: https://secure.phabricator.com/D12118 --- .../almanac/storage/AlmanacProperty.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/applications/almanac/storage/AlmanacProperty.php b/src/applications/almanac/storage/AlmanacProperty.php index b20fb14936..9692143d10 100644 --- a/src/applications/almanac/storage/AlmanacProperty.php +++ b/src/applications/almanac/storage/AlmanacProperty.php @@ -31,6 +31,40 @@ final class AlmanacProperty return $this; } + public static function buildTransactions( + AlmanacPropertyInterface $object, + array $properties) { + + $template = $object->getApplicationTransactionTemplate(); + + $attached_properties = $object->getAlmanacProperties(); + foreach ($properties as $key => $value) { + if (empty($attached_properties[$key])) { + $attached_properties[] = id(new AlmanacProperty()) + ->setObjectPHID($object->getPHID()) + ->setFieldName($key); + } + } + $object->attachAlmanacProperties($attached_properties); + + $field_list = PhabricatorCustomField::getObjectFields( + $object, + PhabricatorCustomField::ROLE_DEFAULT); + $fields = $field_list->getFields(); + + $xactions = array(); + foreach ($properties as $name => $property) { + $xactions[] = id(clone $template) + ->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD) + ->setMetadataValue('customfield:key', $name) + ->setOldValue($object->getAlmanacPropertyValue($name)) + ->setNewValue($property); + } + + return $xactions; + } + + /* -( PhabricatorPolicyInterface )----------------------------------------- */