[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/repository/query/ -> PhabricatorRepositoryPushEventQuery.php (source)

   1  <?php
   2  
   3  final class PhabricatorRepositoryPushEventQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $repositoryPHIDs;
   9    private $pusherPHIDs;
  10    private $needLogs;
  11  
  12    public function withIDs(array $ids) {
  13      $this->ids = $ids;
  14      return $this;
  15    }
  16  
  17    public function withPHIDs(array $phids) {
  18      $this->phids = $phids;
  19      return $this;
  20    }
  21  
  22    public function withRepositoryPHIDs(array $repository_phids) {
  23      $this->repositoryPHIDs = $repository_phids;
  24      return $this;
  25    }
  26  
  27    public function withPusherPHIDs(array $pusher_phids) {
  28      $this->pusherPHIDs = $pusher_phids;
  29      return $this;
  30    }
  31  
  32    public function needLogs($need_logs) {
  33      $this->needLogs = $need_logs;
  34      return $this;
  35    }
  36  
  37    protected function loadPage() {
  38      $table = new PhabricatorRepositoryPushEvent();
  39      $conn_r = $table->establishConnection('r');
  40  
  41      $data = queryfx_all(
  42        $conn_r,
  43        'SELECT * FROM %T %Q %Q %Q',
  44        $table->getTableName(),
  45        $this->buildWhereClause($conn_r),
  46        $this->buildOrderClause($conn_r),
  47        $this->buildLimitClause($conn_r));
  48  
  49      return $table->loadAllFromArray($data);
  50    }
  51  
  52    public function willFilterPage(array $events) {
  53      $repository_phids = mpull($events, 'getRepositoryPHID');
  54      $repositories = id(new PhabricatorRepositoryQuery())
  55        ->setViewer($this->getViewer())
  56        ->withPHIDs($repository_phids)
  57        ->execute();
  58      $repositories = mpull($repositories, null, 'getPHID');
  59  
  60      foreach ($events as $key => $event) {
  61        $phid = $event->getRepositoryPHID();
  62        if (empty($repositories[$phid])) {
  63          unset($events[$key]);
  64          continue;
  65        }
  66        $event->attachRepository($repositories[$phid]);
  67      }
  68  
  69      return $events;
  70    }
  71  
  72    public function didFilterPage(array $events) {
  73      $phids = mpull($events, 'getPHID');
  74  
  75      if ($this->needLogs) {
  76        $logs = id(new PhabricatorRepositoryPushLogQuery())
  77          ->setParentQuery($this)
  78          ->setViewer($this->getViewer())
  79          ->withPushEventPHIDs($phids)
  80          ->execute();
  81        $logs = mgroup($logs, 'getPushEventPHID');
  82        foreach ($events as $key => $event) {
  83          $event_logs = idx($logs, $event->getPHID(), array());
  84          $event->attachLogs($event_logs);
  85        }
  86      }
  87  
  88      return $events;
  89    }
  90  
  91    private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
  92      $where = array();
  93  
  94      if ($this->ids) {
  95        $where[] = qsprintf(
  96          $conn_r,
  97          'id IN (%Ld)',
  98          $this->ids);
  99      }
 100  
 101      if ($this->phids) {
 102        $where[] = qsprintf(
 103          $conn_r,
 104          'phid IN (%Ls)',
 105          $this->phids);
 106      }
 107  
 108      if ($this->repositoryPHIDs) {
 109        $where[] = qsprintf(
 110          $conn_r,
 111          'repositoryPHID IN (%Ls)',
 112          $this->repositoryPHIDs);
 113      }
 114  
 115      if ($this->pusherPHIDs) {
 116        $where[] = qsprintf(
 117          $conn_r,
 118          'pusherPHID in (%Ls)',
 119          $this->pusherPHIDs);
 120      }
 121  
 122      $where[] = $this->buildPagingClause($conn_r);
 123  
 124      return $this->formatWhereClause($where);
 125    }
 126  
 127    public function getQueryApplicationClass() {
 128      return 'PhabricatorDiffusionApplication';
 129    }
 130  
 131  }


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