Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15446991
D14600.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D14600.id.diff
View Options
diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php
--- a/src/applications/transactions/editengine/PhabricatorEditEngine.php
+++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php
@@ -379,6 +379,83 @@
/**
+ * Try to load an object by ID, PHID, or monogram. This is done primarily
+ * to make Conduit a little easier to use.
+ *
+ * @param wild ID, PHID, or monogram.
+ * @return object Corresponding editable object.
+ * @task load
+ */
+ private function newObjectFromIdentifier($identifier) {
+ if (is_int($identifier) || ctype_digit($identifier)) {
+ $object = $this->newObjectFromID($identifier);
+
+ if (!$object) {
+ throw new Exception(
+ pht(
+ 'No object exists with ID "%s".',
+ $identifier));
+ }
+
+ return $object;
+ }
+
+ $type_unknown = PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN;
+ if (phid_get_type($identifier) != $type_unknown) {
+ $object = $this->newObjectFromPHID($identifier);
+
+ if (!$object) {
+ throw new Exception(
+ pht(
+ 'No object exists with PHID "%s".',
+ $identifier));
+ }
+
+ return $object;
+ }
+
+ $target = id(new PhabricatorObjectQuery())
+ ->setViewer($this->getViewer())
+ ->withNames(array($identifier))
+ ->executeOne();
+ if (!$target) {
+ throw new Exception(
+ pht(
+ 'Monogram "%s" does not identify a valid object.',
+ $identifier));
+ }
+
+ $expect = $this->newEditableObject();
+ $expect_class = get_class($expect);
+ $target_class = get_class($target);
+ if ($expect_class !== $target_class) {
+ throw new Exception(
+ pht(
+ 'Monogram "%s" identifies an object of the wrong type. Loaded '.
+ 'object has class "%s", but this editor operates on objects of '.
+ 'type "%s".',
+ $identifier,
+ $target_class,
+ $expect_class));
+ }
+
+ // Load the object by PHID using this engine's standard query. This makes
+ // sure it's really valid, goes through standard policy check logic, and
+ // picks up any `need...()` clauses we want it to load with.
+
+ $object = $this->newObjectFromPHID($target->getPHID());
+ if (!$object) {
+ throw new Exception(
+ pht(
+ 'Failed to reload object identified by monogram "%s" when '.
+ 'querying by PHID.',
+ $identifier));
+ }
+
+ return $object;
+ }
+
+ /**
* Load an object by ID.
*
* @param int Object ID.
@@ -851,13 +928,10 @@
get_class($this)));
}
- $phid = $request->getValue('objectPHID');
- if ($phid) {
+ $identifier = $request->getValue('objectIdentifier');
+ if ($identifier) {
$this->setIsCreate(false);
- $object = $this->newObjectFromPHID($phid);
- if (!$object) {
- throw new Exception(pht('No such object with PHID "%s".', $phid));
- }
+ $object = $this->newObjectFromIdentifier($identifier);
} else {
$this->setIsCreate(true);
$object = $this->newEditableObject();
diff --git a/src/applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php b/src/applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php
--- a/src/applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php
+++ b/src/applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php
@@ -22,7 +22,7 @@
final protected function defineParamTypes() {
return array(
'transactions' => 'list<map<string, wild>>',
- 'objectPHID' => 'optional phid',
+ 'objectIdentifier' => 'optional id|phid|string',
);
}
@@ -90,7 +90,7 @@
Creating Objects
----------------
-To create an object, pass a list of `transactions` but leave `objectPHID`
+To create an object, pass a list of `transactions` but leave `objectIdentifier`
empty. This will create a new object with the initial field values you
specify.
@@ -99,7 +99,11 @@
---------------
To edit an object, pass a list of `transactions` and specify an object to
-apply them to with `objectPHID`. This will apply the changes to the object.
+apply them to with `objectIdentifier`. This will apply the changes to the
+object.
+
+You may pass an ID (like `123`), PHID (like `PHID-WXYZ-abcdef...`), or
+monogram (like `T123`, for objects which have monograms).
Return Type
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 28, 9:15 PM (6 d, 13 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7705874
Default Alt Text
D14600.id.diff (4 KB)
Attached To
Mode
D14600: Allow EditEngine Conduit endpoints to accept object IDs and monograms
Attached
Detach File
Event Timeline
Log In to Comment