Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/query/HarbormasterBuildableQuery.php
<?php | <?php | ||||
final class HarbormasterBuildableQuery | final class HarbormasterBuildableQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
private $buildablePHIDs; | private $buildablePHIDs; | ||||
private $containerPHIDs; | private $containerPHIDs; | ||||
private $manualBuildables; | private $manualBuildables; | ||||
private $needContainerObjects; | private $needContainerObjects; | ||||
private $needContainerHandles; | |||||
private $needBuildableHandles; | |||||
private $needBuilds; | private $needBuilds; | ||||
private $needTargets; | private $needTargets; | ||||
public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
$this->ids = $ids; | $this->ids = $ids; | ||||
return $this; | return $this; | ||||
} | } | ||||
Show All 17 Lines | public function withManualBuildables($manual) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needContainerObjects($need) { | public function needContainerObjects($need) { | ||||
$this->needContainerObjects = $need; | $this->needContainerObjects = $need; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needContainerHandles($need) { | |||||
$this->needContainerHandles = $need; | |||||
return $this; | |||||
} | |||||
public function needBuildableHandles($need) { | |||||
$this->needBuildableHandles = $need; | |||||
return $this; | |||||
} | |||||
public function needBuilds($need) { | public function needBuilds($need) { | ||||
$this->needBuilds = $need; | $this->needBuilds = $need; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needTargets($need) { | public function needTargets($need) { | ||||
$this->needTargets = $need; | $this->needTargets = $need; | ||||
return $this; | return $this; | ||||
Show All 28 Lines | foreach ($page as $key => $buildable) { | ||||
} | } | ||||
$buildable->attachBuildableObject($buildables[$buildable_phid]); | $buildable->attachBuildableObject($buildables[$buildable_phid]); | ||||
} | } | ||||
return $page; | return $page; | ||||
} | } | ||||
protected function didFilterPage(array $page) { | protected function didFilterPage(array $page) { | ||||
if ($this->needContainerObjects || $this->needContainerHandles) { | |||||
$container_phids = array_filter(mpull($page, 'getContainerPHID')); | |||||
if ($this->needContainerObjects) { | if ($this->needContainerObjects) { | ||||
$containers = array(); | $container_phids = array_filter(mpull($page, 'getContainerPHID')); | ||||
if ($container_phids) { | if ($container_phids) { | ||||
$containers = id(new PhabricatorObjectQuery()) | $containers = id(new PhabricatorObjectQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->withPHIDs($container_phids) | ->withPHIDs($container_phids) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->execute(); | ->execute(); | ||||
$containers = mpull($containers, null, 'getPHID'); | $containers = mpull($containers, null, 'getPHID'); | ||||
} else { | |||||
$containers = array(); | |||||
} | } | ||||
foreach ($page as $key => $buildable) { | foreach ($page as $key => $buildable) { | ||||
$container_phid = $buildable->getContainerPHID(); | $container_phid = $buildable->getContainerPHID(); | ||||
$buildable->attachContainerObject(idx($containers, $container_phid)); | $buildable->attachContainerObject(idx($containers, $container_phid)); | ||||
} | } | ||||
} | } | ||||
if ($this->needContainerHandles) { | |||||
$handles = array(); | |||||
if ($container_phids) { | |||||
$handles = id(new PhabricatorHandleQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->withPHIDs($container_phids) | |||||
->setParentQuery($this) | |||||
->execute(); | |||||
} | |||||
foreach ($page as $key => $buildable) { | |||||
$container_phid = $buildable->getContainerPHID(); | |||||
$buildable->attachContainerHandle(idx($handles, $container_phid)); | |||||
} | |||||
} | |||||
} | |||||
if ($this->needBuildableHandles) { | |||||
$handles = array(); | |||||
$handle_phids = array_filter(mpull($page, 'getBuildablePHID')); | |||||
if ($handle_phids) { | |||||
$handles = id(new PhabricatorHandleQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->withPHIDs($handle_phids) | |||||
->setParentQuery($this) | |||||
->execute(); | |||||
} | |||||
foreach ($page as $key => $buildable) { | |||||
$handle_phid = $buildable->getBuildablePHID(); | |||||
$buildable->attachBuildableHandle(idx($handles, $handle_phid)); | |||||
} | |||||
} | |||||
if ($this->needBuilds || $this->needTargets) { | if ($this->needBuilds || $this->needTargets) { | ||||
$builds = id(new HarbormasterBuildQuery()) | $builds = id(new HarbormasterBuildQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->withBuildablePHIDs(mpull($page, 'getPHID')) | ->withBuildablePHIDs(mpull($page, 'getPHID')) | ||||
->needBuildTargets($this->needTargets) | ->needBuildTargets($this->needTargets) | ||||
->execute(); | ->execute(); | ||||
$builds = mgroup($builds, 'getBuildablePHID'); | $builds = mgroup($builds, 'getBuildablePHID'); | ||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |