diff --git a/src/applications/audit/constants/PhabricatorAuditCommitStatusConstants.php b/src/applications/audit/constants/PhabricatorAuditCommitStatusConstants.php index 877fd0b4ba..e559862c83 100644 --- a/src/applications/audit/constants/PhabricatorAuditCommitStatusConstants.php +++ b/src/applications/audit/constants/PhabricatorAuditCommitStatusConstants.php @@ -2,6 +2,9 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject { + private $key; + private $spec = array(); + const NONE = 0; const NEEDS_AUDIT = 1; const CONCERN_RAISED = 2; @@ -16,6 +19,47 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject { const MODERN_AUDITED = 'audited'; const MODERN_NEEDS_VERIFICATION = 'needs-verification'; + public static function newForLegacyStatus($status) { + $map = self::getMap(); + + foreach ($map as $key => $spec) { + if (idx($spec, 'legacy') == $status) { + return self::newForStatus($key); + } + } + + return self::newForStatus($status); + } + + public static function newForStatus($status) { + $result = new self(); + + $result->key = $status; + + $map = self::getMap(); + if (isset($map[$status])) { + $result->spec = $map[$status]; + } + + return $result; + } + + public function getKey() { + return $this->key; + } + + public function getIcon() { + return idx($this->spec, 'icon'); + } + + public function getColor() { + return idx($this->spec, 'color'); + } + + public function getName() { + return idx($this->spec, 'name', pht('Unknown ("%s")', $this->key)); + } + public static function getStatusNameMap() { $map = self::getMap(); return ipull($map, 'name', 'legacy'); diff --git a/src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php b/src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php index db6ce096c4..96d06e65c2 100644 --- a/src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php +++ b/src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php @@ -30,11 +30,11 @@ final class PhabricatorAuditSynchronizeManagementWorkflow continue; } - $old_status = $commit->getAuditStatus(); + $old_status = $commit->getAuditStatusObject(); $commit->updateAuditStatus($commit->getAudits()); - $new_status = $commit->getAuditStatus(); + $new_status = $commit->getAuditStatusObject(); - if ($old_status == $new_status) { + if ($old_status->getKey() == $new_status->getKey()) { echo tsprintf( "%s\n", pht( @@ -46,10 +46,8 @@ final class PhabricatorAuditSynchronizeManagementWorkflow pht( 'Updating "%s": "%s" -> "%s".', $commit->getDisplayName(), - PhabricatorAuditCommitStatusConstants::getStatusName( - $old_status), - PhabricatorAuditCommitStatusConstants::getStatusName( - $new_status))); + $old_status->getName(), + $new_status->getName())); $commit->save(); } diff --git a/src/applications/audit/view/PhabricatorAuditListView.php b/src/applications/audit/view/PhabricatorAuditListView.php index cb9fecac3a..fb56e7cd55 100644 --- a/src/applications/audit/view/PhabricatorAuditListView.php +++ b/src/applications/audit/view/PhabricatorAuditListView.php @@ -120,14 +120,11 @@ final class PhabricatorAuditListView extends AphrontView { $commit_desc = $this->getCommitDescription($commit_phid); $committed = phabricator_datetime($commit->getEpoch(), $viewer); - $status = $commit->getAuditStatus(); + $status = $commit->getAuditStatusObject(); - $status_text = - PhabricatorAuditCommitStatusConstants::getStatusName($status); - $status_color = - PhabricatorAuditCommitStatusConstants::getStatusColor($status); - $status_icon = - PhabricatorAuditCommitStatusConstants::getStatusIcon($status); + $status_text = $status->getName(); + $status_color = $status->getColor(); + $status_icon = $status->getIcon(); $author_phid = $commit->getAuthorPHID(); if ($author_phid) { diff --git a/src/applications/diffusion/view/DiffusionHistoryTableView.php b/src/applications/diffusion/view/DiffusionHistoryTableView.php index 3885bbf47c..cfd7019679 100644 --- a/src/applications/diffusion/view/DiffusionHistoryTableView.php +++ b/src/applications/diffusion/view/DiffusionHistoryTableView.php @@ -114,10 +114,10 @@ final class DiffusionHistoryTableView extends DiffusionHistoryView { 'type' => $history->getFileType(), )); - $status = $commit->getAuditStatus(); - $icon = PhabricatorAuditCommitStatusConstants::getStatusIcon($status); - $color = PhabricatorAuditCommitStatusConstants::getStatusColor($status); - $name = PhabricatorAuditCommitStatusConstants::getStatusName($status); + $status = $commit->getAuditStatusObject(); + $icon = $status->getIcon(); + $color = $status->getColor(); + $name = $status->getName(); $audit_view = id(new PHUIIconView()) ->setIcon($icon, $color) diff --git a/src/applications/repository/phid/PhabricatorRepositoryCommitPHIDType.php b/src/applications/repository/phid/PhabricatorRepositoryCommitPHIDType.php index b5abd40032..c37bdc04f9 100644 --- a/src/applications/repository/phid/PhabricatorRepositoryCommitPHIDType.php +++ b/src/applications/repository/phid/PhabricatorRepositoryCommitPHIDType.php @@ -82,10 +82,10 @@ final class PhabricatorRepositoryCommitPHIDType extends PhabricatorPHIDType { $handle->setURI($commit->getURI()); $handle->setTimestamp($commit->getEpoch()); - $status = $commit->getAuditStatus(); - $icon = PhabricatorAuditCommitStatusConstants::getStatusIcon($status); - $color = PhabricatorAuditCommitStatusConstants::getStatusColor($status); - $name = PhabricatorAuditCommitStatusConstants::getStatusName($status); + $status = $commit->getAuditStatusObject(); + $icon = $status->getIcon(); + $color = $status->getColor(); + $name = $status->getName(); $handle ->setStateIcon($icon) diff --git a/src/applications/repository/storage/PhabricatorRepositoryCommit.php b/src/applications/repository/storage/PhabricatorRepositoryCommit.php index f36869686f..447db08e6c 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryCommit.php +++ b/src/applications/repository/storage/PhabricatorRepositoryCommit.php @@ -530,6 +530,11 @@ final class PhabricatorRepositoryCommit return $data->getCommitDetail('authorPHID'); } + public function getAuditStatusObject() { + $status = $this->getAuditStatus(); + return PhabricatorAuditCommitStatusConstants::newForLegacyStatus($status); + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() {