Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13956895
D14151.id34193.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D14151.id34193.diff
View Options
diff --git a/resources/sql/autopatches/20150923.drydock.resourceid.1.sql b/resources/sql/autopatches/20150923.drydock.resourceid.1.sql
new file mode 100644
--- /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
--- /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
--- /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
--- a/src/applications/drydock/controller/DrydockLeaseViewController.php
+++ b/src/applications/drydock/controller/DrydockLeaseViewController.php
@@ -110,20 +110,13 @@
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
--- a/src/applications/drydock/controller/DrydockResourceViewController.php
+++ b/src/applications/drydock/controller/DrydockResourceViewController.php
@@ -27,7 +27,7 @@
$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
--- a/src/applications/drydock/query/DrydockLeaseQuery.php
+++ b/src/applications/drydock/query/DrydockLeaseQuery.php
@@ -4,7 +4,7 @@
private $ids;
private $phids;
- private $resourceIDs;
+ private $resourcePHIDs;
private $statuses;
private $datasourceQuery;
private $needCommands;
@@ -19,8 +19,8 @@
return $this;
}
- public function withResourceIDs(array $ids) {
- $this->resourceIDs = $ids;
+ public function withResourcePHIDs(array $phids) {
+ $this->resourcePHIDs = $phids;
return $this;
}
@@ -43,22 +43,24 @@
}
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 @@
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
--- 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 @@
'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 @@
$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
--- a/src/applications/drydock/worker/DrydockAllocatorWorker.php
+++ b/src/applications/drydock/worker/DrydockAllocatorWorker.php
@@ -462,10 +462,10 @@
'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
--- a/src/applications/drydock/worker/DrydockLeaseWorker.php
+++ b/src/applications/drydock/worker/DrydockLeaseWorker.php
@@ -20,17 +20,10 @@
$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
--- a/src/applications/drydock/worker/DrydockResourceUpdateWorker.php
+++ b/src/applications/drydock/worker/DrydockResourceUpdateWorker.php
@@ -72,7 +72,7 @@
$leases = id(new DrydockLeaseQuery())
->setViewer($viewer)
- ->withResourceIDs(array($resource->getID()))
+ ->withResourcePHIDs(array($resource->getPHID()))
->withStatuses($statuses)
->execute();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 15 2024, 7:30 AM (4 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6711845
Default Alt Text
D14151.id34193.diff (7 KB)
Attached To
Mode
D14151: Give Drydock leases a resourcePHID instead of a resourceID
Attached
Detach File
Event Timeline
Log In to Comment