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

Allow EditEngine Conduit endpoints to accept object IDs and monograms

Summary:
Ref T9132. This is a quality-of-life improvement for new `application.edit` endpoints.

Instead of strictly requiring PHIDs, allow IDs or monograms. This primarily makes these endpoints easier to test and use.

Test Plan: Edited objects via API by passing IDs, PHIDs and monograms.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9132

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

+87 -9
+80 -6
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 379 379 380 380 381 381 /** 382 + * Try to load an object by ID, PHID, or monogram. This is done primarily 383 + * to make Conduit a little easier to use. 384 + * 385 + * @param wild ID, PHID, or monogram. 386 + * @return object Corresponding editable object. 387 + * @task load 388 + */ 389 + private function newObjectFromIdentifier($identifier) { 390 + if (is_int($identifier) || ctype_digit($identifier)) { 391 + $object = $this->newObjectFromID($identifier); 392 + 393 + if (!$object) { 394 + throw new Exception( 395 + pht( 396 + 'No object exists with ID "%s".', 397 + $identifier)); 398 + } 399 + 400 + return $object; 401 + } 402 + 403 + $type_unknown = PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN; 404 + if (phid_get_type($identifier) != $type_unknown) { 405 + $object = $this->newObjectFromPHID($identifier); 406 + 407 + if (!$object) { 408 + throw new Exception( 409 + pht( 410 + 'No object exists with PHID "%s".', 411 + $identifier)); 412 + } 413 + 414 + return $object; 415 + } 416 + 417 + $target = id(new PhabricatorObjectQuery()) 418 + ->setViewer($this->getViewer()) 419 + ->withNames(array($identifier)) 420 + ->executeOne(); 421 + if (!$target) { 422 + throw new Exception( 423 + pht( 424 + 'Monogram "%s" does not identify a valid object.', 425 + $identifier)); 426 + } 427 + 428 + $expect = $this->newEditableObject(); 429 + $expect_class = get_class($expect); 430 + $target_class = get_class($target); 431 + if ($expect_class !== $target_class) { 432 + throw new Exception( 433 + pht( 434 + 'Monogram "%s" identifies an object of the wrong type. Loaded '. 435 + 'object has class "%s", but this editor operates on objects of '. 436 + 'type "%s".', 437 + $identifier, 438 + $target_class, 439 + $expect_class)); 440 + } 441 + 442 + // Load the object by PHID using this engine's standard query. This makes 443 + // sure it's really valid, goes through standard policy check logic, and 444 + // picks up any `need...()` clauses we want it to load with. 445 + 446 + $object = $this->newObjectFromPHID($target->getPHID()); 447 + if (!$object) { 448 + throw new Exception( 449 + pht( 450 + 'Failed to reload object identified by monogram "%s" when '. 451 + 'querying by PHID.', 452 + $identifier)); 453 + } 454 + 455 + return $object; 456 + } 457 + 458 + /** 382 459 * Load an object by ID. 383 460 * 384 461 * @param int Object ID. ··· 851 928 get_class($this))); 852 929 } 853 930 854 - $phid = $request->getValue('objectPHID'); 855 - if ($phid) { 931 + $identifier = $request->getValue('objectIdentifier'); 932 + if ($identifier) { 856 933 $this->setIsCreate(false); 857 - $object = $this->newObjectFromPHID($phid); 858 - if (!$object) { 859 - throw new Exception(pht('No such object with PHID "%s".', $phid)); 860 - } 934 + $object = $this->newObjectFromIdentifier($identifier); 861 935 } else { 862 936 $this->setIsCreate(true); 863 937 $object = $this->newEditableObject();
+7 -3
src/applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php
··· 22 22 final protected function defineParamTypes() { 23 23 return array( 24 24 'transactions' => 'list<map<string, wild>>', 25 - 'objectPHID' => 'optional phid', 25 + 'objectIdentifier' => 'optional id|phid|string', 26 26 ); 27 27 } 28 28 ··· 90 90 Creating Objects 91 91 ---------------- 92 92 93 - To create an object, pass a list of `transactions` but leave `objectPHID` 93 + To create an object, pass a list of `transactions` but leave `objectIdentifier` 94 94 empty. This will create a new object with the initial field values you 95 95 specify. 96 96 ··· 99 99 --------------- 100 100 101 101 To edit an object, pass a list of `transactions` and specify an object to 102 - apply them to with `objectPHID`. This will apply the changes to the object. 102 + apply them to with `objectIdentifier`. This will apply the changes to the 103 + object. 104 + 105 + You may pass an ID (like `123`), PHID (like `PHID-WXYZ-abcdef...`), or 106 + monogram (like `T123`, for objects which have monograms). 103 107 104 108 105 109 Return Type