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 )----------------------------------------- */