diff --git a/resources/sql/autopatches/20150923.drydock.resourceid.1.sql b/resources/sql/autopatches/20150923.drydock.resourceid.1.sql new file mode 100644 index 0000000000..ad87d64669 --- /dev/null +++ b/resources/sql/autopatches/20150923.drydock.resourceid.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_drydock.drydock_lease + ADD resourcePHID VARBINARY(64); diff --git a/resources/sql/autopatches/20150923.drydock.resourceid.2.sql b/resources/sql/autopatches/20150923.drydock.resourceid.2.sql new file mode 100644 index 0000000000..22f6d32d47 --- /dev/null +++ b/resources/sql/autopatches/20150923.drydock.resourceid.2.sql @@ -0,0 +1,5 @@ +UPDATE + {$NAMESPACE}_drydock.drydock_lease l, + {$NAMESPACE}_drydock.drydock_resource r + SET l.resourcePHID = r.phid + WHERE l.resourceID = r.id; diff --git a/resources/sql/autopatches/20150923.drydock.resourceid.3.sql b/resources/sql/autopatches/20150923.drydock.resourceid.3.sql new file mode 100644 index 0000000000..f3520fa510 --- /dev/null +++ b/resources/sql/autopatches/20150923.drydock.resourceid.3.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_drydock.drydock_lease + DROP resourceID; diff --git a/src/applications/drydock/controller/DrydockLeaseViewController.php b/src/applications/drydock/controller/DrydockLeaseViewController.php index d068602bd8..bb748cceee 100644 --- a/src/applications/drydock/controller/DrydockLeaseViewController.php +++ b/src/applications/drydock/controller/DrydockLeaseViewController.php @@ -110,20 +110,13 @@ final class DrydockLeaseViewController extends DrydockLeaseController { pht('Resource Type'), $lease->getResourceType()); - $resource = id(new DrydockResourceQuery()) - ->setViewer($this->getViewer()) - ->withIDs(array($lease->getResourceID())) - ->executeOne(); - - if ($resource !== null) { - $view->addProperty( - pht('Resource'), - $this->getViewer()->renderHandle($resource->getPHID())); + $resource_phid = $lease->getResourcePHID(); + if ($resource_phid) { + $resource_display = $viewer->renderHandle($resource_phid); } else { - $view->addProperty( - pht('Resource'), - pht('No Resource')); + $resource_display = phutil_tag('em', array(), pht('No Resource')); } + $view->addProperty(pht('Resource'), $resource_display); $until = $lease->getUntil(); if ($until) { diff --git a/src/applications/drydock/controller/DrydockResourceViewController.php b/src/applications/drydock/controller/DrydockResourceViewController.php index 40009e34ce..659f7b4fc1 100644 --- a/src/applications/drydock/controller/DrydockResourceViewController.php +++ b/src/applications/drydock/controller/DrydockResourceViewController.php @@ -27,7 +27,7 @@ final class DrydockResourceViewController extends DrydockResourceController { $leases = id(new DrydockLeaseQuery()) ->setViewer($viewer) - ->withResourceIDs(array($resource->getID())) + ->withResourcePHIDs(array($resource->getPHID())) ->execute(); $lease_list = id(new DrydockLeaseListView()) diff --git a/src/applications/drydock/query/DrydockLeaseQuery.php b/src/applications/drydock/query/DrydockLeaseQuery.php index a212a27ca8..0d12a1fa21 100644 --- a/src/applications/drydock/query/DrydockLeaseQuery.php +++ b/src/applications/drydock/query/DrydockLeaseQuery.php @@ -4,7 +4,7 @@ final class DrydockLeaseQuery extends DrydockQuery { private $ids; private $phids; - private $resourceIDs; + private $resourcePHIDs; private $statuses; private $datasourceQuery; private $needCommands; @@ -19,8 +19,8 @@ final class DrydockLeaseQuery extends DrydockQuery { return $this; } - public function withResourceIDs(array $ids) { - $this->resourceIDs = $ids; + public function withResourcePHIDs(array $phids) { + $this->resourcePHIDs = $phids; return $this; } @@ -43,22 +43,24 @@ final class DrydockLeaseQuery extends DrydockQuery { } protected function willFilterPage(array $leases) { - $resource_ids = array_filter(mpull($leases, 'getResourceID')); - if ($resource_ids) { + $resource_phids = array_filter(mpull($leases, 'getResourcePHID')); + if ($resource_phids) { $resources = id(new DrydockResourceQuery()) ->setParentQuery($this) ->setViewer($this->getViewer()) - ->withIDs(array_unique($resource_ids)) + ->withPHIDs(array_unique($resource_phids)) ->execute(); + $resources = mpull($resources, null, 'getPHID'); } else { $resources = array(); } foreach ($leases as $key => $lease) { $resource = null; - if ($lease->getResourceID()) { - $resource = idx($resources, $lease->getResourceID()); + if ($lease->getResourcePHID()) { + $resource = idx($resources, $lease->getResourcePHID()); if (!$resource) { + $this->didRejectResult($lease); unset($leases[$key]); continue; } @@ -72,11 +74,11 @@ final class DrydockLeaseQuery extends DrydockQuery { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); - if ($this->resourceIDs !== null) { + if ($this->resourcePHIDs !== null) { $where[] = qsprintf( $conn, - 'resourceID IN (%Ld)', - $this->resourceIDs); + 'resourcePHID IN (%Ls)', + $this->resourcePHIDs); } if ($this->ids !== null) { diff --git a/src/applications/drydock/storage/DrydockLease.php b/src/applications/drydock/storage/DrydockLease.php index 8d88b5760b..b0c084d56f 100644 --- a/src/applications/drydock/storage/DrydockLease.php +++ b/src/applications/drydock/storage/DrydockLease.php @@ -3,7 +3,7 @@ final class DrydockLease extends DrydockDAO implements PhabricatorPolicyInterface { - protected $resourceID; + protected $resourcePHID; protected $resourceType; protected $until; protected $ownerPHID; @@ -64,13 +64,11 @@ final class DrydockLease extends DrydockDAO 'until' => 'epoch?', 'resourceType' => 'text128', 'ownerPHID' => 'phid?', - 'resourceID' => 'id?', + 'resourcePHID' => 'phid?', ), self::CONFIG_KEY_SCHEMA => array( - 'key_phid' => null, - 'phid' => array( - 'columns' => array('phid'), - 'unique' => true, + 'key_resource' => array( + 'columns' => array('resourcePHID', 'status'), ), ), ) + parent::getConfiguration(); @@ -219,7 +217,7 @@ final class DrydockLease extends DrydockDAO $this->openTransaction(); $this - ->setResourceID($resource->getID()) + ->setResourcePHID($resource->getPHID()) ->setStatus($new_status) ->save(); diff --git a/src/applications/drydock/worker/DrydockAllocatorWorker.php b/src/applications/drydock/worker/DrydockAllocatorWorker.php index 4288662434..2c6caa41b5 100644 --- a/src/applications/drydock/worker/DrydockAllocatorWorker.php +++ b/src/applications/drydock/worker/DrydockAllocatorWorker.php @@ -462,10 +462,10 @@ final class DrydockAllocatorWorker extends DrydockWorker { 'acquireLease()')); } - $lease_id = $lease->getResourceID(); - $resource_id = $resource->getID(); + $lease_phid = $lease->getResourcePHID(); + $resource_phid = $resource->getPHID(); - if ($lease_id !== $resource_id) { + if ($lease_phid !== $resource_phid) { // TODO: Destroy the lease? throw new Exception( pht( diff --git a/src/applications/drydock/worker/DrydockLeaseWorker.php b/src/applications/drydock/worker/DrydockLeaseWorker.php index 2143a4e4cf..82a5d1891e 100644 --- a/src/applications/drydock/worker/DrydockLeaseWorker.php +++ b/src/applications/drydock/worker/DrydockLeaseWorker.php @@ -20,17 +20,10 @@ final class DrydockLeaseWorker extends DrydockWorker { $actual_status)); } - $resource_id = $lease->getResourceID(); - - $resource = id(new DrydockResourceQuery()) - ->setViewer($this->getViewer()) - ->withIDs(array($resource_id)) - ->executeOne(); + $resource = $lease->getResource(); if (!$resource) { throw new PhabricatorWorkerPermanentFailureException( - pht( - 'Trying to activate lease on invalid resource ("%s").', - $resource_id)); + pht('Trying to activate lease with no resource.')); } $resource_status = $resource->getStatus(); diff --git a/src/applications/drydock/worker/DrydockResourceUpdateWorker.php b/src/applications/drydock/worker/DrydockResourceUpdateWorker.php index 7528df8d12..532090bf35 100644 --- a/src/applications/drydock/worker/DrydockResourceUpdateWorker.php +++ b/src/applications/drydock/worker/DrydockResourceUpdateWorker.php @@ -72,7 +72,7 @@ final class DrydockResourceUpdateWorker extends DrydockWorker { $leases = id(new DrydockLeaseQuery()) ->setViewer($viewer) - ->withResourceIDs(array($resource->getID())) + ->withResourcePHIDs(array($resource->getPHID())) ->withStatuses($statuses) ->execute();