[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/harbormaster/query/ -> HarbormasterBuildArtifactQuery.php (source)

   1  <?php
   2  
   3  final class HarbormasterBuildArtifactQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $buildTargetPHIDs;
   8    private $artifactTypes;
   9    private $artifactKeys;
  10    private $keyBuildPHID;
  11    private $keyBuildGeneration;
  12  
  13    public function withIDs(array $ids) {
  14      $this->ids = $ids;
  15      return $this;
  16    }
  17  
  18    public function withBuildTargetPHIDs(array $build_target_phids) {
  19      $this->buildTargetPHIDs = $build_target_phids;
  20      return $this;
  21    }
  22  
  23    public function withArtifactTypes(array $artifact_types) {
  24      $this->artifactTypes = $artifact_types;
  25      return $this;
  26    }
  27  
  28    public function withArtifactKeys(
  29      $build_phid,
  30      $build_gen,
  31      array $artifact_keys) {
  32      $this->keyBuildPHID = $build_phid;
  33      $this->keyBuildGeneration = $build_gen;
  34      $this->artifactKeys = $artifact_keys;
  35      return $this;
  36    }
  37  
  38    protected function loadPage() {
  39      $table = new HarbormasterBuildArtifact();
  40      $conn_r = $table->establishConnection('r');
  41  
  42      $data = queryfx_all(
  43        $conn_r,
  44        'SELECT * FROM %T %Q %Q %Q',
  45        $table->getTableName(),
  46        $this->buildWhereClause($conn_r),
  47        $this->buildOrderClause($conn_r),
  48        $this->buildLimitClause($conn_r));
  49  
  50      return $table->loadAllFromArray($data);
  51    }
  52  
  53    protected function willFilterPage(array $page) {
  54      $build_targets = array();
  55  
  56      $build_target_phids = array_filter(mpull($page, 'getBuildTargetPHID'));
  57      if ($build_target_phids) {
  58        $build_targets = id(new HarbormasterBuildTargetQuery())
  59          ->setViewer($this->getViewer())
  60          ->withPHIDs($build_target_phids)
  61          ->setParentQuery($this)
  62          ->execute();
  63        $build_targets = mpull($build_targets, null, 'getPHID');
  64      }
  65  
  66      foreach ($page as $key => $build_log) {
  67        $build_target_phid = $build_log->getBuildTargetPHID();
  68        if (empty($build_targets[$build_target_phid])) {
  69          unset($page[$key]);
  70          continue;
  71        }
  72        $build_log->attachBuildTarget($build_targets[$build_target_phid]);
  73      }
  74  
  75      return $page;
  76    }
  77  
  78    private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
  79      $where = array();
  80  
  81      if ($this->ids) {
  82        $where[] = qsprintf(
  83          $conn_r,
  84          'id IN (%Ld)',
  85          $this->ids);
  86      }
  87  
  88      if ($this->buildTargetPHIDs) {
  89        $where[] = qsprintf(
  90          $conn_r,
  91          'buildTargetPHID IN (%Ls)',
  92          $this->buildTargetPHIDs);
  93      }
  94  
  95      if ($this->artifactTypes) {
  96        $where[] = qsprintf(
  97          $conn_r,
  98          'artifactType in (%Ls)',
  99          $this->artifactTypes);
 100      }
 101  
 102      if ($this->artifactKeys) {
 103        $indexes = array();
 104        foreach ($this->artifactKeys as $key) {
 105          $indexes[] = PhabricatorHash::digestForIndex(
 106            $this->keyBuildPHID.$this->keyBuildGeneration.$key);
 107        }
 108  
 109        $where[] = qsprintf(
 110          $conn_r,
 111          'artifactIndex IN (%Ls)',
 112          $indexes);
 113      }
 114  
 115      $where[] = $this->buildPagingClause($conn_r);
 116  
 117      return $this->formatWhereClause($where);
 118    }
 119  
 120    public function getQueryApplicationClass() {
 121      return 'PhabricatorHarbormasterApplication';
 122    }
 123  
 124  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1