mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 08:12:40 +01:00
f010730e49
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
76 lines
1.8 KiB
PHP
76 lines
1.8 KiB
PHP
<?php
|
|
|
|
final class DifferentialInlineCommentEditController
|
|
extends PhabricatorInlineCommentController {
|
|
|
|
private $revisionID;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->revisionID = $data['id'];
|
|
}
|
|
|
|
protected function createComment() {
|
|
|
|
// Verify revision and changeset correspond to actual objects.
|
|
$revision_id = $this->revisionID;
|
|
$changeset_id = $this->getChangesetID();
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($revision_id))
|
|
->executeOne();
|
|
|
|
if (!$revision) {
|
|
throw new Exception("Invalid revision ID!");
|
|
}
|
|
|
|
if (!id(new DifferentialChangeset())->load($changeset_id)) {
|
|
throw new Exception("Invalid changeset ID!");
|
|
}
|
|
|
|
return id(new DifferentialInlineComment())
|
|
->setRevision($revision)
|
|
->setChangesetID($changeset_id);
|
|
}
|
|
|
|
protected function loadComment($id) {
|
|
return id(new DifferentialInlineCommentQuery())
|
|
->withIDs(array($id))
|
|
->executeOne();
|
|
}
|
|
|
|
protected function loadCommentForEdit($id) {
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
$inline = $this->loadComment($id);
|
|
if (!$this->canEditInlineComment($user, $inline)) {
|
|
throw new Exception("That comment is not editable!");
|
|
}
|
|
return $inline;
|
|
}
|
|
|
|
private function canEditInlineComment(
|
|
PhabricatorUser $user,
|
|
DifferentialInlineComment $inline) {
|
|
|
|
// Only the author may edit a comment.
|
|
if ($inline->getAuthorPHID() != $user->getPHID()) {
|
|
return false;
|
|
}
|
|
|
|
// Saved comments may not be edited.
|
|
if ($inline->getCommentID()) {
|
|
return false;
|
|
}
|
|
|
|
// Inline must be attached to the active revision.
|
|
if ($inline->getRevisionID() != $this->revisionID) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|