Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15412138
D10982.id26376.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D10982.id26376.diff
View Options
diff --git a/resources/sql/autopatches/20141210.reposervice.sql b/resources/sql/autopatches/20141210.reposervice.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20141210.reposervice.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_repository.repository
+ ADD almanacServicePHID VARBINARY(64);
diff --git a/src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php b/src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php
--- a/src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php
+++ b/src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php
@@ -31,7 +31,8 @@
$viewer = $request->getUser();
$query = id(new AlmanacServiceQuery())
- ->setViewer($viewer);
+ ->setViewer($viewer)
+ ->needBindings(true);
$ids = $request->getValue('ids');
if ($ids !== null) {
@@ -52,16 +53,6 @@
$services = $query->executeWithCursorPager($pager);
- if ($services) {
- $bindings = id(new AlmanacBindingQuery())
- ->setViewer($viewer)
- ->withServicePHIDs(mpull($services, 'getPHID'))
- ->execute();
- $bindings = mgroup($bindings, 'getServicePHID');
- } else {
- $bindings = array();
- }
-
$data = array();
foreach ($services as $service) {
$phid = $service->getPHID();
@@ -69,7 +60,7 @@
$properties = $service->getAlmanacProperties();
$properties = mpull($properties, 'getFieldValue', 'getFieldName');
- $service_bindings = idx($bindings, $phid, array());
+ $service_bindings = $service->getBindings();
$service_bindings = array_values($service_bindings);
foreach ($service_bindings as $key => $service_binding) {
$service_bindings[$key] = $this->getBindingDictionary($service_binding);
diff --git a/src/applications/almanac/query/AlmanacServiceQuery.php b/src/applications/almanac/query/AlmanacServiceQuery.php
--- a/src/applications/almanac/query/AlmanacServiceQuery.php
+++ b/src/applications/almanac/query/AlmanacServiceQuery.php
@@ -6,6 +6,7 @@
private $ids;
private $phids;
private $names;
+ private $needBindings;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -22,6 +23,11 @@
return $this;
}
+ public function needBindings($need_bindings) {
+ $this->needBindings = $need_bindings;
+ return $this;
+ }
+
protected function loadPage() {
$table = new AlmanacService();
$conn_r = $table->establishConnection('r');
@@ -71,4 +77,22 @@
return $this->formatWhereClause($where);
}
+ protected function didFilterPage(array $services) {
+ if ($this->needBindings) {
+ $service_phids = mpull($services, 'getPHID');
+ $bindings = id(new AlmanacBindingQuery())
+ ->setViewer($this->getViewer())
+ ->withServicePHIDs($service_phids)
+ ->execute();
+ $bindings = mgroup($bindings, 'getServicePHID');
+
+ foreach ($services as $service) {
+ $service_bindings = idx($bindings, $service->getPHID(), array());
+ $service->attachBindings($service_bindings);
+ }
+ }
+
+ return parent::didFilterPage($services);
+ }
+
}
diff --git a/src/applications/almanac/storage/AlmanacService.php b/src/applications/almanac/storage/AlmanacService.php
--- a/src/applications/almanac/storage/AlmanacService.php
+++ b/src/applications/almanac/storage/AlmanacService.php
@@ -17,6 +17,7 @@
private $customFields = self::ATTACHABLE;
private $almanacProperties = self::ATTACHABLE;
+ private $bindings = self::ATTACHABLE;
public static function initializeNewService() {
return id(new AlmanacService())
@@ -65,6 +66,15 @@
return '/almanac/service/view/'.$this->getName().'/';
}
+ public function getBindings() {
+ return $this->assertAttached($this->bindings);
+ }
+
+ public function attachBindings(array $bindings) {
+ $this->bindings = $bindings;
+ return $this;
+ }
+
/* -( AlmanacPropertyInterface )------------------------------------------- */
diff --git a/src/applications/diffusion/query/DiffusionQuery.php b/src/applications/diffusion/query/DiffusionQuery.php
--- a/src/applications/diffusion/query/DiffusionQuery.php
+++ b/src/applications/diffusion/query/DiffusionQuery.php
@@ -62,12 +62,61 @@
$params = $params + $core_params;
- return id(new ConduitCall(
- $method,
- $params
- ))
- ->setUser($user)
- ->execute();
+ $service_phid = $repository->getAlmanacServicePHID();
+ if ($service_phid === null) {
+ return id(new ConduitCall($method, $params))
+ ->setUser($user)
+ ->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() {
diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php
--- a/src/applications/repository/storage/PhabricatorRepository.php
+++ b/src/applications/repository/storage/PhabricatorRepository.php
@@ -52,6 +52,7 @@
protected $versionControlSystem;
protected $details = array();
protected $credentialPHID;
+ protected $almanacServicePHID;
private $commitCount = self::ATTACHABLE;
private $mostRecentCommit = self::ATTACHABLE;
@@ -86,6 +87,7 @@
'uuid' => 'text64?',
'pushPolicy' => 'policy',
'credentialPHID' => 'phid?',
+ 'almanacServicePHID' => 'phid?',
),
self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 20, 11:27 AM (2 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7681658
Default Alt Text
D10982.id26376.diff (6 KB)
Attached To
Mode
D10982: Allow repositories to be bound to an AlmanacService
Attached
Detach File
Event Timeline
Log In to Comment