Differential D20124 Diff 48042 src/applications/owners/xaction/PhabricatorOwnersPackageAuditingTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/owners/xaction/PhabricatorOwnersPackageAuditingTransaction.php
<?php | <?php | ||||
final class PhabricatorOwnersPackageAuditingTransaction | final class PhabricatorOwnersPackageAuditingTransaction | ||||
extends PhabricatorOwnersPackageTransactionType { | extends PhabricatorOwnersPackageTransactionType { | ||||
const TRANSACTIONTYPE = 'owners.auditing'; | const TRANSACTIONTYPE = 'owners.auditing'; | ||||
public function generateOldValue($object) { | public function generateOldValue($object) { | ||||
return (int)$object->getAuditingEnabled(); | return $object->getAuditingState(); | ||||
} | } | ||||
public function generateNewValue($object, $value) { | public function generateNewValue($object, $value) { | ||||
switch ($value) { | return PhabricatorOwnersAuditRule::getStorageValueFromAPIValue($value); | ||||
case PhabricatorOwnersPackage::AUDITING_AUDIT: | |||||
return 1; | |||||
case '1': | |||||
// TODO: Remove, deprecated. | |||||
return 1; | |||||
default: | |||||
return 0; | |||||
} | |||||
} | } | ||||
public function applyInternalEffects($object, $value) { | public function applyInternalEffects($object, $value) { | ||||
$object->setAuditingEnabled($value); | $object->setAuditingState($value); | ||||
} | } | ||||
public function getTitle() { | public function getTitle() { | ||||
if ($this->getNewValue()) { | $old_value = $this->getOldValue(); | ||||
return pht( | $new_value = $this->getNewValue(); | ||||
'%s enabled auditing for this package.', | |||||
$this->renderAuthor()); | $old_rule = PhabricatorOwnersAuditRule::newFromState($old_value); | ||||
} else { | $new_rule = PhabricatorOwnersAuditRule::newFromState($new_value); | ||||
return pht( | return pht( | ||||
'%s disabled auditing for this package.', | '%s changed the audit rule for this package from %s to %s.', | ||||
$this->renderAuthor()); | $this->renderAuthor(), | ||||
} | $this->renderValue($old_rule->getDisplayName()), | ||||
$this->renderValue($new_rule->getDisplayName())); | |||||
} | } | ||||
public function validateTransactions($object, array $xactions) { | public function validateTransactions($object, array $xactions) { | ||||
$errors = array(); | $errors = array(); | ||||
// See PHI1047. This transaction type accepted some weird stuff. Continue | // See PHI1047. This transaction type accepted some weird stuff. Continue | ||||
// supporting it for now, but move toward sensible consistency. | // supporting it for now, but move toward sensible consistency. | ||||
$modern_options = array( | $modern_options = PhabricatorOwnersAuditRule::getModernValueMap(); | ||||
PhabricatorOwnersPackage::AUDITING_NONE => | $deprecated_options = PhabricatorOwnersAuditRule::getDeprecatedValueMap(); | ||||
sprintf('"%s"', PhabricatorOwnersPackage::AUDITING_NONE), | |||||
PhabricatorOwnersPackage::AUDITING_AUDIT => | |||||
sprintf('"%s"', PhabricatorOwnersPackage::AUDITING_AUDIT), | |||||
); | |||||
$deprecated_options = array( | |||||
'0' => '"0"', | |||||
'1' => '"1"', | |||||
'' => pht('"" (empty string)'), | |||||
); | |||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
$new_value = $xaction->getNewValue(); | $new_value = $xaction->getNewValue(); | ||||
if (isset($modern_options[$new_value])) { | if (isset($modern_options[$new_value])) { | ||||
continue; | continue; | ||||
} | } | ||||
Show All 18 Lines |