1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-12 00:26:13 +01:00
phorge-phorge/src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php
epriestley aca0f642a3 Add a "bin/audit synchronize" command
Summary: Ref T10978. This is just a maintenance convenience script. It can fix up overall commit state after you `bin/audit delete` stuff or nuke a bunch of stuff from the database, as I did on `secure.phabricator.com`.

Test Plan: Ran `bin/audit synchronize`, and `bin/audit update-owners`.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10978

Differential Revision: https://secure.phabricator.com/D17271
2017-01-31 09:19:31 -08:00

58 lines
1.6 KiB
PHP

<?php
final class PhabricatorAuditSynchronizeManagementWorkflow
extends PhabricatorAuditManagementWorkflow {
protected function didConstruct() {
$this
->setName('synchronize')
->setExamples('**synchronize** ...')
->setSynopsis(pht('Update audit status for commits.'))
->setArguments(
array_merge(
$this->getCommitConstraintArguments(),
array()));
}
public function execute(PhutilArgumentParser $args) {
$viewer = $this->getViewer();
$objects = $this->loadCommitsWithConstraints($args);
foreach ($objects as $object) {
$commits = $this->loadCommitsForConstraintObject($object);
foreach ($commits as $commit) {
$commit = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withPHIDs(array($commit->getPHID()))
->needAuditRequests(true)
->executeOne();
if (!$commit) {
continue;
}
$old_status = $commit->getAuditStatus();
$commit->updateAuditStatus($commit->getAudits());
$new_status = $commit->getAuditStatus();
if ($old_status == $new_status) {
echo tsprintf(
"%s\n",
pht(
'No changes for "%s".',
$commit->getDisplayName()));
} else {
echo tsprintf(
"%s\n",
pht(
'Updated "%s": "%s" -> "%s".',
$commit->getDisplayName(),
PhabricatorAuditCommitStatusConstants::getStatusName(
$old_status),
PhabricatorAuditCommitStatusConstants::getStatusName(
$new_status)));
}
}
}
}
}