1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-10 13:58:34 +01:00
phorge-phorge/src/applications/differential/query/DifferentialTransactionQuery.php
epriestley 4d86d51125 Prepare TransactionCommentQuery for extension
Summary:
Ref T2009. Ref T1460. The way Diffusion and Differential load inlines is horrible garbage right now:

  - Differential does an ad-hoc query to get the PHIDs, then does a real load to policy check.
  - Diffusion completely fakes things. In practice this is not a policy violation, but it's dangerous.

Make TransactionCommentQuery extensible so we can subclass it and get the query building correctly in the right Query layer.

Specifically, the Diffusion and Differential subclasses of this Query will add appropriate `withX()` methods to let us express the query in SQL.

Test Plan: Loaded, previewed, edited, and submitted inlines in Differential and Diffusion

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2009, T1460

Differential Revision: https://secure.phabricator.com/D12026
2015-03-09 14:11:18 -07:00

48 lines
1.2 KiB
PHP

<?php
final class DifferentialTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new DifferentialTransaction();
}
public static function loadUnsubmittedInlineComments(
PhabricatorUser $viewer,
DifferentialRevision $revision) {
// TODO: Subclass ApplicationTransactionCommentQuery to do this for real.
$table = new DifferentialTransactionComment();
$conn_r = $table->establishConnection('r');
$phids = queryfx_all(
$conn_r,
'SELECT phid FROM %T
WHERE revisionPHID = %s
AND authorPHID = %s
AND transactionPHID IS NULL
AND isDeleted = 0',
$table->getTableName(),
$revision->getPHID(),
$viewer->getPHID());
$phids = ipull($phids, 'phid');
if (!$phids) {
return array();
}
$comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery())
->setTemplate(new DifferentialTransactionComment())
->setViewer($viewer)
->withPHIDs($phids)
->execute();
$comments = PhabricatorInlineCommentController::loadAndAttachReplies(
$viewer,
$comments);
return $comments;
}
}