1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02: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',
'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.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',
'DrydockResource' => 'applications/drydock/storage/DrydockResource.php',
'DrydockResourceCloseController' => 'applications/drydock/controller/DrydockResourceCloseController.php',
@ -3074,6 +3076,8 @@ phutil_register_library_map(array(
'DrydockManagementWaitForLeaseWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementWorkflow' => 'PhutilArgumentWorkflow',
'DrydockPHIDTypeBlueprint' => 'PhabricatorPHIDType',
'DrydockPHIDTypeLease' => 'PhabricatorPHIDType',
'DrydockPHIDTypeResource' => 'PhabricatorPHIDType',
'DrydockPreallocatedHostBlueprintImplementation' => 'DrydockBlueprintImplementation',
'DrydockResource' =>
array(

View file

@ -29,6 +29,12 @@ final class DrydockPHIDTypeBlueprint extends PhabricatorPHIDType {
array $handles,
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();
foreach ($blueprints as $blueprint) {
if (array_key_exists($implementations, $blueprint->getClassName())) {
if (array_key_exists($blueprint->getClassName(), $implementations)) {
$blueprint->attachImplementation(
$implementations[$blueprint->getClassName()]);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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