1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Publish "done" inline comment checkbox state in Diffusion

Summary:
Ref T1460. See D12126. This is essentially the same change, but for Diffusion.

This is a bit copy/pastey. I'm going to make an effort to lift inline handling into the core before pushing this in, so hopefully that will clean things up a bit.

Test Plan: Submitted stuff in Diffusion and got checkmarks to publish.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T1460

Differential Revision: https://secure.phabricator.com/D12128
This commit is contained in:
epriestley 2015-03-22 06:00:49 -07:00
parent 9f3210c883
commit cbb5a297d5
3 changed files with 104 additions and 1 deletions

View file

@ -9,6 +9,7 @@ final class PhabricatorAuditEditor
private $heraldEmailPHIDs = array();
private $affectedFiles;
private $rawPatch;
private $expandedDone;
public function addAuditReason($phid, $reason) {
if (!isset($this->auditReasonMap[$phid])) {
@ -54,6 +55,7 @@ final class PhabricatorAuditEditor
$types[] = PhabricatorTransactions::TYPE_EDGE;
$types[] = PhabricatorAuditTransaction::TYPE_COMMIT;
$types[] = PhabricatorAuditTransaction::TYPE_INLINEDONE;
// TODO: These will get modernized eventually, but that can happen one
// at a time later on.
@ -102,6 +104,7 @@ final class PhabricatorAuditEditor
case PhabricatorAuditActionConstants::INLINE:
case PhabricatorAuditActionConstants::ADD_AUDITORS:
case PhabricatorAuditTransaction::TYPE_COMMIT:
case PhabricatorAuditTransaction::TYPE_INLINEDONE:
return $xaction->getNewValue();
}
@ -120,6 +123,7 @@ final class PhabricatorAuditEditor
case PhabricatorAuditActionConstants::INLINE:
case PhabricatorAuditActionConstants::ADD_AUDITORS:
case PhabricatorAuditTransaction::TYPE_COMMIT:
case PhabricatorAuditTransaction::TYPE_INLINEDONE:
return;
}
@ -143,6 +147,18 @@ final class PhabricatorAuditEditor
$reply->setHasReplies(1)->save();
}
return;
case PhabricatorAuditTransaction::TYPE_INLINEDONE:
$table = new PhabricatorAuditTransactionComment();
$conn_w = $table->establishConnection('w');
foreach ($xaction->getNewValue() as $phid => $state) {
queryfx(
$conn_w,
'UPDATE %T SET fixedState = %s WHERE phid = %s',
$table->getTableName(),
$state,
$phid);
}
return;
case PhabricatorAuditActionConstants::ADD_AUDITORS:
$new = $xaction->getNewValue();
if (!is_array($new)) {
@ -344,6 +360,52 @@ final class PhabricatorAuditEditor
default:
break;
}
if (!$this->expandedDone) {
switch ($xaction->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
case PhabricatorAuditActionConstants::ACTION:
$this->expandedDone = true;
$actor_phid = $this->getActingAsPHID();
$actor_is_author = ($object->getAuthorPHID() == $actor_phid);
if (!$actor_is_author) {
break;
}
$state_map = array(
PhabricatorInlineCommentInterface::STATE_DRAFT =>
PhabricatorInlineCommentInterface::STATE_DONE,
PhabricatorInlineCommentInterface::STATE_UNDRAFT =>
PhabricatorInlineCommentInterface::STATE_UNDONE,
);
$inlines = id(new DiffusionDiffInlineCommentQuery())
->setViewer($this->getActor())
->withCommitPHIDs(array($object->getPHID()))
->withFixedStates(array_keys($state_map))
->execute();
if (!$inlines) {
break;
}
$old_value = mpull($inlines, 'getFixedState', 'getPHID');
$new_value = array();
foreach ($old_value as $key => $state) {
$new_value[$key] = $state_map[$state];
}
$xactions[] = id(new PhabricatorAuditTransaction())
->setTransactionType(PhabricatorAuditTransaction::TYPE_INLINEDONE)
->setIgnoreOnNoEffect(true)
->setOldValue($old_value)
->setNewValue($new_value);
break;
}
}
return $xactions;
}

View file

@ -4,6 +4,7 @@ final class PhabricatorAuditTransaction
extends PhabricatorApplicationTransaction {
const TYPE_COMMIT = 'audit:commit';
const TYPE_INLINEDONE = 'audit:inlinedone';
const MAILTAG_ACTION_CONCERN = 'audit-action-concern';
const MAILTAG_ACTION_ACCEPT = 'audit-action-accept';
@ -182,6 +183,36 @@ final class PhabricatorAuditTransaction
}
return $title;
case self::TYPE_INLINEDONE:
$done = 0;
$undone = 0;
foreach ($new as $phid => $state) {
if ($state == PhabricatorInlineCommentInterface::STATE_DONE) {
$done++;
} else {
$undone++;
}
}
if ($done && $undone) {
return pht(
'%s marked %s inline comment(s) as done and %s inline comment(s) '.
'as not done.',
$author_handle,
new PhutilNumber($done),
new PhutilNumber($undone));
} else if ($done) {
return pht(
'%s marked %s inline comment(s) as done.',
$author_handle,
new PhutilNumber($done));
} else {
return pht(
'%s marked %s inline comment(s) as not done.',
$author_handle,
new PhutilNumber($undone));
}
break;
case PhabricatorAuditActionConstants::INLINE:
return pht(
'%s added inline comments.',
@ -388,6 +419,16 @@ final class PhabricatorAuditTransaction
}
public function shouldGenerateOldValue() {
switch ($this->getTransactionType()) {
case self::TYPE_INLINEDONE:
return false;
}
return parent::shouldGenerateOldValue();
}
// TODO: These two mail methods can likely be abstracted by introducing a
// formal concept of "inline comment" transactions.

View file

@ -70,7 +70,7 @@ final class DiffusionInlineCommentController
$commit = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withPHIDs(array($inline->getCommitPHID()))
->exeucteOne();
->executeOne();
if (!$commit) {
throw new Exception(pht('Failed to load commit.'));
}