1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Make Drydock Lease and Resource PHIDs use newer PHID infrastructure

Summary:
Ref T2015. These never got updated to the new stuff, move them out of the old `Constants` class and let them load handles, etc.

Also some half-cleanup of some Blueprint/BlueprintImplementation stuff.

Test Plan: Used `phid.query` to query a Resource, Lease, and Blueprint.

Reviewers: btrahan

Reviewed By: btrahan

CC: hach-que, aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D7828
This commit is contained in:
epriestley 2013-12-26 12:29:58 -08:00
parent f9f70dc2e9
commit 1a82743491
11 changed files with 127 additions and 7 deletions

View file

@ -668,6 +668,8 @@ phutil_register_library_map(array(
'DrydockManagementWaitForLeaseWorkflow' => 'applications/drydock/management/DrydockManagementWaitForLeaseWorkflow.php', 'DrydockManagementWaitForLeaseWorkflow' => 'applications/drydock/management/DrydockManagementWaitForLeaseWorkflow.php',
'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php', 'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php',
'DrydockPHIDTypeBlueprint' => 'applications/drydock/phid/DrydockPHIDTypeBlueprint.php', 'DrydockPHIDTypeBlueprint' => 'applications/drydock/phid/DrydockPHIDTypeBlueprint.php',
'DrydockPHIDTypeLease' => 'applications/drydock/phid/DrydockPHIDTypeLease.php',
'DrydockPHIDTypeResource' => 'applications/drydock/phid/DrydockPHIDTypeResource.php',
'DrydockPreallocatedHostBlueprintImplementation' => 'applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php', 'DrydockPreallocatedHostBlueprintImplementation' => 'applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php',
'DrydockResource' => 'applications/drydock/storage/DrydockResource.php', 'DrydockResource' => 'applications/drydock/storage/DrydockResource.php',
'DrydockResourceCloseController' => 'applications/drydock/controller/DrydockResourceCloseController.php', 'DrydockResourceCloseController' => 'applications/drydock/controller/DrydockResourceCloseController.php',
@ -3074,6 +3076,8 @@ phutil_register_library_map(array(
'DrydockManagementWaitForLeaseWorkflow' => 'DrydockManagementWorkflow', 'DrydockManagementWaitForLeaseWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementWorkflow' => 'PhutilArgumentWorkflow', 'DrydockManagementWorkflow' => 'PhutilArgumentWorkflow',
'DrydockPHIDTypeBlueprint' => 'PhabricatorPHIDType', 'DrydockPHIDTypeBlueprint' => 'PhabricatorPHIDType',
'DrydockPHIDTypeLease' => 'PhabricatorPHIDType',
'DrydockPHIDTypeResource' => 'PhabricatorPHIDType',
'DrydockPreallocatedHostBlueprintImplementation' => 'DrydockBlueprintImplementation', 'DrydockPreallocatedHostBlueprintImplementation' => 'DrydockBlueprintImplementation',
'DrydockResource' => 'DrydockResource' =>
array( array(

View file

@ -29,6 +29,12 @@ final class DrydockPHIDTypeBlueprint extends PhabricatorPHIDType {
array $handles, array $handles,
array $objects) { array $objects) {
foreach ($handles as $phid => $handle) {
$blueprint = $objects[$phid];
$id = $blueprint->getID();
$handle->setURI("/drydock/blueprint/{$id}/");
}
} }
} }

View file

@ -0,0 +1,40 @@
<?php
final class DrydockPHIDTypeLease extends PhabricatorPHIDType {
const TYPECONST = 'DRYL';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Drydock Lease');
}
public function newObject() {
return new DrydockLease();
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new DrydockLeaseQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$lease = $objects[$phid];
$id = $lease->getID();
$handle->setURI("/drydock/lease/{$id}/");
}
}
}

View file

@ -0,0 +1,40 @@
<?php
final class DrydockPHIDTypeResource extends PhabricatorPHIDType {
const TYPECONST = 'DRYR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Drydock Resource');
}
public function newObject() {
return new DrydockResource();
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new DrydockResourceQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$resource = $objects[$phid];
$id = $resource->getID();
$handle->setURI("/drydock/resource/{$id}/");
}
}
}

View file

@ -34,7 +34,7 @@ final class DrydockBlueprintQuery
DrydockBlueprintImplementation::getAllBlueprintImplementations(); DrydockBlueprintImplementation::getAllBlueprintImplementations();
foreach ($blueprints as $blueprint) { foreach ($blueprints as $blueprint) {
if (array_key_exists($implementations, $blueprint->getClassName())) { if (array_key_exists($blueprint->getClassName(), $implementations)) {
$blueprint->attachImplementation( $blueprint->attachImplementation(
$implementations[$blueprint->getClassName()]); $implementations[$blueprint->getClassName()]);
} }

View file

@ -4,6 +4,7 @@ final class DrydockLeaseQuery
extends PhabricatorCursorPagedPolicyAwareQuery { extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids; private $ids;
private $phids;
private $resourceIDs; private $resourceIDs;
private $statuses; private $statuses;
@ -12,6 +13,11 @@ final class DrydockLeaseQuery
return $this; return $this;
} }
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withResourceIDs(array $ids) { public function withResourceIDs(array $ids) {
$this->resourceIDs = $ids; $this->resourceIDs = $ids;
return $this; return $this;
@ -73,6 +79,13 @@ final class DrydockLeaseQuery
$this->ids); $this->ids);
} }
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
'phid IN (%Ls)',
$this->phids);
}
if ($this->statuses) { if ($this->statuses) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,

View file

@ -4,6 +4,7 @@ final class DrydockResourceQuery
extends PhabricatorCursorPagedPolicyAwareQuery { extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids; private $ids;
private $phids;
private $statuses; private $statuses;
private $types; private $types;
private $blueprintPHIDs; private $blueprintPHIDs;
@ -13,6 +14,11 @@ final class DrydockResourceQuery
return $this; return $this;
} }
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withTypes(array $types) { public function withTypes(array $types) {
$this->types = $types; $this->types = $types;
return $this; return $this;
@ -55,6 +61,13 @@ final class DrydockResourceQuery
$this->ids); $this->ids);
} }
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
'phid IN (%Ls)',
$this->phids);
}
if ($this->types) { if ($this->types) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,

View file

@ -9,6 +9,8 @@ final class DrydockBlueprint extends DrydockDAO
protected $editPolicy; protected $editPolicy;
protected $details; protected $details;
private $implementation = self::ATTACHABLE;
public function getConfiguration() { public function getConfiguration() {
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
@ -34,6 +36,12 @@ final class DrydockBlueprint extends DrydockDAO
return id(new $class())->attachInstance($this); return id(new $class())->attachInstance($this);
} }
public function attachImplementation(DrydockBlueprintImplementation $impl) {
$this->implementation = $impl;
return $this;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -56,8 +56,7 @@ final class DrydockLease extends DrydockDAO
} }
public function generatePHID() { public function generatePHID() {
return PhabricatorPHID::generateNewPHID( return PhabricatorPHID::generateNewPHID(DrydockPHIDTypeLease::TYPECONST);
PhabricatorPHIDConstants::PHID_TYPE_DRYL);
} }
public function getInterface($type) { public function getInterface($type) {

View file

@ -27,8 +27,7 @@ final class DrydockResource extends DrydockDAO
} }
public function generatePHID() { public function generatePHID() {
return PhabricatorPHID::generateNewPHID( return PhabricatorPHID::generateNewPHID(DrydockPHIDTypeResource::TYPECONST);
PhabricatorPHIDConstants::PHID_TYPE_DRYR);
} }
public function getAttribute($key, $default = null) { public function getAttribute($key, $default = null) {

View file

@ -7,8 +7,6 @@ final class PhabricatorPHIDConstants {
const PHID_TYPE_MAGIC = '!!!!'; const PHID_TYPE_MAGIC = '!!!!';
const PHID_TYPE_STRY = 'STRY'; const PHID_TYPE_STRY = 'STRY';
const PHID_TYPE_ACMT = 'ACMT'; const PHID_TYPE_ACMT = 'ACMT';
const PHID_TYPE_DRYR = 'DRYR';
const PHID_TYPE_DRYL = 'DRYL';
const PHID_TYPE_OASC = 'OASC'; const PHID_TYPE_OASC = 'OASC';
const PHID_TYPE_OASA = 'OASA'; const PHID_TYPE_OASA = 'OASA';
const PHID_TYPE_TOBJ = 'TOBJ'; const PHID_TYPE_TOBJ = 'TOBJ';