Differential D21233 Diff 50569 src/infrastructure/diff/engine/PhabricatorInlineCommentAdjustmentEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/engine/PhabricatorInlineCommentAdjustmentEngine.php
- This file was moved from src/applications/differential/query/DifferentialInlineCommentQuery.php.
<?php | <?php | ||||
/** | final class PhabricatorInlineCommentAdjustmentEngine | ||||
* Temporary wrapper for transitioning Differential to ApplicationTransactions. | extends Phobject { | ||||
*/ | |||||
final class DifferentialInlineCommentQuery | |||||
extends PhabricatorOffsetPagedQuery { | |||||
// TODO: Remove this when this query eventually moves to PolicyAware. | |||||
private $viewer; | private $viewer; | ||||
private $inlines; | |||||
private $ids; | private $revision; | ||||
private $phids; | private $oldChangesets; | ||||
private $drafts; | private $newChangesets; | ||||
private $authorPHIDs; | |||||
private $revisionPHIDs; | |||||
private $deletedDrafts; | |||||
private $needHidden; | |||||
public function setViewer(PhabricatorUser $viewer) { | public function setViewer(PhabricatorUser $viewer) { | ||||
$this->viewer = $viewer; | $this->viewer = $viewer; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getViewer() { | public function getViewer() { | ||||
return $this->viewer; | return $this->viewer; | ||||
} | } | ||||
public function withIDs(array $ids) { | public function setInlines(array $inlines) { | ||||
$this->ids = $ids; | assert_instances_of($inlines, 'DifferentialInlineComment'); | ||||
$this->inlines = $inlines; | |||||
return $this; | return $this; | ||||
} | } | ||||
public function withPHIDs(array $phids) { | public function getInlines() { | ||||
$this->phids = $phids; | return $this->inlines; | ||||
return $this; | |||||
} | } | ||||
public function withDrafts($drafts) { | public function setOldChangesets(array $old_changesets) { | ||||
$this->drafts = $drafts; | assert_instances_of($old_changesets, 'DifferentialChangeset'); | ||||
$this->oldChangesets = $old_changesets; | |||||
return $this; | return $this; | ||||
} | } | ||||
public function withAuthorPHIDs(array $author_phids) { | public function getOldChangesets() { | ||||
$this->authorPHIDs = $author_phids; | return $this->oldChangesets; | ||||
return $this; | |||||
} | } | ||||
public function withRevisionPHIDs(array $revision_phids) { | public function setNewChangesets(array $new_changesets) { | ||||
$this->revisionPHIDs = $revision_phids; | assert_instances_of($new_changesets, 'DifferentialChangeset'); | ||||
$this->newChangesets = $new_changesets; | |||||
return $this; | return $this; | ||||
} | } | ||||
public function withDeletedDrafts($deleted_drafts) { | public function getNewChangesets() { | ||||
$this->deletedDrafts = $deleted_drafts; | return $this->newChangesets; | ||||
return $this; | |||||
} | } | ||||
public function needHidden($need) { | public function setRevision(DifferentialRevision $revision) { | ||||
$this->needHidden = $need; | $this->revision = $revision; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function execute() { | public function getRevision() { | ||||
$table = new DifferentialTransactionComment(); | return $this->revision; | ||||
$conn_r = $table->establishConnection('r'); | |||||
$data = queryfx_all( | |||||
$conn_r, | |||||
'SELECT * FROM %T %Q %Q', | |||||
$table->getTableName(), | |||||
$this->buildWhereClause($conn_r), | |||||
$this->buildLimitClause($conn_r)); | |||||
$comments = $table->loadAllFromArray($data); | |||||
if ($this->needHidden) { | |||||
$viewer_phid = $this->getViewer()->getPHID(); | |||||
if ($viewer_phid && $comments) { | |||||
$hidden = queryfx_all( | |||||
$conn_r, | |||||
'SELECT commentID FROM %T WHERE userPHID = %s | |||||
AND commentID IN (%Ls)', | |||||
id(new DifferentialHiddenComment())->getTableName(), | |||||
$viewer_phid, | |||||
mpull($comments, 'getID')); | |||||
$hidden = array_fuse(ipull($hidden, 'commentID')); | |||||
} else { | |||||
$hidden = array(); | |||||
} | |||||
foreach ($comments as $inline) { | |||||
$inline->attachIsHidden(isset($hidden[$inline->getID()])); | |||||
} | |||||
} | } | ||||
foreach ($comments as $key => $value) { | public function execute() { | ||||
$comments[$key] = DifferentialInlineComment::newFromModernComment( | |||||
$value); | |||||
} | |||||
return $comments; | |||||
} | |||||
public function executeOne() { | |||||
// TODO: Remove when this query moves to PolicyAware. | |||||
return head($this->execute()); | |||||
} | |||||
protected function buildWhereClause(AphrontDatabaseConnection $conn) { | |||||
$where = array(); | |||||
// Only find inline comments. | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'changesetID IS NOT NULL'); | |||||
if ($this->ids !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'id IN (%Ld)', | |||||
$this->ids); | |||||
} | |||||
if ($this->phids !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'phid IN (%Ls)', | |||||
$this->phids); | |||||
} | |||||
if ($this->revisionPHIDs !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'revisionPHID IN (%Ls)', | |||||
$this->revisionPHIDs); | |||||
} | |||||
if ($this->drafts === null) { | |||||
if ($this->deletedDrafts) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'(authorPHID = %s) OR (transactionPHID IS NOT NULL)', | |||||
$this->getViewer()->getPHID()); | |||||
} else { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'(authorPHID = %s AND isDeleted = 0) | |||||
OR (transactionPHID IS NOT NULL)', | |||||
$this->getViewer()->getPHID()); | |||||
} | |||||
} else if ($this->drafts) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'(authorPHID = %s AND isDeleted = 0) AND (transactionPHID IS NULL)', | |||||
$this->getViewer()->getPHID()); | |||||
} else { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'transactionPHID IS NOT NULL'); | |||||
} | |||||
return $this->formatWhereClause($conn, $where); | |||||
} | |||||
public function adjustInlinesForChangesets( | |||||
array $inlines, | |||||
array $old, | |||||
array $new, | |||||
DifferentialRevision $revision) { | |||||
assert_instances_of($inlines, 'DifferentialInlineComment'); | |||||
assert_instances_of($old, 'DifferentialChangeset'); | |||||
assert_instances_of($new, 'DifferentialChangeset'); | |||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$inlines = $this->getInlines(); | |||||
$revision = $this->getRevision(); | |||||
$old = $this->getOldChangesets(); | |||||
$new = $this->getNewChangesets(); | |||||
$no_ghosts = $viewer->compareUserSetting( | $no_ghosts = $viewer->compareUserSetting( | ||||
PhabricatorOlderInlinesSetting::SETTINGKEY, | PhabricatorOlderInlinesSetting::SETTINGKEY, | ||||
PhabricatorOlderInlinesSetting::VALUE_GHOST_INLINES_DISABLED); | PhabricatorOlderInlinesSetting::VALUE_GHOST_INLINES_DISABLED); | ||||
if ($no_ghosts) { | if ($no_ghosts) { | ||||
return $inlines; | return $inlines; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines |