[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class HeraldTranscriptQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $ids; 7 private $objectPHIDs; 8 private $needPartialRecords; 9 10 public function withIDs(array $ids) { 11 $this->ids = $ids; 12 return $this; 13 } 14 15 public function withObjectPHIDs(array $phids) { 16 $this->objectPHIDs = $phids; 17 return $this; 18 } 19 20 public function needPartialRecords($need_partial) { 21 $this->needPartialRecords = $need_partial; 22 return $this; 23 } 24 25 public function loadPage() { 26 $transcript = new HeraldTranscript(); 27 $conn_r = $transcript->establishConnection('r'); 28 29 // NOTE: Transcripts include a potentially enormous amount of serialized 30 // data, so we're loading only some of the fields here if the caller asked 31 // for partial records. 32 33 if ($this->needPartialRecords) { 34 $fields = implode( 35 ', ', 36 array( 37 'id', 38 'phid', 39 'objectPHID', 40 'time', 41 'duration', 42 'dryRun', 43 'host', 44 )); 45 } else { 46 $fields = '*'; 47 } 48 49 $rows = queryfx_all( 50 $conn_r, 51 'SELECT %Q FROM %T t %Q %Q %Q', 52 $fields, 53 $transcript->getTableName(), 54 $this->buildWhereClause($conn_r), 55 $this->buildOrderClause($conn_r), 56 $this->buildLimitClause($conn_r)); 57 58 $transcripts = $transcript->loadAllFromArray($rows); 59 60 if ($this->needPartialRecords) { 61 // Make sure nothing tries to write these; they aren't complete. 62 foreach ($transcripts as $transcript) { 63 $transcript->makeEphemeral(); 64 } 65 } 66 67 return $transcripts; 68 } 69 70 public function willFilterPage(array $transcripts) { 71 $phids = mpull($transcripts, 'getObjectPHID'); 72 73 $objects = id(new PhabricatorObjectQuery()) 74 ->setViewer($this->getViewer()) 75 ->withPHIDs($phids) 76 ->execute(); 77 78 foreach ($transcripts as $key => $transcript) { 79 if (empty($objects[$transcript->getObjectPHID()])) { 80 $this->didRejectResult($transcript); 81 unset($transcripts[$key]); 82 } 83 } 84 85 return $transcripts; 86 } 87 88 public function buildWhereClause(AphrontDatabaseConnection $conn_r) { 89 $where = array(); 90 91 if ($this->ids) { 92 $where[] = qsprintf( 93 $conn_r, 94 'id IN (%Ld)', 95 $this->ids); 96 } 97 98 if ($this->objectPHIDs) { 99 $where[] = qsprintf( 100 $conn_r, 101 'objectPHID in (%Ls)', 102 $this->objectPHIDs); 103 } 104 105 $where[] = $this->buildPagingClause($conn_r); 106 107 return $this->formatWhereClause($where); 108 } 109 110 public function getQueryApplicationClass() { 111 return 'PhabricatorHeraldApplication'; 112 } 113 114 }
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 |