1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Use standard infrastructure to attach commits to other objects

Summary:
Ref T4896. Now that we have a transaction editor, we can delete a giant block of hacks.

I believe this also resolves the commit/task attachment issues @joshuaspence and @mbishopim3 mentioned.

Test Plan: Attached and detached commits and tasks.

Reviewers: btrahan, joshuaspence, mbishopim3

Reviewed By: mbishopim3

Subscribers: mbishopim3, epriestley, joshuaspence

Maniphest Tasks: T4896

Differential Revision: https://secure.phabricator.com/D10138
This commit is contained in:
epriestley 2014-08-04 12:03:58 -07:00
parent 725e2fa410
commit e8d272b0da
6 changed files with 73 additions and 68 deletions

View file

@ -4851,6 +4851,7 @@ phutil_register_library_map(array(
'PhabricatorSubscribableInterface',
'HarbormasterBuildableInterface',
'PhabricatorCustomFieldInterface',
'PhabricatorApplicationTransactionInterface',
),
'PhabricatorRepositoryCommitChangeParserWorker' => 'PhabricatorRepositoryCommitParserWorker',
'PhabricatorRepositoryCommitData' => 'PhabricatorRepositoryDAO',

View file

@ -7,6 +7,7 @@ final class PhabricatorAuditEditor
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_EDGE;
// TODO: These will get modernized eventually, but that can happen one
// at a time later on.
@ -66,6 +67,7 @@ final class PhabricatorAuditEditor
switch ($xaction->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
case PhabricatorTransactions::TYPE_EDGE:
case PhabricatorAuditActionConstants::ACTION:
case PhabricatorAuditActionConstants::INLINE:
case PhabricatorAuditActionConstants::ADD_AUDITORS:
@ -82,6 +84,7 @@ final class PhabricatorAuditEditor
switch ($xaction->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
case PhabricatorTransactions::TYPE_EDGE:
case PhabricatorAuditActionConstants::ACTION:
case PhabricatorAuditActionConstants::INLINE:
return;
@ -130,6 +133,20 @@ final class PhabricatorAuditEditor
PhabricatorLiskDAO $object,
array $xactions) {
// Load auditors explicitly; we may not have them if the caller was a
// generic piece of infrastructure.
$commit = id(new DiffusionCommitQuery())
->setViewer($this->requireActor())
->withIDs(array($object->getID()))
->needAuditRequests(true)
->executeOne();
if (!$commit) {
throw new Exception(
pht('Failed to load commit during transaction finalization!'));
}
$object->attachAudits($commit->getAudits());
$status_concerned = PhabricatorAuditStatusConstants::CONCERNED;
$status_closed = PhabricatorAuditStatusConstants::CLOSED;
$status_resigned = PhabricatorAuditStatusConstants::RESIGNED;

View file

@ -5,9 +5,11 @@ final class DiffusionCommitHasTaskEdgeType extends PhabricatorEdgeType {
const EDGECONST = 2;
public function shouldWriteInverseTransactions() {
// TODO: This should happen after T4896, but Diffusion does not support
// transactions yet.
return false;
return true;
}
public function getInverseEdgeConstant() {
return ManiphestTaskHasCommitEdgeType::EDGECONST;
}
public function getTransactionAddString(

View file

@ -5,9 +5,11 @@ final class ManiphestTaskHasCommitEdgeType extends PhabricatorEdgeType {
const EDGECONST = 1;
public function shouldWriteInverseTransactions() {
// TODO: This should happen after T4896, but Diffusion does not support
// transactions yet.
return false;
return true;
}
public function getInverseEdgeConstant() {
return DiffusionCommitHasTaskEdgeType::EDGECONST;
}
public function getTransactionAddString(

View file

@ -8,7 +8,8 @@ final class PhabricatorRepositoryCommit
PhabricatorTokenReceiverInterface,
PhabricatorSubscribableInterface,
HarbormasterBuildableInterface,
PhabricatorCustomFieldInterface {
PhabricatorCustomFieldInterface,
PhabricatorApplicationTransactionInterface {
protected $repositoryID;
protected $phid;
@ -351,4 +352,20 @@ final class PhabricatorRepositoryCommit
return true;
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new PhabricatorAuditEditor();
}
public function getApplicationTransactionObject() {
return $this;
}
public function getApplicationTransactionTemplate() {
return new PhabricatorAuditTransaction();
}
}

View file

@ -57,39 +57,6 @@ final class PhabricatorSearchAttachController
$phids = array_values($phids);
if ($edge_type) {
if ($object instanceof PhabricatorRepositoryCommit) {
// TODO: Remove this entire branch of special cased grossness
// after T4896.
$old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$this->phid,
$edge_type);
$add_phids = $phids;
$rem_phids = array_diff($old_phids, $add_phids);
// Doing this correctly (in a way that writes edge transactions) would
// be a huge mess and we don't get the commit half of the transaction
// anyway until T4896, so just write the edges themselves and skip
// the transactions for now.
$editor = new PhabricatorEdgeEditor();
foreach ($add_phids as $phid) {
$editor->addEdge(
$object->getPHID(),
DiffusionCommitHasTaskEdgeType::EDGECONST,
$phid);
}
foreach ($rem_phids as $phid) {
$editor->removeEdge(
$object->getPHID(),
DiffusionCommitHasTaskEdgeType::EDGECONST,
$phid);
}
$editor->save();
} else {
if (!$object instanceof PhabricatorApplicationTransactionInterface) {
throw new Exception(
pht(
@ -118,7 +85,6 @@ final class PhabricatorSearchAttachController
$txn_editor->applyTransactions(
$object->getApplicationTransactionObject(),
array($txn_template));
}
return id(new AphrontReloadResponse())->setURI($handle->getURI());
} else {