Differential D17271 Diff 41553 src/applications/audit/management/PhabricatorAuditUpdateOwnersManagementWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/management/PhabricatorAuditUpdateOwnersManagementWorkflow.php
<?php | <?php | ||||
final class PhabricatorAuditUpdateOwnersManagementWorkflow | final class PhabricatorAuditUpdateOwnersManagementWorkflow | ||||
extends PhabricatorAuditManagementWorkflow { | extends PhabricatorAuditManagementWorkflow { | ||||
protected function didConstruct() { | protected function didConstruct() { | ||||
$this | $this | ||||
->setName('update-owners') | ->setName('update-owners') | ||||
->setExamples('**update-owners** ...') | ->setExamples('**update-owners** ...') | ||||
->setSynopsis(pht('Update package relationships for commits.')) | ->setSynopsis(pht('Update package relationships for commits.')) | ||||
->setArguments( | ->setArguments( | ||||
array( | array_merge( | ||||
array( | $this->getCommitConstraintArguments(), | ||||
'name' => 'all', | array())); | ||||
'help' => pht('Update all commits in all repositories.'), | |||||
), | |||||
array( | |||||
'name' => 'objects', | |||||
'wildcard' => true, | |||||
'help' => pht('Update named commits and repositories.'), | |||||
), | |||||
)); | |||||
} | } | ||||
public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$objects = $this->loadCommitsWithConstraints($args); | |||||
$all = $args->getArg('all'); | |||||
$names = $args->getArg('objects'); | |||||
if (!$names && !$all) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Specify "--all" to update everything, or a list of specific '. | |||||
'commits or repositories to update.')); | |||||
} else if ($names && $all) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Specify either a list of objects to update or "--all", but not '. | |||||
'both.')); | |||||
} | |||||
if ($all) { | |||||
$objects = new LiskMigrationIterator(new PhabricatorRepository()); | |||||
} else { | |||||
$query = id(new PhabricatorObjectQuery()) | |||||
->setViewer($viewer) | |||||
->withNames($names); | |||||
$query->execute(); | |||||
$objects = array(); | |||||
$results = $query->getNamedResults(); | |||||
foreach ($names as $name) { | |||||
if (!isset($results[$name])) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Object "%s" is not a valid object.', | |||||
$name)); | |||||
} | |||||
$object = $results[$name]; | |||||
if (!($object instanceof PhabricatorRepository) && | |||||
!($object instanceof PhabricatorRepositoryCommit)) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Object "%s" is not a valid repository or commit.', | |||||
$name)); | |||||
} | |||||
$objects[] = $object; | |||||
} | |||||
} | |||||
foreach ($objects as $object) { | foreach ($objects as $object) { | ||||
if ($object instanceof PhabricatorRepository) { | $commits = $this->loadCommitsForConstraintObject($object); | ||||
$commits = id(new DiffusionCommitQuery()) | |||||
->setViewer($viewer) | |||||
->withRepository($object) | |||||
->execute(); | |||||
} else { | |||||
$commits = array($object); | |||||
} | |||||
foreach ($commits as $commit) { | foreach ($commits as $commit) { | ||||
$repository = $commit->getRepository(); | $repository = $commit->getRepository(); | ||||
$affected_paths = PhabricatorOwnerPathQuery::loadAffectedPaths( | $affected_paths = PhabricatorOwnerPathQuery::loadAffectedPaths( | ||||
$repository, | $repository, | ||||
$commit, | $commit, | ||||
$viewer); | $viewer); | ||||
Show All 25 Lines |