mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-27 14:09:11 +01:00
Summary: Ref T9252. Drydock currently uses integer statuses, but there's no reason for this (they don't need to be ordered) and it makes debugging them, working with them, future APIs, etc., more cumbersome. Switch to string instead. Also rename `STATUS_OPEN` to `STATUS_ACTIVE` and `STATUS_CLOSED` to `STATUS_RELEASED` for consistency. This makes resources and leases have more similar states, and gives resource states more accurate names. Test Plan: Browsed web UI, grepped for changed constants, applied patch, inspected database. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9252 Differential Revision: https://secure.phabricator.com/D14153
115 lines
2.5 KiB
PHP
115 lines
2.5 KiB
PHP
<?php
|
|
|
|
final class DrydockLeaseQuery extends DrydockQuery {
|
|
|
|
private $ids;
|
|
private $phids;
|
|
private $resourcePHIDs;
|
|
private $statuses;
|
|
private $datasourceQuery;
|
|
private $needCommands;
|
|
|
|
public function withIDs(array $ids) {
|
|
$this->ids = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function withPHIDs(array $phids) {
|
|
$this->phids = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withResourcePHIDs(array $phids) {
|
|
$this->resourcePHIDs = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withStatuses(array $statuses) {
|
|
$this->statuses = $statuses;
|
|
return $this;
|
|
}
|
|
|
|
public function withDatasourceQuery($query) {
|
|
$this->datasourceQuery = $query;
|
|
return $this;
|
|
}
|
|
|
|
public function newResultObject() {
|
|
return new DrydockLease();
|
|
}
|
|
|
|
protected function loadPage() {
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
}
|
|
|
|
protected function willFilterPage(array $leases) {
|
|
$resource_phids = array_filter(mpull($leases, 'getResourcePHID'));
|
|
if ($resource_phids) {
|
|
$resources = id(new DrydockResourceQuery())
|
|
->setParentQuery($this)
|
|
->setViewer($this->getViewer())
|
|
->withPHIDs(array_unique($resource_phids))
|
|
->execute();
|
|
$resources = mpull($resources, null, 'getPHID');
|
|
} else {
|
|
$resources = array();
|
|
}
|
|
|
|
foreach ($leases as $key => $lease) {
|
|
$resource = null;
|
|
if ($lease->getResourcePHID()) {
|
|
$resource = idx($resources, $lease->getResourcePHID());
|
|
if (!$resource) {
|
|
$this->didRejectResult($lease);
|
|
unset($leases[$key]);
|
|
continue;
|
|
}
|
|
}
|
|
$lease->attachResource($resource);
|
|
}
|
|
|
|
return $leases;
|
|
}
|
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
$where = parent::buildWhereClauseParts($conn);
|
|
|
|
if ($this->resourcePHIDs !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'resourcePHID IN (%Ls)',
|
|
$this->resourcePHIDs);
|
|
}
|
|
|
|
if ($this->ids !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'id IN (%Ld)',
|
|
$this->ids);
|
|
}
|
|
|
|
if ($this->phids !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'phid IN (%Ls)',
|
|
$this->phids);
|
|
}
|
|
|
|
if ($this->statuses !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'status IN (%Ls)',
|
|
$this->statuses);
|
|
}
|
|
|
|
if ($this->datasourceQuery !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'id = %d',
|
|
(int)$this->datasourceQuery);
|
|
}
|
|
|
|
return $where;
|
|
}
|
|
|
|
}
|