mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-15 03:12:41 +01:00
3db5833622
Summary: Ref T2015. Update DrydockLog for policy awareness and give it a policy query. Test Plan: Browsed all the log interfaces. Reviewers: btrahan Reviewed By: btrahan CC: hach-que, aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7831
79 lines
1.8 KiB
PHP
79 lines
1.8 KiB
PHP
<?php
|
|
|
|
final class DrydockLogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
private $resourceIDs;
|
|
private $leaseIDs;
|
|
|
|
public function withResourceIDs(array $ids) {
|
|
$this->resourceIDs = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function withLeaseIDs(array $ids) {
|
|
$this->leaseIDs = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function loadPage() {
|
|
$table = new DrydockLog();
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
$data = queryfx_all(
|
|
$conn_r,
|
|
'SELECT log.* FROM %T log %Q %Q %Q',
|
|
$table->getTableName(),
|
|
$this->buildWhereClause($conn_r),
|
|
$this->buildOrderClause($conn_r),
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
return $table->loadAllFromArray($data);
|
|
}
|
|
|
|
public function willFilterPage(array $logs) {
|
|
$resource_ids = mpull($logs, 'getResourceID');
|
|
$resources = id(new DrydockResourceQuery())
|
|
->setParentQuery($this)
|
|
->setViewer($this->getViewer())
|
|
->withIDs($resource_ids)
|
|
->execute();
|
|
|
|
foreach ($logs as $key => $log) {
|
|
$resource = idx($resources, $log->getResourceID());
|
|
if (!$resource) {
|
|
unset($logs[$key]);
|
|
continue;
|
|
}
|
|
$log->attachResource($resource);
|
|
}
|
|
|
|
return $logs;
|
|
}
|
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
$where = array();
|
|
|
|
if ($this->resourceIDs) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'resourceID IN (%Ld)',
|
|
$this->resourceIDs);
|
|
}
|
|
|
|
if ($this->leaseIDs) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'leaseID IN (%Ld)',
|
|
$this->leaseIDs);
|
|
}
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
return $this->formatWhereClause($where);
|
|
}
|
|
|
|
public function getQueryApplicationClass() {
|
|
return 'PhabricatorApplicationDrydock';
|
|
}
|
|
|
|
}
|