Differential D20127 Diff 48137 src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php
<?php | <?php | ||||
final class PhabricatorAuditSynchronizeManagementWorkflow | final class PhabricatorAuditSynchronizeManagementWorkflow | ||||
extends PhabricatorAuditManagementWorkflow { | extends PhabricatorAuditManagementWorkflow { | ||||
protected function didConstruct() { | protected function didConstruct() { | ||||
$this | $this | ||||
->setName('synchronize') | ->setName('synchronize') | ||||
->setExamples('**synchronize** ...') | ->setExamples( | ||||
->setSynopsis(pht('Update audit status for commits.')) | "**synchronize** __repository__ ...\n". | ||||
"**synchronize** __commit__ ...\n". | |||||
"**synchronize** --all") | |||||
->setSynopsis( | |||||
pht( | |||||
'Update commits to make their summary audit state reflect the '. | |||||
'state of their actual audit requests. This can fix inconsistencies '. | |||||
'in database state if audit requests have been mangled '. | |||||
'accidentally (or on purpose).')) | |||||
->setArguments( | ->setArguments( | ||||
array_merge( | array_merge( | ||||
$this->getCommitConstraintArguments(), | $this->getCommitConstraintArguments(), | ||||
array())); | array())); | ||||
} | } | ||||
public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$objects = $this->loadCommitsWithConstraints($args); | $objects = $this->loadCommitsWithConstraints($args); | ||||
foreach ($objects as $object) { | foreach ($objects as $object) { | ||||
$commits = $this->loadCommitsForConstraintObject($object); | $commits = $this->loadCommitsForConstraintObject($object); | ||||
foreach ($commits as $commit) { | foreach ($commits as $commit) { | ||||
$commit = id(new DiffusionCommitQuery()) | $this->synchronizeCommitAuditState($commit->getPHID()); | ||||
->setViewer($viewer) | |||||
->withPHIDs(array($commit->getPHID())) | |||||
->needAuditRequests(true) | |||||
->executeOne(); | |||||
if (!$commit) { | |||||
continue; | |||||
} | |||||
$old_status = $commit->getAuditStatusObject(); | |||||
$commit->updateAuditStatus($commit->getAudits()); | |||||
$new_status = $commit->getAuditStatusObject(); | |||||
if ($old_status->getKey() == $new_status->getKey()) { | |||||
echo tsprintf( | |||||
"%s\n", | |||||
pht( | |||||
'No changes for "%s".', | |||||
$commit->getDisplayName())); | |||||
} else { | |||||
echo tsprintf( | |||||
"%s\n", | |||||
pht( | |||||
'Updating "%s": "%s" -> "%s".', | |||||
$commit->getDisplayName(), | |||||
$old_status->getName(), | |||||
$new_status->getName())); | |||||
$commit->save(); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |