1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-01 11:12:42 +01:00
phorge-phorge/src/applications/differential/storage/DifferentialTransactionComment.php

113 lines
3.1 KiB
PHP
Raw Normal View History

<?php
final class DifferentialTransactionComment
extends PhabricatorApplicationTransactionComment {
protected $revisionPHID;
protected $changesetID;
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
protected $isNewFile = 0;
protected $lineNumber = 0;
protected $lineLength = 0;
protected $fixedState;
protected $hasReplies = 0;
protected $replyToCommentPHID;
private $replyToComment = self::ATTACHABLE;
private $isHidden = self::ATTACHABLE;
public function getApplicationTransactionObject() {
return new DifferentialTransaction();
}
public function attachReplyToComment(
DifferentialTransactionComment $comment = null) {
$this->replyToComment = $comment;
return $this;
}
public function getReplyToComment() {
return $this->assertAttached($this->replyToComment);
}
protected function getConfiguration() {
$config = parent::getConfiguration();
$config[self::CONFIG_COLUMN_SCHEMA] = array(
'revisionPHID' => 'phid?',
'changesetID' => 'id?',
'isNewFile' => 'bool',
'lineNumber' => 'uint32',
'lineLength' => 'uint32',
'fixedState' => 'text12?',
'hasReplies' => 'bool',
'replyToCommentPHID' => 'phid?',
) + $config[self::CONFIG_COLUMN_SCHEMA];
$config[self::CONFIG_KEY_SCHEMA] = array(
'key_draft' => array(
'columns' => array('authorPHID', 'transactionPHID'),
),
'key_changeset' => array(
'columns' => array('changesetID'),
),
'key_revision' => array(
'columns' => array('revisionPHID'),
),
) + $config[self::CONFIG_KEY_SCHEMA];
return $config;
}
public function shouldUseMarkupCache($field) {
// Only cache submitted comments.
return ($this->getTransactionPHID() != null);
}
public static function sortAndGroupInlines(
array $inlines,
array $changesets) {
assert_instances_of($inlines, 'DifferentialTransaction');
assert_instances_of($changesets, 'DifferentialChangeset');
$changesets = mpull($changesets, null, 'getID');
$changesets = msort($changesets, 'getFilename');
// Group the changesets by file and reorder them by display order.
$inline_groups = array();
foreach ($inlines as $inline) {
$changeset_id = $inline->getComment()->getChangesetID();
$inline_groups[$changeset_id][] = $inline;
}
$inline_groups = array_select_keys($inline_groups, array_keys($changesets));
foreach ($inline_groups as $changeset_id => $group) {
// Sort the group of inlines by line number.
$items = array();
foreach ($group as $inline) {
$comment = $inline->getComment();
$num = $comment->getLineNumber();
$len = $comment->getLineLength();
$id = $comment->getID();
$items[] = array(
'inline' => $inline,
'sort' => sprintf('~%010d%010d%010d', $num, $len, $id),
);
}
$items = isort($items, 'sort');
$items = ipull($items, 'inline');
$inline_groups[$changeset_id] = $items;
}
return $inline_groups;
}
public function getIsHidden() {
return $this->assertAttached($this->isHidden);
}
public function attachIsHidden($hidden) {
$this->isHidden = $hidden;
return $this;
}
}