2013-06-21 12:54:56 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Temporary wrapper for transitioning Differential to ApplicationTransactions.
|
|
|
|
*/
|
|
|
|
final class DifferentialInlineCommentQuery
|
|
|
|
extends PhabricatorOffsetPagedQuery {
|
|
|
|
|
2015-04-20 14:33:58 -07:00
|
|
|
// TODO: Remove this when this query eventually moves to PolicyAware.
|
|
|
|
private $viewer;
|
|
|
|
|
2013-06-21 12:54:56 -07:00
|
|
|
private $ids;
|
2015-03-08 13:04:38 -07:00
|
|
|
private $phids;
|
2015-04-20 14:33:58 -07:00
|
|
|
private $drafts;
|
|
|
|
private $authorPHIDs;
|
|
|
|
private $revisionPHIDs;
|
|
|
|
private $deletedDrafts;
|
|
|
|
|
|
|
|
public function setViewer(PhabricatorUser $viewer) {
|
|
|
|
$this->viewer = $viewer;
|
2013-06-21 12:54:56 -07:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-04-20 14:33:58 -07:00
|
|
|
public function getViewer() {
|
|
|
|
return $this->viewer;
|
2013-06-21 12:54:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-03-08 13:04:38 -07:00
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-04-20 14:33:58 -07:00
|
|
|
public function withDrafts($drafts) {
|
|
|
|
$this->drafts = $drafts;
|
2013-06-21 12:54:56 -07:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-04-20 14:33:58 -07:00
|
|
|
public function withAuthorPHIDs(array $author_phids) {
|
|
|
|
$this->authorPHIDs = $author_phids;
|
2013-06-21 12:54:56 -07:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-04-20 14:33:58 -07:00
|
|
|
public function withRevisionPHIDs(array $revision_phids) {
|
|
|
|
$this->revisionPHIDs = $revision_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withDeletedDrafts($deleted_drafts) {
|
|
|
|
$this->deletedDrafts = $deleted_drafts;
|
2013-06-21 12:54:56 -07:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
Migrate all Differential inline comments to ApplicationTransactions
Summary:
Ref T2222. This implements step (1) described there, which is moving over all the inline comments.
The old and new tables are simliar. The only real trick here is that `transactionPHID` and `legacyCommentID` mean roughly the same thing (`null` if the inline is a draft, non-null if it has been submitted) but we don't have real `transactionPHID`s yet. We just make some up -- we'll backfill them later.
Two risks here:
- I need to take a second look at the keys on this table. I think we need to tweak them a bit, and it will be less disruptive to do that before this migration than after.
- This will take a while for Facebook, and other large installs with tens of thousands of revisions. I'll communicate this.
I'm otherwise pretty satisfied with this, seems to work well and is pretty low risk / non-disruptive.
Test Plan:
- Before migrating, then after migrating:
- Made a bunch of inlines (drafts, submitted).
- Edited and deleted inlines.
- Verified inlines showed up in preview.
- Verified that inlines aren't indexed when they're drafts (`bin/search index D935`).
- Verified that inlines ARE indexed when they're not drafts.
- Verified that drafts inlines make revisions appear as "with draft" in the revision list.
- Made left, right, and draft inlines.
- Migrated (`bin/storage upgrade`).
- Verified that my inlines from before the migration still showed up.
- (Repeated all the stuff above.)
- Manually inspected the inline comment table.
Reviewers: btrahan
Reviewed By: btrahan
CC: FacebookPOC, aran
Maniphest Tasks: T2222
Differential Revision: https://secure.phabricator.com/D7139
2013-10-19 05:03:25 -07:00
|
|
|
$table = new DifferentialTransactionComment();
|
2013-06-21 12:54:56 -07:00
|
|
|
$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));
|
|
|
|
|
Migrate all Differential inline comments to ApplicationTransactions
Summary:
Ref T2222. This implements step (1) described there, which is moving over all the inline comments.
The old and new tables are simliar. The only real trick here is that `transactionPHID` and `legacyCommentID` mean roughly the same thing (`null` if the inline is a draft, non-null if it has been submitted) but we don't have real `transactionPHID`s yet. We just make some up -- we'll backfill them later.
Two risks here:
- I need to take a second look at the keys on this table. I think we need to tweak them a bit, and it will be less disruptive to do that before this migration than after.
- This will take a while for Facebook, and other large installs with tens of thousands of revisions. I'll communicate this.
I'm otherwise pretty satisfied with this, seems to work well and is pretty low risk / non-disruptive.
Test Plan:
- Before migrating, then after migrating:
- Made a bunch of inlines (drafts, submitted).
- Edited and deleted inlines.
- Verified inlines showed up in preview.
- Verified that inlines aren't indexed when they're drafts (`bin/search index D935`).
- Verified that inlines ARE indexed when they're not drafts.
- Verified that drafts inlines make revisions appear as "with draft" in the revision list.
- Made left, right, and draft inlines.
- Migrated (`bin/storage upgrade`).
- Verified that my inlines from before the migration still showed up.
- (Repeated all the stuff above.)
- Manually inspected the inline comment table.
Reviewers: btrahan
Reviewed By: btrahan
CC: FacebookPOC, aran
Maniphest Tasks: T2222
Differential Revision: https://secure.phabricator.com/D7139
2013-10-19 05:03:25 -07:00
|
|
|
$comments = $table->loadAllFromArray($data);
|
|
|
|
|
|
|
|
foreach ($comments as $key => $value) {
|
|
|
|
$comments[$key] = DifferentialInlineComment::newFromModernComment(
|
|
|
|
$value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $comments;
|
2013-06-21 12:54:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function executeOne() {
|
2015-04-20 14:33:58 -07:00
|
|
|
// TODO: Remove when this query moves to PolicyAware.
|
2013-06-21 12:54:56 -07:00
|
|
|
return head($this->execute());
|
|
|
|
}
|
|
|
|
|
Make buildWhereClause() a method of AphrontCursorPagedPolicyAwareQuery
Summary:
Ref T4100. Ref T5595.
To support a unified "Projects:" query across all applications, a future diff is going to add a set of "Edge Logic" capabilities to `PolicyAwareQuery` which write the required SELECT, JOIN, WHERE, HAVING and GROUP clauses for you.
With the addition of "Edge Logic", we'll have three systems which may need to build components of query claues: ordering/paging, customfields/applicationsearch, and edge logic.
For most clauses, queries don't currently call into the parent explicitly to get default components. I want to move more query construction logic up the class tree so it can be shared.
For most methods, this isn't a problem, but many subclasses define a `buildWhereClause()`. Make all such definitions protected and consistent.
This causes no behavioral changes.
Test Plan: Ran `arc unit --everything`, which does a pretty through job of verifying this statically.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: yelirekim, hach-que, epriestley
Maniphest Tasks: T4100, T5595
Differential Revision: https://secure.phabricator.com/D12453
2015-04-18 07:08:30 -07:00
|
|
|
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
2013-06-21 12:54:56 -07:00
|
|
|
$where = array();
|
|
|
|
|
Migrate all Differential inline comments to ApplicationTransactions
Summary:
Ref T2222. This implements step (1) described there, which is moving over all the inline comments.
The old and new tables are simliar. The only real trick here is that `transactionPHID` and `legacyCommentID` mean roughly the same thing (`null` if the inline is a draft, non-null if it has been submitted) but we don't have real `transactionPHID`s yet. We just make some up -- we'll backfill them later.
Two risks here:
- I need to take a second look at the keys on this table. I think we need to tweak them a bit, and it will be less disruptive to do that before this migration than after.
- This will take a while for Facebook, and other large installs with tens of thousands of revisions. I'll communicate this.
I'm otherwise pretty satisfied with this, seems to work well and is pretty low risk / non-disruptive.
Test Plan:
- Before migrating, then after migrating:
- Made a bunch of inlines (drafts, submitted).
- Edited and deleted inlines.
- Verified inlines showed up in preview.
- Verified that inlines aren't indexed when they're drafts (`bin/search index D935`).
- Verified that inlines ARE indexed when they're not drafts.
- Verified that drafts inlines make revisions appear as "with draft" in the revision list.
- Made left, right, and draft inlines.
- Migrated (`bin/storage upgrade`).
- Verified that my inlines from before the migration still showed up.
- (Repeated all the stuff above.)
- Manually inspected the inline comment table.
Reviewers: btrahan
Reviewed By: btrahan
CC: FacebookPOC, aran
Maniphest Tasks: T2222
Differential Revision: https://secure.phabricator.com/D7139
2013-10-19 05:03:25 -07:00
|
|
|
// Only find inline comments.
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'changesetID IS NOT NULL');
|
|
|
|
|
2015-04-20 14:33:58 -07:00
|
|
|
if ($this->ids !== null) {
|
2013-06-21 12:54:56 -07:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2015-03-08 13:04:38 -07:00
|
|
|
if ($this->phids !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2015-04-20 14:33:58 -07:00
|
|
|
if ($this->revisionPHIDs !== null) {
|
2013-06-21 12:54:56 -07:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-04-20 14:33:58 -07:00
|
|
|
'revisionPHID IN (%Ls)',
|
|
|
|
$this->revisionPHIDs);
|
2013-06-21 12:54:56 -07:00
|
|
|
}
|
|
|
|
|
2015-04-20 14:33:58 -07:00
|
|
|
if ($this->drafts === null) {
|
|
|
|
if ($this->deletedDrafts) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'(authorPHID = %s) OR (transactionPHID IS NOT NULL)',
|
|
|
|
$this->getViewer()->getPHID());
|
|
|
|
} else {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'(authorPHID = %s AND isDeleted = 0)
|
|
|
|
OR (transactionPHID IS NOT NULL)',
|
|
|
|
$this->getViewer()->getPHID());
|
Migrate all Differential inline comments to ApplicationTransactions
Summary:
Ref T2222. This implements step (1) described there, which is moving over all the inline comments.
The old and new tables are simliar. The only real trick here is that `transactionPHID` and `legacyCommentID` mean roughly the same thing (`null` if the inline is a draft, non-null if it has been submitted) but we don't have real `transactionPHID`s yet. We just make some up -- we'll backfill them later.
Two risks here:
- I need to take a second look at the keys on this table. I think we need to tweak them a bit, and it will be less disruptive to do that before this migration than after.
- This will take a while for Facebook, and other large installs with tens of thousands of revisions. I'll communicate this.
I'm otherwise pretty satisfied with this, seems to work well and is pretty low risk / non-disruptive.
Test Plan:
- Before migrating, then after migrating:
- Made a bunch of inlines (drafts, submitted).
- Edited and deleted inlines.
- Verified inlines showed up in preview.
- Verified that inlines aren't indexed when they're drafts (`bin/search index D935`).
- Verified that inlines ARE indexed when they're not drafts.
- Verified that drafts inlines make revisions appear as "with draft" in the revision list.
- Made left, right, and draft inlines.
- Migrated (`bin/storage upgrade`).
- Verified that my inlines from before the migration still showed up.
- (Repeated all the stuff above.)
- Manually inspected the inline comment table.
Reviewers: btrahan
Reviewed By: btrahan
CC: FacebookPOC, aran
Maniphest Tasks: T2222
Differential Revision: https://secure.phabricator.com/D7139
2013-10-19 05:03:25 -07:00
|
|
|
}
|
2015-04-20 14:33:58 -07:00
|
|
|
} else if ($this->drafts) {
|
2013-06-21 12:54:56 -07:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-04-20 14:33:58 -07:00
|
|
|
'(authorPHID = %s AND isDeleted = 0) AND (transactionPHID IS NULL)',
|
|
|
|
$this->getViewer()->getPHID());
|
|
|
|
} else {
|
2013-06-21 12:54:56 -07:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-04-20 14:33:58 -07:00
|
|
|
'transactionPHID IS NOT NULL');
|
2013-06-21 12:54:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|