Path: blob/master/src/applications/audit/management/PhabricatorAuditManagementWorkflow.php
12256 views
<?php12abstract class PhabricatorAuditManagementWorkflow3extends PhabricatorManagementWorkflow {456protected function getCommitConstraintArguments() {7return array(8array(9'name' => 'all',10'help' => pht('Update all commits in all repositories.'),11),12array(13'name' => 'objects',14'wildcard' => true,15'help' => pht('Update named commits and repositories.'),16),17);18}1920protected function loadCommitsWithConstraints(PhutilArgumentParser $args) {21$viewer = $this->getViewer();2223$all = $args->getArg('all');24$names = $args->getArg('objects');2526if (!$names && !$all) {27throw new PhutilArgumentUsageException(28pht(29'Specify "--all" to affect everything, or a list of specific '.30'commits or repositories to affect.'));31} else if ($names && $all) {32throw new PhutilArgumentUsageException(33pht(34'Specify either a list of objects to affect or "--all", but not '.35'both.'));36}3738if ($all) {39$objects = new LiskMigrationIterator(new PhabricatorRepository());40} else {41$query = id(new PhabricatorObjectQuery())42->setViewer($viewer)43->withNames($names);4445$query->execute();4647$objects = array();4849$results = $query->getNamedResults();50foreach ($names as $name) {51if (!isset($results[$name])) {52throw new PhutilArgumentUsageException(53pht(54'Object "%s" is not a valid object.',55$name));56}5758$object = $results[$name];59if (!($object instanceof PhabricatorRepository) &&60!($object instanceof PhabricatorRepositoryCommit)) {61throw new PhutilArgumentUsageException(62pht(63'Object "%s" is not a valid repository or commit.',64$name));65}6667$objects[] = $object;68}69}7071return $objects;72}7374protected function loadCommitsForConstraintObject($object) {75$viewer = $this->getViewer();7677if ($object instanceof PhabricatorRepository) {78$commits = id(new DiffusionCommitQuery())79->setViewer($viewer)80->withRepository($object)81->execute();82} else {83$commits = array($object);84}8586return $commits;87}8889protected function synchronizeCommitAuditState($commit_phid) {90$viewer = $this->getViewer();9192$commit = id(new DiffusionCommitQuery())93->setViewer($viewer)94->withPHIDs(array($commit_phid))95->needAuditRequests(true)96->executeOne();97if (!$commit) {98return;99}100101$old_status = $commit->getAuditStatusObject();102$commit->updateAuditStatus($commit->getAudits());103$new_status = $commit->getAuditStatusObject();104105if ($old_status->getKey() == $new_status->getKey()) {106echo tsprintf(107"%s\n",108pht(109'No synchronization changes for "%s".',110$commit->getDisplayName()));111} else {112echo tsprintf(113"%s\n",114pht(115'Synchronizing "%s": "%s" -> "%s".',116$commit->getDisplayName(),117$old_status->getName(),118$new_status->getName()));119120$commit->save();121}122}123124}125126127