[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ReleephBranchQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $ids; 7 private $phids; 8 private $productPHIDs; 9 private $productIDs; 10 11 const STATUS_ALL = 'status-all'; 12 const STATUS_OPEN = 'status-open'; 13 private $status = self::STATUS_ALL; 14 15 private $needCutPointCommits; 16 17 public function withIDs(array $ids) { 18 $this->ids = $ids; 19 return $this; 20 } 21 22 public function withPHIDs(array $phids) { 23 $this->phids = $phids; 24 return $this; 25 } 26 27 public function needCutPointCommits($need_commits) { 28 $this->needCutPointCommits = $need_commits; 29 return $this; 30 } 31 32 public function withStatus($status) { 33 $this->status = $status; 34 return $this; 35 } 36 37 public function withProductPHIDs($product_phids) { 38 $this->productPHIDs = $product_phids; 39 return $this; 40 } 41 42 public function loadPage() { 43 $table = new ReleephBranch(); 44 $conn_r = $table->establishConnection('r'); 45 46 $data = queryfx_all( 47 $conn_r, 48 'SELECT * FROM %T %Q %Q %Q', 49 $table->getTableName(), 50 $this->buildWhereClause($conn_r), 51 $this->buildOrderClause($conn_r), 52 $this->buildLimitClause($conn_r)); 53 54 return $table->loadAllFromArray($data); 55 } 56 57 public function willExecute() { 58 if ($this->productPHIDs !== null) { 59 $products = id(new ReleephProductQuery()) 60 ->setViewer($this->getViewer()) 61 ->withPHIDs($this->productPHIDs) 62 ->execute(); 63 64 if (!$products) { 65 throw new PhabricatorEmptyQueryException(); 66 } 67 68 $this->productIDs = mpull($products, 'getID'); 69 } 70 } 71 72 public function willFilterPage(array $branches) { 73 $project_ids = mpull($branches, 'getReleephProjectID'); 74 75 $projects = id(new ReleephProductQuery()) 76 ->withIDs($project_ids) 77 ->setViewer($this->getViewer()) 78 ->execute(); 79 80 foreach ($branches as $key => $branch) { 81 $project_id = $project_ids[$key]; 82 if (isset($projects[$project_id])) { 83 $branch->attachProject($projects[$project_id]); 84 } else { 85 unset($branches[$key]); 86 } 87 } 88 89 if ($this->needCutPointCommits) { 90 $commit_phids = mpull($branches, 'getCutPointCommitPHID'); 91 $commits = id(new DiffusionCommitQuery()) 92 ->setViewer($this->getViewer()) 93 ->withPHIDs($commit_phids) 94 ->execute(); 95 $commits = mpull($commits, null, 'getPHID'); 96 97 foreach ($branches as $branch) { 98 $commit = idx($commits, $branch->getCutPointCommitPHID()); 99 $branch->attachCutPointCommit($commit); 100 } 101 } 102 103 return $branches; 104 } 105 106 private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 107 $where = array(); 108 109 if ($this->ids !== null) { 110 $where[] = qsprintf( 111 $conn_r, 112 'id IN (%Ld)', 113 $this->ids); 114 } 115 116 if ($this->phids !== null) { 117 $where[] = qsprintf( 118 $conn_r, 119 'phid IN (%Ls)', 120 $this->phids); 121 } 122 123 if ($this->productIDs !== null) { 124 $where[] = qsprintf( 125 $conn_r, 126 'releephProjectID IN (%Ld)', 127 $this->productIDs); 128 } 129 130 $status = $this->status; 131 switch ($status) { 132 case self::STATUS_ALL: 133 break; 134 case self::STATUS_OPEN: 135 $where[] = qsprintf( 136 $conn_r, 137 'isActive = 1'); 138 break; 139 default: 140 throw new Exception("Unknown status constant '{$status}'!"); 141 } 142 143 $where[] = $this->buildPagingClause($conn_r); 144 145 return $this->formatWhereClause($where); 146 } 147 148 public function getQueryApplicationClass() { 149 return 'PhabricatorReleephApplication'; 150 } 151 152 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |