[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Temporary wrapper for transitioning Differential to ApplicationTransactions. 5 */ 6 final class DifferentialInlineCommentQuery 7 extends PhabricatorOffsetPagedQuery { 8 9 private $revisionIDs; 10 private $notDraft; 11 private $ids; 12 private $commentIDs; 13 14 private $viewerAndChangesetIDs; 15 private $draftComments; 16 private $draftsByAuthors; 17 18 public function withRevisionIDs(array $ids) { 19 $this->revisionIDs = $ids; 20 return $this; 21 } 22 23 public function withNotDraft($not_draft) { 24 $this->notDraft = $not_draft; 25 return $this; 26 } 27 28 public function withIDs(array $ids) { 29 $this->ids = $ids; 30 return $this; 31 } 32 33 public function withViewerAndChangesetIDs($author_phid, array $ids) { 34 $this->viewerAndChangesetIDs = array($author_phid, $ids); 35 return $this; 36 } 37 38 public function withDraftComments($author_phid, $revision_id) { 39 $this->draftComments = array($author_phid, $revision_id); 40 return $this; 41 } 42 43 public function withDraftsByAuthors(array $author_phids) { 44 $this->draftsByAuthors = $author_phids; 45 return $this; 46 } 47 48 public function execute() { 49 $table = new DifferentialTransactionComment(); 50 $conn_r = $table->establishConnection('r'); 51 52 $data = queryfx_all( 53 $conn_r, 54 'SELECT * FROM %T %Q %Q', 55 $table->getTableName(), 56 $this->buildWhereClause($conn_r), 57 $this->buildLimitClause($conn_r)); 58 59 $comments = $table->loadAllFromArray($data); 60 61 foreach ($comments as $key => $value) { 62 $comments[$key] = DifferentialInlineComment::newFromModernComment( 63 $value); 64 } 65 66 return $comments; 67 } 68 69 public function executeOne() { 70 return head($this->execute()); 71 } 72 73 private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 74 $where = array(); 75 76 // Only find inline comments. 77 $where[] = qsprintf( 78 $conn_r, 79 'changesetID IS NOT NULL'); 80 81 if ($this->revisionIDs) { 82 83 // Look up revision PHIDs. 84 $revision_phids = queryfx_all( 85 $conn_r, 86 'SELECT phid FROM %T WHERE id IN (%Ld)', 87 id(new DifferentialRevision())->getTableName(), 88 $this->revisionIDs); 89 90 if (!$revision_phids) { 91 throw new PhabricatorEmptyQueryException(); 92 } 93 $revision_phids = ipull($revision_phids, 'phid'); 94 95 $where[] = qsprintf( 96 $conn_r, 97 'revisionPHID IN (%Ls)', 98 $revision_phids); 99 } 100 101 if ($this->notDraft) { 102 $where[] = qsprintf( 103 $conn_r, 104 'transactionPHID IS NOT NULL'); 105 } 106 107 if ($this->ids) { 108 $where[] = qsprintf( 109 $conn_r, 110 'id IN (%Ld)', 111 $this->ids); 112 } 113 114 if ($this->viewerAndChangesetIDs) { 115 list($phid, $ids) = $this->viewerAndChangesetIDs; 116 $where[] = qsprintf( 117 $conn_r, 118 'changesetID IN (%Ld) AND 119 (authorPHID = %s OR transactionPHID IS NOT NULL)', 120 $ids, 121 $phid); 122 } 123 124 if ($this->draftComments) { 125 list($phid, $rev_id) = $this->draftComments; 126 127 $rev_phid = queryfx_one( 128 $conn_r, 129 'SELECT phid FROM %T WHERE id = %d', 130 id(new DifferentialRevision())->getTableName(), 131 $rev_id); 132 133 if (!$rev_phid) { 134 throw new PhabricatorEmptyQueryException(); 135 } 136 137 $rev_phid = $rev_phid['phid']; 138 139 $where[] = qsprintf( 140 $conn_r, 141 'authorPHID = %s AND revisionPHID = %s AND transactionPHID IS NULL', 142 $phid, 143 $rev_phid); 144 } 145 146 if ($this->draftsByAuthors) { 147 $where[] = qsprintf( 148 $conn_r, 149 'authorPHID IN (%Ls) AND transactionPHID IS NULL', 150 $this->draftsByAuthors); 151 } 152 153 return $this->formatWhereClause($where); 154 } 155 156 }
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 |