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 $affectedFiles; | private $affectedFiles; | ||||
private $rawPatch; | private $rawPatch; | ||||
private $auditorPHIDs = array(); | private $auditorPHIDs = array(); | ||||
private $didExpandInlineState = false; | private $didExpandInlineState = false; | ||||
private $oldAuditStatus = null; | private $oldAuditStatus = null; | ||||
public function addAuditReason($phid, $reason) { | |||||
if (!isset($this->auditReasonMap[$phid])) { | |||||
$this->auditReasonMap[$phid] = array(); | |||||
} | |||||
$this->auditReasonMap[$phid][] = $reason; | |||||
return $this; | |||||
} | |||||
private function getAuditReasons($phid) { | |||||
if (isset($this->auditReasonMap[$phid])) { | |||||
return $this->auditReasonMap[$phid]; | |||||
} | |||||
if ($this->getIsHeraldEditor()) { | |||||
$name = 'herald'; | |||||
} else { | |||||
$name = $this->getActor()->getUsername(); | |||||
} | |||||
return array(pht('Added by %s.', $name)); | |||||
} | |||||
public function setRawPatch($patch) { | public function setRawPatch($patch) { | ||||
$this->rawPatch = $patch; | $this->rawPatch = $patch; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getRawPatch() { | public function getRawPatch() { | ||||
return $this->rawPatch; | return $this->rawPatch; | ||||
} | } | ||||
Show All 13 Lines | public function getTransactionTypes() { | ||||
$types[] = PhabricatorTransactions::TYPE_EDGE; | $types[] = PhabricatorTransactions::TYPE_EDGE; | ||||
$types[] = PhabricatorTransactions::TYPE_INLINESTATE; | $types[] = PhabricatorTransactions::TYPE_INLINESTATE; | ||||
$types[] = PhabricatorAuditTransaction::TYPE_COMMIT; | $types[] = PhabricatorAuditTransaction::TYPE_COMMIT; | ||||
// 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::INLINE; | $types[] = PhabricatorAuditActionConstants::INLINE; | ||||
$types[] = PhabricatorAuditActionConstants::ADD_AUDITORS; | |||||
return $types; | return $types; | ||||
} | } | ||||
protected function expandTransactions( | protected function expandTransactions( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
Show All 28 Lines | final class PhabricatorAuditEditor | ||||
protected function getCustomTransactionOldValue( | protected function getCustomTransactionOldValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
return null; | return null; | ||||
case PhabricatorAuditActionConstants::ADD_AUDITORS: | |||||
// TODO: For now, just record the added PHIDs. Eventually, turn these | |||||
// into real edge transactions, probably? | |||||
return array(); | |||||
} | } | ||||
return parent::getCustomTransactionOldValue($object, $xaction); | return parent::getCustomTransactionOldValue($object, $xaction); | ||||
} | } | ||||
protected function getCustomTransactionNewValue( | protected function getCustomTransactionNewValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
case PhabricatorAuditActionConstants::ADD_AUDITORS: | |||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
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 PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
case PhabricatorAuditActionConstants::ADD_AUDITORS: | |||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
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 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 PhabricatorAuditActionConstants::ADD_AUDITORS: | |||||
$new = $xaction->getNewValue(); | |||||
if (!is_array($new)) { | |||||
$new = array(); | |||||
} | |||||
$old = $xaction->getOldValue(); | |||||
if (!is_array($old)) { | |||||
$old = array(); | |||||
} | |||||
$add = array_diff_key($new, $old); | |||||
$actor = $this->requireActor(); | |||||
$requests = $object->getAudits(); | |||||
$requests = mpull($requests, null, 'getAuditorPHID'); | |||||
foreach ($add as $phid) { | |||||
if (isset($requests[$phid])) { | |||||
$request = $requests[$phid]; | |||||
// Only update an existing request if the current status is not | |||||
// an interesting status. | |||||
if ($request->isInteresting()) { | |||||
continue; | |||||
} | |||||
} else { | |||||
$request = id(new PhabricatorRepositoryAuditRequest()) | |||||
->setCommitPHID($object->getPHID()) | |||||
->setAuditorPHID($phid); | |||||
} | |||||
if ($this->getIsHeraldEditor()) { | |||||
$audit_requested = $xaction->getMetadataValue('auditStatus'); | |||||
$audit_reason_map = $xaction->getMetadataValue('auditReasonMap'); | |||||
$audit_reason = $audit_reason_map[$phid]; | |||||
} else { | |||||
$audit_requested = PhabricatorAuditStatusConstants::AUDIT_REQUESTED; | |||||
$audit_reason = $this->getAuditReasons($phid); | |||||
} | |||||
$request | |||||
->setAuditStatus($audit_requested) | |||||
->setAuditReasons($audit_reason) | |||||
->save(); | |||||
$requests[$phid] = $request; | |||||
} | |||||
$object->attachAudits($requests); | |||||
return; | |||||
} | } | ||||
return parent::applyCustomExternalTransaction($object, $xaction); | return parent::applyCustomExternalTransaction($object, $xaction); | ||||
} | } | ||||
protected function applyBuiltinExternalTransaction( | protected function applyBuiltinExternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | $result = DifferentialCommitMessageParser::newStandardParser($actor) | ||||
->parseFields($message); | ->parseFields($message); | ||||
$field_key = DifferentialAuditorsCommitMessageField::FIELDKEY; | $field_key = DifferentialAuditorsCommitMessageField::FIELDKEY; | ||||
$phids = idx($result, $field_key, null); | $phids = idx($result, $field_key, null); | ||||
if (!$phids) { | if (!$phids) { | ||||
return array(); | return array(); | ||||
} | } | ||||
return id(new PhabricatorAuditTransaction()) | return $commit->getApplicationTransactionTemplate() | ||||
->setTransactionType(DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE) | ->setTransactionType(DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE) | ||||
->setNewValue( | ->setNewValue( | ||||
array( | array( | ||||
'+' => array_fuse($phids), | '+' => array_fuse($phids), | ||||
)); | )); | ||||
} | } | ||||
protected function sortTransactions(array $xactions) { | protected function sortTransactions(array $xactions) { | ||||
▲ Show 20 Lines • Show All 472 Lines • Show Last 20 Lines |