@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+192 -68
+2
src/__phutil_library_map__.php
··· 1887 1887 'PhabricatorAuditManagementWorkflow' => 'applications/audit/management/PhabricatorAuditManagementWorkflow.php', 1888 1888 'PhabricatorAuditReplyHandler' => 'applications/audit/mail/PhabricatorAuditReplyHandler.php', 1889 1889 'PhabricatorAuditStatusConstants' => 'applications/audit/constants/PhabricatorAuditStatusConstants.php', 1890 + 'PhabricatorAuditSynchronizeManagementWorkflow' => 'applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php', 1890 1891 'PhabricatorAuditTransaction' => 'applications/audit/storage/PhabricatorAuditTransaction.php', 1891 1892 'PhabricatorAuditTransactionComment' => 'applications/audit/storage/PhabricatorAuditTransactionComment.php', 1892 1893 'PhabricatorAuditTransactionQuery' => 'applications/audit/query/PhabricatorAuditTransactionQuery.php', ··· 6783 6784 'PhabricatorAuditManagementWorkflow' => 'PhabricatorManagementWorkflow', 6784 6785 'PhabricatorAuditReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 6785 6786 'PhabricatorAuditStatusConstants' => 'Phobject', 6787 + 'PhabricatorAuditSynchronizeManagementWorkflow' => 'PhabricatorAuditManagementWorkflow', 6786 6788 'PhabricatorAuditTransaction' => 'PhabricatorModularTransaction', 6787 6789 'PhabricatorAuditTransactionComment' => 'PhabricatorApplicationTransactionComment', 6788 6790 'PhabricatorAuditTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+87 -1
src/applications/audit/management/PhabricatorAuditManagementWorkflow.php
··· 1 1 <?php 2 2 3 3 abstract class PhabricatorAuditManagementWorkflow 4 - extends PhabricatorManagementWorkflow {} 4 + extends PhabricatorManagementWorkflow { 5 + 6 + 7 + protected function getCommitConstraintArguments() { 8 + return array( 9 + array( 10 + 'name' => 'all', 11 + 'help' => pht('Update all commits in all repositories.'), 12 + ), 13 + array( 14 + 'name' => 'objects', 15 + 'wildcard' => true, 16 + 'help' => pht('Update named commits and repositories.'), 17 + ), 18 + ); 19 + } 20 + 21 + protected function loadCommitsWithConstraints(PhutilArgumentParser $args) { 22 + $viewer = $this->getViewer(); 23 + 24 + $all = $args->getArg('all'); 25 + $names = $args->getArg('objects'); 26 + 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.')); 37 + } 38 + 39 + if ($all) { 40 + $objects = new LiskMigrationIterator(new PhabricatorRepository()); 41 + } else { 42 + $query = id(new PhabricatorObjectQuery()) 43 + ->setViewer($viewer) 44 + ->withNames($names); 45 + 46 + $query->execute(); 47 + 48 + $objects = array(); 49 + 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)); 57 + } 58 + 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)); 66 + } 67 + 68 + $objects[] = $object; 69 + } 70 + } 71 + 72 + return $objects; 73 + } 74 + 75 + protected function loadCommitsForConstraintObject($object) { 76 + $viewer = $this->getViewer(); 77 + 78 + if ($object instanceof PhabricatorRepository) { 79 + $commits = id(new DiffusionCommitQuery()) 80 + ->setViewer($viewer) 81 + ->withRepository($object) 82 + ->execute(); 83 + } else { 84 + $commits = array($object); 85 + } 86 + 87 + return $commits; 88 + } 89 + 90 + }
+58
src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php
··· 1 + <?php 2 + 3 + final class PhabricatorAuditSynchronizeManagementWorkflow 4 + extends PhabricatorAuditManagementWorkflow { 5 + 6 + protected function didConstruct() { 7 + $this 8 + ->setName('synchronize') 9 + ->setExamples('**synchronize** ...') 10 + ->setSynopsis(pht('Update audit status for commits.')) 11 + ->setArguments( 12 + array_merge( 13 + $this->getCommitConstraintArguments(), 14 + array())); 15 + } 16 + 17 + public function execute(PhutilArgumentParser $args) { 18 + $viewer = $this->getViewer(); 19 + $objects = $this->loadCommitsWithConstraints($args); 20 + 21 + foreach ($objects as $object) { 22 + $commits = $this->loadCommitsForConstraintObject($object); 23 + foreach ($commits as $commit) { 24 + $commit = id(new DiffusionCommitQuery()) 25 + ->setViewer($viewer) 26 + ->withPHIDs(array($commit->getPHID())) 27 + ->needAuditRequests(true) 28 + ->executeOne(); 29 + if (!$commit) { 30 + continue; 31 + } 32 + 33 + $old_status = $commit->getAuditStatus(); 34 + $commit->updateAuditStatus($commit->getAudits()); 35 + $new_status = $commit->getAuditStatus(); 36 + 37 + if ($old_status == $new_status) { 38 + echo tsprintf( 39 + "%s\n", 40 + pht( 41 + 'No changes for "%s".', 42 + $commit->getDisplayName())); 43 + } else { 44 + echo tsprintf( 45 + "%s\n", 46 + pht( 47 + 'Updated "%s": "%s" -> "%s".', 48 + $commit->getDisplayName(), 49 + PhabricatorAuditCommitStatusConstants::getStatusName( 50 + $old_status), 51 + PhabricatorAuditCommitStatusConstants::getStatusName( 52 + $new_status))); 53 + } 54 + } 55 + } 56 + } 57 + 58 + }
+5 -67
src/applications/audit/management/PhabricatorAuditUpdateOwnersManagementWorkflow.php
··· 9 9 ->setExamples('**update-owners** ...') 10 10 ->setSynopsis(pht('Update package relationships for commits.')) 11 11 ->setArguments( 12 - array( 13 - array( 14 - 'name' => 'all', 15 - 'help' => pht('Update all commits in all repositories.'), 16 - ), 17 - array( 18 - 'name' => 'objects', 19 - 'wildcard' => true, 20 - 'help' => pht('Update named commits and repositories.'), 21 - ), 22 - )); 12 + array_merge( 13 + $this->getCommitConstraintArguments(), 14 + array())); 23 15 } 24 16 25 17 public function execute(PhutilArgumentParser $args) { 26 18 $viewer = $this->getViewer(); 27 - 28 - $all = $args->getArg('all'); 29 - $names = $args->getArg('objects'); 30 - 31 - if (!$names && !$all) { 32 - throw new PhutilArgumentUsageException( 33 - pht( 34 - 'Specify "--all" to update everything, or a list of specific '. 35 - 'commits or repositories to update.')); 36 - } else if ($names && $all) { 37 - throw new PhutilArgumentUsageException( 38 - pht( 39 - 'Specify either a list of objects to update or "--all", but not '. 40 - 'both.')); 41 - } 42 - 43 - if ($all) { 44 - $objects = new LiskMigrationIterator(new PhabricatorRepository()); 45 - } else { 46 - $query = id(new PhabricatorObjectQuery()) 47 - ->setViewer($viewer) 48 - ->withNames($names); 49 - 50 - $query->execute(); 51 - 52 - $objects = array(); 53 - 54 - $results = $query->getNamedResults(); 55 - foreach ($names as $name) { 56 - if (!isset($results[$name])) { 57 - throw new PhutilArgumentUsageException( 58 - pht( 59 - 'Object "%s" is not a valid object.', 60 - $name)); 61 - } 62 - 63 - $object = $results[$name]; 64 - if (!($object instanceof PhabricatorRepository) && 65 - !($object instanceof PhabricatorRepositoryCommit)) { 66 - throw new PhutilArgumentUsageException( 67 - pht( 68 - 'Object "%s" is not a valid repository or commit.', 69 - $name)); 70 - } 71 - 72 - $objects[] = $object; 73 - } 74 - } 19 + $objects = $this->loadCommitsWithConstraints($args); 75 20 76 21 foreach ($objects as $object) { 77 - if ($object instanceof PhabricatorRepository) { 78 - $commits = id(new DiffusionCommitQuery()) 79 - ->setViewer($viewer) 80 - ->withRepository($object) 81 - ->execute(); 82 - } else { 83 - $commits = array($object); 84 - } 22 + $commits = $this->loadCommitsForConstraintObject($object); 85 23 86 24 foreach ($commits as $commit) { 87 25 $repository = $commit->getRepository();
+40
src/docs/user/userguide/audit.diviner
··· 156 156 - Press "?" to view keyboard shortcuts. 157 157 158 158 159 + Audit Maintenance 160 + ================= 161 + 162 + The `bin/audit` command allows you to perform several maintenance operations. 163 + Get more information about a command by running: 164 + 165 + ``` 166 + phabricator/ $ ./bin/audit help <command> 167 + ``` 168 + 169 + Supported operations are: 170 + 171 + **Delete Audits**: Delete audits that match certain parameters with 172 + `bin/audit delete`. 173 + 174 + You can use this command to forcibly delete requests which may have triggered 175 + incorrectly (for example, because a package or Herald rule was configured in an 176 + overbroad way). 177 + 178 + After deleting audits, you may want to run `bin/audit synchronize` to 179 + synchronize audit state. 180 + 181 + **Synchronize Audit State**: Synchronize the audit state of commits to the 182 + current open audit requests with `bin/audit synchronize`. 183 + 184 + Normally, overall audit state is automatically kept up to date as changes are 185 + made to an audit. However, if you delete audits or manually update the database 186 + to make changes to audit request state, the state of corresponding commits may 187 + no longer be correct. 188 + 189 + This command will update commits so their overall audit state reflects the 190 + cumulative state of their actual audit requests. 191 + 192 + **Update Owners Package Membership**: Update which Owners packages commits 193 + belong to with `bin/audit update-owners`. 194 + 195 + Normally, commits are automatically associated with packages when they are 196 + imported. You can use this command to manually rebuild this association if 197 + you run into problems with it. 198 + 159 199 Next Steps 160 200 ========== 161 201