[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorRepositoryRefCursorQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $repositoryPHIDs; 7 private $refTypes; 8 private $refNames; 9 10 public function withRepositoryPHIDs(array $phids) { 11 $this->repositoryPHIDs = $phids; 12 return $this; 13 } 14 15 public function withRefTypes(array $types) { 16 $this->refTypes = $types; 17 return $this; 18 } 19 20 public function withRefNames(array $names) { 21 $this->refNames = $names; 22 return $this; 23 } 24 25 protected function loadPage() { 26 $table = new PhabricatorRepositoryRefCursor(); 27 $conn_r = $table->establishConnection('r'); 28 29 $data = queryfx_all( 30 $conn_r, 31 'SELECT * FROM %T r %Q %Q %Q', 32 $table->getTableName(), 33 $this->buildWhereClause($conn_r), 34 $this->buildOrderClause($conn_r), 35 $this->buildLimitClause($conn_r)); 36 37 return $table->loadAllFromArray($data); 38 } 39 40 public function willFilterPage(array $refs) { 41 $repository_phids = mpull($refs, 'getRepositoryPHID'); 42 43 $repositories = id(new PhabricatorRepositoryQuery()) 44 ->setViewer($this->getViewer()) 45 ->setParentQuery($this) 46 ->withPHIDs($repository_phids) 47 ->execute(); 48 $repositories = mpull($repositories, null, 'getPHID'); 49 50 foreach ($refs as $key => $ref) { 51 $repository = idx($repositories, $ref->getRepositoryPHID()); 52 if (!$repository) { 53 unset($refs[$key]); 54 continue; 55 } 56 $ref->attachRepository($repository); 57 } 58 59 return $refs; 60 } 61 62 private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 63 $where = array(); 64 65 if ($this->repositoryPHIDs !== null) { 66 $where[] = qsprintf( 67 $conn_r, 68 'repositoryPHID IN (%Ls)', 69 $this->repositoryPHIDs); 70 } 71 72 if ($this->refTypes !== null) { 73 $where[] = qsprintf( 74 $conn_r, 75 'refType IN (%Ls)', 76 $this->refTypes); 77 } 78 79 if ($this->refNames !== null) { 80 $name_hashes = array(); 81 foreach ($this->refNames as $name) { 82 $name_hashes[] = PhabricatorHash::digestForIndex($name); 83 } 84 85 $where[] = qsprintf( 86 $conn_r, 87 'refNameHash IN (%Ls)', 88 $name_hashes); 89 } 90 91 $where[] = $this->buildPagingClause($conn_r); 92 93 return $this->formatWhereClause($where); 94 } 95 96 public function getQueryApplicationClass() { 97 return 'PhabricatorDiffusionApplication'; 98 } 99 100 }
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 |