Path: blob/master/src/applications/harbormaster/conduit/HarbormasterQueryAutotargetsConduitAPIMethod.php
12256 views
<?php12final class HarbormasterQueryAutotargetsConduitAPIMethod3extends HarbormasterConduitAPIMethod {45public function getAPIMethodName() {6return 'harbormaster.queryautotargets';7}89public function getMethodDescription() {10return pht('Load or create build autotargets.');11}1213protected function defineParamTypes() {14return array(15'objectPHID' => 'phid',16'targetKeys' => 'list<string>',17);18}1920protected function defineReturnType() {21return 'map<string, phid>';22}2324protected function execute(ConduitAPIRequest $request) {25$viewer = $request->getUser();2627$phid = $request->getValue('objectPHID');2829// NOTE: We use withNames() to let monograms like "D123" work, which makes30// this a little easier to test. Real PHIDs will still work as expected.3132$object = id(new PhabricatorObjectQuery())33->setViewer($viewer)34->withNames(array($phid))35->executeOne();36if (!$object) {37throw new Exception(38pht(39'No such object "%s" exists.',40$phid));41}4243if (!($object instanceof HarbormasterBuildableInterface)) {44throw new Exception(45pht(46'Object "%s" does not implement interface "%s". Autotargets may '.47'only be queried for buildable objects.',48$phid,49'HarbormasterBuildableInterface'));50}5152$autotargets = $request->getValue('targetKeys', array());5354if ($autotargets) {55$targets = id(new HarbormasterTargetEngine())56->setViewer($viewer)57->setObject($object)58->setAutoTargetKeys($autotargets)59->buildTargets();60} else {61$targets = array();62}6364// Reorder the results according to the request order so we can make test65// assertions that subsequent calls return the same results.6667$map = mpull($targets, 'getPHID');68$map = array_select_keys($map, $autotargets);6970return array(71'targetMap' => $map,72);73}7475}767778