1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 07:50:57 +01:00

Migrate Audit comment text into new storage

Summary:
Ref T4896. This is substantially similar to D8196.

Migrate the comment text out of the `audit_comment` table and into the `audit_transaction_comment` table. Do double reads on `PhabricatorAuditComment` so the APIs aren't disturbed. The old table is still updated.

Test Plan:
  - Before applying migration, cleared cache and browsed around. Things looked fine, except no comment text.
  - Applied migration.
  - Cleared cache, browsed around, saw all my old comments.
  - Added some new comments.
  - Spot checked migrated and new rows in database.

Reviewers: btrahan, joshuaspence

Reviewed By: joshuaspence

Subscribers: epriestley

Maniphest Tasks: T4896

Differential Revision: https://secure.phabricator.com/D10020
This commit is contained in:
epriestley 2014-07-24 18:00:30 -07:00
parent dc5c87f74c
commit 3d78c0eff7
3 changed files with 157 additions and 5 deletions

View file

@ -0,0 +1,61 @@
<?php
$conn_w = id(new PhabricatorAuditTransaction())->establishConnection('w');
$rows = new LiskRawMigrationIterator($conn_w, 'audit_comment');
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize();
echo "Migrating Audit comment text to modern storage...\n";
foreach ($rows as $row) {
$id = $row['id'];
echo "Migrating Audit comment {$id}...\n";
if (!strlen($row['content'])) {
echo "Comment has no text, continuing.\n";
continue;
}
$xaction_phid = PhabricatorPHID::generateNewPHID(
PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST,
PhabricatorRepositoryCommitPHIDType::TYPECONST);
$comment_phid = PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_XCMT,
PhabricatorRepositoryCommitPHIDType::TYPECONST);
queryfx(
$conn_w,
'INSERT IGNORE INTO %T
(phid, transactionPHID, authorPHID, viewPolicy, editPolicy,
commentVersion, content, contentSource, isDeleted,
dateCreated, dateModified, commitPHID, pathID,
legacyCommentID)
VALUES (%s, %s, %s, %s, %s,
%d, %s, %s, %d,
%d, %d, %s, %nd,
%d)',
'audit_transaction_comment',
// phid, transactionPHID, authorPHID, viewPolicy, editPolicy
$comment_phid,
$xaction_phid,
$row['actorPHID'],
'public',
$row['actorPHID'],
// commentVersion, content, contentSource, isDeleted
1,
$row['content'],
$content_source,
0,
// dateCreated, dateModified, commitPHID, pathID, legacyCommentID
$row['dateCreated'],
$row['dateModified'],
$row['targetPHID'],
null,
$row['id']);
}
echo "Done.\n";

View file

@ -12,16 +12,40 @@ final class PhabricatorAuditComment extends PhabricatorAuditDAO
protected $actorPHID;
protected $targetPHID;
protected $action;
protected $content;
protected $content = '';
protected $metadata = array();
private $proxyComment;
public static function loadComments(
PhabricatorUser $viewer,
$commit_phid) {
return id(new PhabricatorAuditComment())->loadAllWhere(
$comments = id(new PhabricatorAuditComment())->loadAllWhere(
'targetPHID = %s',
$commit_phid);
if ($comments) {
$table = new PhabricatorAuditTransactionComment();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T WHERE legacyCommentID IN (%Ld) AND pathID IS NULL',
$table->getTableName(),
mpull($comments, 'getID'));
$texts = $table->loadAllFromArray($data);
$texts = mpull($texts, null, 'getLegacyCommentID');
foreach ($comments as $comment) {
$text = idx($texts, $comment->getID());
if ($text) {
$comment->setProxyComment($text);
}
}
}
return $comments;
}
public function getConfiguration() {
@ -38,6 +62,70 @@ final class PhabricatorAuditComment extends PhabricatorAuditDAO
}
public function getContent() {
return $this->getProxyComment()->getContent();
}
public function setContent($content) {
// NOTE: We no longer read this field, but there's no cost to continuing
// to write it in case something goes horribly wrong, since it makes it
// far easier to back out of this.
$this->content = $content;
$this->getProxyComment()->setContent($content);
return $this;
}
private function getProxyComment() {
if (!$this->proxyComment) {
$this->proxyComment = new PhabricatorAuditTransactionComment();
}
return $this->proxyComment;
}
public function setProxyComment(PhabricatorAuditTransactionComment $proxy) {
if ($this->proxyComment) {
throw new Exception(pht('You can not overwrite a proxy comment.'));
}
$this->proxyComment = $proxy;
return $this;
}
public function setTargetPHID($target_phid) {
$this->getProxyComment()->setCommitPHID($target_phid);
return parent::setTargetPHID($target_phid);
}
public function save() {
$this->openTransaction();
$result = parent::save();
if (strlen($this->getContent())) {
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array());
$xaction_phid = PhabricatorPHID::generateNewPHID(
PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST,
PhabricatorRepositoryCommitPHIDType::TYPECONST);
$proxy = $this->getProxyComment();
$proxy
->setAuthorPHID($this->getActorPHID())
->setViewPolicy('public')
->setEditPolicy($this->getActorPHID())
->setContentSource($content_source)
->setCommentVersion(1)
->setLegacyCommentID($this->getID())
->setTransactionPHID($xaction_phid)
->save();
}
$this->saveTransaction();
return $result;
}
/* -( PhabricatorMarkupInterface Implementation )-------------------------- */

View file

@ -33,7 +33,8 @@ final class PhabricatorAuditInlineComment
$commit_phid) {
$inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere(
'authorPHID = %s AND commitPHID = %s AND transactionPHID IS NULL',
'authorPHID = %s AND commitPHID = %s AND transactionPHID IS NULL
AND pathID IS NOT NULL',
$viewer->getPHID(),
$commit_phid);
@ -45,7 +46,8 @@ final class PhabricatorAuditInlineComment
$commit_phid) {
$inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere(
'commitPHID = %s AND transactionPHID IS NOT NULL',
'commitPHID = %s AND transactionPHID IS NOT NULL
AND pathID IS NOT NULL',
$commit_phid);
return self::buildProxies($inlines);
@ -58,7 +60,8 @@ final class PhabricatorAuditInlineComment
if ($path_id === null) {
$inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere(
'commitPHID = %s AND (transactionPHID IS NOT NULL OR authorPHID = %s)',
'commitPHID = %s AND (transactionPHID IS NOT NULL OR authorPHID = %s)
AND pathID IS NOT NULL',
$commit_phid,
$viewer->getPHID());
} else {