Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
| Show First 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | /* -( Creating and Loading Objects )--------------------------------------- */ | ||||
| */ | */ | ||||
| private function setIsCreate($is_create) { | private function setIsCreate($is_create) { | ||||
| $this->isCreate = $is_create; | $this->isCreate = $is_create; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * 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. | * Load an object by ID. | ||||
| * | * | ||||
| * @param int Object ID. | * @param int Object ID. | ||||
| * @return object|null Object, or null if no such object exists. | * @return object|null Object, or null if no such object exists. | ||||
| * @task load | * @task load | ||||
| */ | */ | ||||
| private function newObjectFromID($id) { | private function newObjectFromID($id) { | ||||
| $query = $this->newObjectQuery() | $query = $this->newObjectQuery() | ||||
| ▲ Show 20 Lines • Show All 456 Lines • ▼ Show 20 Lines | final public function buildConduitResponse(ConduitAPIRequest $request) { | ||||
| $config = $this->loadEditEngineConfiguration(null); | $config = $this->loadEditEngineConfiguration(null); | ||||
| if (!$config) { | if (!$config) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Unable to load configuration for this EditEngine ("%s").', | 'Unable to load configuration for this EditEngine ("%s").', | ||||
| get_class($this))); | get_class($this))); | ||||
| } | } | ||||
| $phid = $request->getValue('objectPHID'); | $identifier = $request->getValue('objectIdentifier'); | ||||
| if ($phid) { | if ($identifier) { | ||||
| $this->setIsCreate(false); | $this->setIsCreate(false); | ||||
| $object = $this->newObjectFromPHID($phid); | $object = $this->newObjectFromIdentifier($identifier); | ||||
| if (!$object) { | |||||
| throw new Exception(pht('No such object with PHID "%s".', $phid)); | |||||
| } | |||||
| } else { | } else { | ||||
| $this->setIsCreate(true); | $this->setIsCreate(true); | ||||
| $object = $this->newEditableObject(); | $object = $this->newEditableObject(); | ||||
| } | } | ||||
| $this->validateObject($object); | $this->validateObject($object); | ||||
| $fields = $this->buildEditFields($object); | $fields = $this->buildEditFields($object); | ||||
| ▲ Show 20 Lines • Show All 170 Lines • Show Last 20 Lines | |||||