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

Give EditEngine a Conduit-specific initialization pathway for objects

Summary:
Depends on D18845. See PHI243 for context and more details.

Briefly, some objects need a "type" transaction (or something similar) very early on, and we can't generate their fields until we know the object type. Drydock blueprints are an example: a blueprint's fields depend on the blueprint's type.

In web interfaces, the workflow just forces the user to select a type first. For Conduit workflows, I think the cleanest approach is to proactively extract and apply type information before processing the request. This will make the implementation a little messier, but the API cleaner.

An alternative is to add more fields to the API, like a "type" field. This makes the implementation cleaner, but the API messier. I think we're better off favoring a cleaner API here.

This change just makes it possible for `DrydockBlueprintEditEngine` to look at the incoming transactions and extract a "type"; it doesn't actually change any behavior.

Test Plan: Performed edits via API, but this change doesn't alter any behavior.

Reviewers: amckinley

Reviewed By: amckinley

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

+46 -21
+46 -21
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 631 631 } 632 632 633 633 /** 634 + * Initialize a new object for object creation via Conduit. 635 + * 636 + * @return object Newly initialized object. 637 + * @param list<wild> Raw transactions. 638 + * @task load 639 + */ 640 + protected function newEditableObjectFromConduit(array $raw_xactions) { 641 + return $this->newEditableObject(); 642 + } 643 + 644 + /** 634 645 * Initialize a new object for documentation creation. 635 646 * 636 647 * @return object Newly initialized object. ··· 2031 2042 get_class($this))); 2032 2043 } 2033 2044 2045 + $raw_xactions = $this->getRawConduitTransactions($request); 2046 + 2034 2047 $identifier = $request->getValue('objectIdentifier'); 2035 2048 if ($identifier) { 2036 2049 $this->setIsCreate(false); ··· 2039 2052 $this->requireCreateCapability(); 2040 2053 2041 2054 $this->setIsCreate(true); 2042 - $object = $this->newEditableObject(); 2055 + $object = $this->newEditableObjectFromConduit($raw_xactions); 2043 2056 } 2044 2057 2045 2058 $this->validateObject($object); ··· 2049 2062 $types = $this->getConduitEditTypesFromFields($fields); 2050 2063 $template = $object->getApplicationTransactionTemplate(); 2051 2064 2052 - $xactions = $this->getConduitTransactions($request, $types, $template); 2065 + $xactions = $this->getConduitTransactions( 2066 + $request, 2067 + $raw_xactions, 2068 + $types, 2069 + $template); 2053 2070 2054 2071 $editor = $object->getApplicationTransactionEditor() 2055 2072 ->setActor($viewer) ··· 2078 2095 ); 2079 2096 } 2080 2097 2081 - 2082 - /** 2083 - * Generate transactions which can be applied from edit actions in a Conduit 2084 - * request. 2085 - * 2086 - * @param ConduitAPIRequest The request. 2087 - * @param list<PhabricatorEditType> Supported edit types. 2088 - * @param PhabricatorApplicationTransaction Template transaction. 2089 - * @return list<PhabricatorApplicationTransaction> Generated transactions. 2090 - * @task conduit 2091 - */ 2092 - private function getConduitTransactions( 2093 - ConduitAPIRequest $request, 2094 - array $types, 2095 - PhabricatorApplicationTransaction $template) { 2096 - 2097 - $viewer = $request->getUser(); 2098 + private function getRawConduitTransactions(ConduitAPIRequest $request) { 2098 2099 $transactions_key = 'transactions'; 2099 2100 2100 2101 $xactions = $request->getValue($transactions_key); ··· 2124 2125 $transactions_key, 2125 2126 $key)); 2126 2127 } 2128 + } 2127 2129 2130 + return $xactions; 2131 + } 2132 + 2133 + 2134 + /** 2135 + * Generate transactions which can be applied from edit actions in a Conduit 2136 + * request. 2137 + * 2138 + * @param ConduitAPIRequest The request. 2139 + * @param list<wild> Raw conduit transactions. 2140 + * @param list<PhabricatorEditType> Supported edit types. 2141 + * @param PhabricatorApplicationTransaction Template transaction. 2142 + * @return list<PhabricatorApplicationTransaction> Generated transactions. 2143 + * @task conduit 2144 + */ 2145 + private function getConduitTransactions( 2146 + ConduitAPIRequest $request, 2147 + array $xactions, 2148 + array $types, 2149 + PhabricatorApplicationTransaction $template) { 2150 + 2151 + $viewer = $request->getUser(); 2152 + $results = array(); 2153 + 2154 + foreach ($xactions as $key => $xaction) { 2128 2155 $type = $xaction['type']; 2129 2156 if (empty($types[$type])) { 2130 2157 throw new Exception( ··· 2136 2163 implode(', ', array_keys($types)))); 2137 2164 } 2138 2165 } 2139 - 2140 - $results = array(); 2141 2166 2142 2167 if ($this->getIsCreate()) { 2143 2168 $results[] = id(clone $template)