Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / audit / management / PhabricatorAuditManagementWorkflow.php
blobb9d90bddc8c8e30a6e0b135b31405955c183b824
1 <?php
3 abstract class PhabricatorAuditManagementWorkflow
4 extends PhabricatorManagementWorkflow {
7 protected function getCommitConstraintArguments() {
8 return array(
9 array(
10 'name' => 'all',
11 'help' => pht('Update all commits in all repositories.'),
13 array(
14 'name' => 'objects',
15 'wildcard' => true,
16 'help' => pht('Update named commits and repositories.'),
21 protected function loadCommitsWithConstraints(PhutilArgumentParser $args) {
22 $viewer = $this->getViewer();
24 $all = $args->getArg('all');
25 $names = $args->getArg('objects');
27 if (!$names && !$all) {
28 throw new PhutilArgumentUsageException(
29 pht(
30 'Specify "--all" to affect everything, or a list of specific '.
31 'commits or repositories to affect.'));
32 } else if ($names && $all) {
33 throw new PhutilArgumentUsageException(
34 pht(
35 'Specify either a list of objects to affect or "--all", but not '.
36 'both.'));
39 if ($all) {
40 $objects = new LiskMigrationIterator(new PhabricatorRepository());
41 } else {
42 $query = id(new PhabricatorObjectQuery())
43 ->setViewer($viewer)
44 ->withNames($names);
46 $query->execute();
48 $objects = array();
50 $results = $query->getNamedResults();
51 foreach ($names as $name) {
52 if (!isset($results[$name])) {
53 throw new PhutilArgumentUsageException(
54 pht(
55 'Object "%s" is not a valid object.',
56 $name));
59 $object = $results[$name];
60 if (!($object instanceof PhabricatorRepository) &&
61 !($object instanceof PhabricatorRepositoryCommit)) {
62 throw new PhutilArgumentUsageException(
63 pht(
64 'Object "%s" is not a valid repository or commit.',
65 $name));
68 $objects[] = $object;
72 return $objects;
75 protected function loadCommitsForConstraintObject($object) {
76 $viewer = $this->getViewer();
78 if ($object instanceof PhabricatorRepository) {
79 $commits = id(new DiffusionCommitQuery())
80 ->setViewer($viewer)
81 ->withRepository($object)
82 ->execute();
83 } else {
84 $commits = array($object);
87 return $commits;
90 protected function synchronizeCommitAuditState($commit_phid) {
91 $viewer = $this->getViewer();
93 $commit = id(new DiffusionCommitQuery())
94 ->setViewer($viewer)
95 ->withPHIDs(array($commit_phid))
96 ->needAuditRequests(true)
97 ->executeOne();
98 if (!$commit) {
99 return;
102 $old_status = $commit->getAuditStatusObject();
103 $commit->updateAuditStatus($commit->getAudits());
104 $new_status = $commit->getAuditStatusObject();
106 if ($old_status->getKey() == $new_status->getKey()) {
107 echo tsprintf(
108 "%s\n",
109 pht(
110 'No synchronization changes for "%s".',
111 $commit->getDisplayName()));
112 } else {
113 echo tsprintf(
114 "%s\n",
115 pht(
116 'Synchronizing "%s": "%s" -> "%s".',
117 $commit->getDisplayName(),
118 $old_status->getName(),
119 $new_status->getName()));
121 $commit->save();