1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 19:32:40 +01:00
phorge-phorge/src/applications/differential/controller/DifferentialInlineCommentEditController.php

97 lines
2.5 KiB
PHP
Raw Normal View History

2011-02-02 01:42:36 +01:00
<?php
final class DifferentialInlineCommentEditController
extends PhabricatorInlineCommentController {
2011-02-02 01:42:36 +01:00
private $revisionID;
public function willProcessRequest(array $data) {
$this->revisionID = $data['id'];
}
protected function createComment() {
2011-02-02 01:42:36 +01:00
// Verify revision and changeset correspond to actual objects.
$revision_id = $this->revisionID;
$changeset_id = $this->getChangesetID();
2011-02-02 01:42:36 +01:00
$viewer = $this->getRequest()->getUser();
$revision = id(new DifferentialRevisionQuery())
->setViewer($viewer)
->withIDs(array($revision_id))
->executeOne();
if (!$revision) {
throw new Exception("Invalid revision ID!");
2011-02-02 01:42:36 +01:00
}
2011-02-02 19:10:25 +01:00
if (!id(new DifferentialChangeset())->load($changeset_id)) {
throw new Exception("Invalid changeset ID!");
}
return id(new DifferentialInlineComment())
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 14:03:25 +02:00
->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, for now, although the schema now
// supports it.
if (!$inline->isDraft()) {
return false;
}
// Inline must be attached to the active revision.
if ($inline->getRevisionID() != $this->revisionID) {
return false;
}
return true;
}
protected function deleteComment(PhabricatorInlineCommentInterface $inline) {
$inline->openTransaction();
DifferentialDraft::deleteHasDraft(
$inline->getAuthorPHID(),
$inline->getRevisionPHID(),
$inline->getPHID());
$inline->delete();
$inline->saveTransaction();
}
protected function saveComment(PhabricatorInlineCommentInterface $inline) {
$inline->openTransaction();
$inline->save();
DifferentialDraft::markHasDraft(
$inline->getAuthorPHID(),
$inline->getRevisionPHID(),
$inline->getPHID());
$inline->saveTransaction();
}
2011-02-02 01:42:36 +01:00
}