Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/editor/PhabricatorAuditEditor.php
<?php | <?php | ||||
final class PhabricatorAuditEditor | final class PhabricatorAuditEditor | ||||
extends PhabricatorApplicationTransactionEditor { | extends PhabricatorApplicationTransactionEditor { | ||||
const MAX_FILES_SHOWN_IN_EMAIL = 1000; | const MAX_FILES_SHOWN_IN_EMAIL = 1000; | ||||
private $auditReasonMap = array(); | private $auditReasonMap = array(); | ||||
private $heraldEmailPHIDs = array(); | private $heraldEmailPHIDs = array(); | ||||
private $affectedFiles; | private $affectedFiles; | ||||
private $rawPatch; | private $rawPatch; | ||||
private $expandedDone; | |||||
private $didExpandInlineState; | |||||
public function addAuditReason($phid, $reason) { | public function addAuditReason($phid, $reason) { | ||||
if (!isset($this->auditReasonMap[$phid])) { | if (!isset($this->auditReasonMap[$phid])) { | ||||
$this->auditReasonMap[$phid] = array(); | $this->auditReasonMap[$phid] = array(); | ||||
} | } | ||||
$this->auditReasonMap[$phid][] = $reason; | $this->auditReasonMap[$phid][] = $reason; | ||||
return $this; | return $this; | ||||
} | } | ||||
Show All 27 Lines | public function getEditorObjectsDescription() { | ||||
return pht('Audits'); | return pht('Audits'); | ||||
} | } | ||||
public function getTransactionTypes() { | public function getTransactionTypes() { | ||||
$types = parent::getTransactionTypes(); | $types = parent::getTransactionTypes(); | ||||
$types[] = PhabricatorTransactions::TYPE_COMMENT; | $types[] = PhabricatorTransactions::TYPE_COMMENT; | ||||
$types[] = PhabricatorTransactions::TYPE_EDGE; | $types[] = PhabricatorTransactions::TYPE_EDGE; | ||||
$types[] = PhabricatorTransactions::TYPE_INLINESTATE; | |||||
$types[] = PhabricatorAuditTransaction::TYPE_COMMIT; | $types[] = PhabricatorAuditTransaction::TYPE_COMMIT; | ||||
$types[] = PhabricatorAuditTransaction::TYPE_INLINEDONE; | |||||
// TODO: These will get modernized eventually, but that can happen one | // TODO: These will get modernized eventually, but that can happen one | ||||
// at a time later on. | // at a time later on. | ||||
$types[] = PhabricatorAuditActionConstants::ACTION; | $types[] = PhabricatorAuditActionConstants::ACTION; | ||||
$types[] = PhabricatorAuditActionConstants::INLINE; | $types[] = PhabricatorAuditActionConstants::INLINE; | ||||
$types[] = PhabricatorAuditActionConstants::ADD_AUDITORS; | $types[] = PhabricatorAuditActionConstants::ADD_AUDITORS; | ||||
return $types; | return $types; | ||||
Show All 32 Lines | protected function getCustomTransactionNewValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorAuditActionConstants::ACTION: | case PhabricatorAuditActionConstants::ACTION: | ||||
case PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
case PhabricatorAuditActionConstants::ADD_AUDITORS: | case PhabricatorAuditActionConstants::ADD_AUDITORS: | ||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
case PhabricatorAuditTransaction::TYPE_INLINEDONE: | |||||
return $xaction->getNewValue(); | return $xaction->getNewValue(); | ||||
} | } | ||||
return parent::getCustomTransactionNewValue($object, $xaction); | return parent::getCustomTransactionNewValue($object, $xaction); | ||||
} | } | ||||
protected function applyCustomInternalTransaction( | protected function applyCustomInternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_COMMENT: | case PhabricatorTransactions::TYPE_COMMENT: | ||||
case PhabricatorTransactions::TYPE_SUBSCRIBERS: | case PhabricatorTransactions::TYPE_SUBSCRIBERS: | ||||
case PhabricatorTransactions::TYPE_EDGE: | case PhabricatorTransactions::TYPE_EDGE: | ||||
case PhabricatorAuditActionConstants::ACTION: | case PhabricatorAuditActionConstants::ACTION: | ||||
case PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
case PhabricatorAuditActionConstants::ADD_AUDITORS: | case PhabricatorAuditActionConstants::ADD_AUDITORS: | ||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
case PhabricatorAuditTransaction::TYPE_INLINEDONE: | |||||
return; | return; | ||||
} | } | ||||
return parent::applyCustomInternalTransaction($object, $xaction); | return parent::applyCustomInternalTransaction($object, $xaction); | ||||
} | } | ||||
protected function applyCustomExternalTransaction( | protected function applyCustomExternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_COMMENT: | case PhabricatorTransactions::TYPE_COMMENT: | ||||
case PhabricatorTransactions::TYPE_SUBSCRIBERS: | case PhabricatorTransactions::TYPE_SUBSCRIBERS: | ||||
case PhabricatorTransactions::TYPE_EDGE: | case PhabricatorTransactions::TYPE_EDGE: | ||||
case PhabricatorAuditActionConstants::ACTION: | case PhabricatorAuditActionConstants::ACTION: | ||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
return; | return; | ||||
case PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
$reply = $xaction->getComment()->getReplyToComment(); | $reply = $xaction->getComment()->getReplyToComment(); | ||||
if ($reply && !$reply->getHasReplies()) { | if ($reply && !$reply->getHasReplies()) { | ||||
$reply->setHasReplies(1)->save(); | $reply->setHasReplies(1)->save(); | ||||
} | } | ||||
return; | 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: | case PhabricatorAuditActionConstants::ADD_AUDITORS: | ||||
$new = $xaction->getNewValue(); | $new = $xaction->getNewValue(); | ||||
if (!is_array($new)) { | if (!is_array($new)) { | ||||
$new = array(); | $new = array(); | ||||
} | } | ||||
$old = $xaction->getOldValue(); | $old = $xaction->getOldValue(); | ||||
if (!is_array($old)) { | if (!is_array($old)) { | ||||
Show All 29 Lines | switch ($xaction->getTransactionType()) { | ||||
$object->attachAudits($requests); | $object->attachAudits($requests); | ||||
return; | return; | ||||
} | } | ||||
return parent::applyCustomExternalTransaction($object, $xaction); | return parent::applyCustomExternalTransaction($object, $xaction); | ||||
} | } | ||||
protected function applyBuiltinExternalTransaction( | |||||
PhabricatorLiskDAO $object, | |||||
PhabricatorApplicationTransaction $xaction) { | |||||
switch ($xaction->getTransactionType()) { | |||||
case PhabricatorTransactions::TYPE_INLINESTATE: | |||||
$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; | |||||
} | |||||
return parent::applyBuiltinExternalTransaction($object, $xaction); | |||||
} | |||||
protected function applyFinalEffects( | protected function applyFinalEffects( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
// Load auditors explicitly; we may not have them if the caller was a | // Load auditors explicitly; we may not have them if the caller was a | ||||
// generic piece of infrastructure. | // generic piece of infrastructure. | ||||
$commit = id(new DiffusionCommitQuery()) | $commit = id(new DiffusionCommitQuery()) | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | switch ($xaction->getTransactionType()) { | ||||
$xactions[] = $request; | $xactions[] = $request; | ||||
$this->setUnmentionablePHIDMap($request->getNewValue()); | $this->setUnmentionablePHIDMap($request->getNewValue()); | ||||
} | } | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
if (!$this->expandedDone) { | if (!$this->didExpandInlineState) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_COMMENT: | case PhabricatorTransactions::TYPE_COMMENT: | ||||
case PhabricatorAuditActionConstants::ACTION: | case PhabricatorAuditActionConstants::ACTION: | ||||
$this->expandedDone = true; | $this->didExpandInlineState = true; | ||||
$actor_phid = $this->getActingAsPHID(); | $actor_phid = $this->getActingAsPHID(); | ||||
$actor_is_author = ($object->getAuthorPHID() == $actor_phid); | $actor_is_author = ($object->getAuthorPHID() == $actor_phid); | ||||
if (!$actor_is_author) { | if (!$actor_is_author) { | ||||
break; | break; | ||||
} | } | ||||
$state_map = array( | $state_map = PhabricatorTransactions::getInlineStateMap(); | ||||
PhabricatorInlineCommentInterface::STATE_DRAFT => | |||||
PhabricatorInlineCommentInterface::STATE_DONE, | |||||
PhabricatorInlineCommentInterface::STATE_UNDRAFT => | |||||
PhabricatorInlineCommentInterface::STATE_UNDONE, | |||||
); | |||||
$inlines = id(new DiffusionDiffInlineCommentQuery()) | $inlines = id(new DiffusionDiffInlineCommentQuery()) | ||||
->setViewer($this->getActor()) | ->setViewer($this->getActor()) | ||||
->withCommitPHIDs(array($object->getPHID())) | ->withCommitPHIDs(array($object->getPHID())) | ||||
->withFixedStates(array_keys($state_map)) | ->withFixedStates(array_keys($state_map)) | ||||
->execute(); | ->execute(); | ||||
if (!$inlines) { | if (!$inlines) { | ||||
break; | break; | ||||
} | } | ||||
$old_value = mpull($inlines, 'getFixedState', 'getPHID'); | $old_value = mpull($inlines, 'getFixedState', 'getPHID'); | ||||
$new_value = array(); | $new_value = array(); | ||||
foreach ($old_value as $key => $state) { | foreach ($old_value as $key => $state) { | ||||
$new_value[$key] = $state_map[$state]; | $new_value[$key] = $state_map[$state]; | ||||
} | } | ||||
$xactions[] = id(new PhabricatorAuditTransaction()) | $xactions[] = id(new PhabricatorAuditTransaction()) | ||||
->setTransactionType(PhabricatorAuditTransaction::TYPE_INLINEDONE) | ->setTransactionType(PhabricatorTransactions::TYPE_INLINESTATE) | ||||
->setIgnoreOnNoEffect(true) | ->setIgnoreOnNoEffect(true) | ||||
->setOldValue($old_value) | ->setOldValue($old_value) | ||||
->setNewValue($new_value); | ->setNewValue($new_value); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return $xactions; | return $xactions; | ||||
▲ Show 20 Lines • Show All 588 Lines • Show Last 20 Lines |