Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/query/DiffusionQuery.php
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | final public static function callConduitWithDiffusionRequest( | ||||
| ); | ); | ||||
| if ($drequest->getBranch() !== null) { | if ($drequest->getBranch() !== null) { | ||||
| $core_params['branch'] = $drequest->getBranch(); | $core_params['branch'] = $drequest->getBranch(); | ||||
| } | } | ||||
| $params = $params + $core_params; | $params = $params + $core_params; | ||||
| return id(new ConduitCall( | $service_phid = $repository->getAlmanacServicePHID(); | ||||
| $method, | if ($service_phid === null) { | ||||
| $params | return id(new ConduitCall($method, $params)) | ||||
| )) | |||||
| ->setUser($user) | ->setUser($user) | ||||
| ->execute(); | ->execute(); | ||||
| } | } | ||||
| $service = id(new AlmanacServiceQuery()) | |||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
| ->withPHIDs(array($service_phid)) | |||||
| ->needBindings(true) | |||||
| ->executeOne(); | |||||
| if (!$service) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'The Alamnac service for this repository is invalid or could not '. | |||||
| 'be loaded.')); | |||||
| } | |||||
| $bindings = $service->getBindings(); | |||||
| if (!$bindings) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'The Alamanc service for this repository is not bound to any '. | |||||
| 'interfaces.')); | |||||
| } | |||||
| $uris = array(); | |||||
| foreach ($bindings as $binding) { | |||||
| $iface = $binding->getInterface(); | |||||
| $protocol = $binding->getAlmanacPropertyValue('protocol'); | |||||
| if ($protocol === 'http') { | |||||
| $uris[] = 'http://'.$iface->renderDisplayAddress().'/'; | |||||
| } else if ($protocol === 'https' || $protocol === null) { | |||||
| $uris[] = 'https://'.$iface->renderDisplayAddress().'/'; | |||||
| } else { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'The Almanac service for this repository has a binding to an '. | |||||
| 'invalid interface with an unknown protocol ("%s").', | |||||
| $protocol)); | |||||
| } | |||||
| } | |||||
| shuffle($uris); | |||||
| $uri = head($uris); | |||||
| $domain = id(new PhutilURI(PhabricatorEnv::getURI('/')))->getDomain(); | |||||
| // TODO: This call needs authentication, which is blocked by T5955. | |||||
| return id(new ConduitClient($uri)) | |||||
| ->setHost($domain) | |||||
| ->callMethodSynchronous($method, $params); | |||||
| } | |||||
| public function execute() { | public function execute() { | ||||
| return $this->executeQuery(); | return $this->executeQuery(); | ||||
| } | } | ||||
| abstract protected function executeQuery(); | abstract protected function executeQuery(); | ||||
| /* -( Query Utilities )---------------------------------------------------- */ | /* -( Query Utilities )---------------------------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines | |||||