From adb7f9ed1ca3044789fdf459aa762b25c36566db Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 6 Mar 2012 15:10:25 -0800 Subject: [PATCH] Add a script to close all open audits in a repository Summary: If you import a repository you may trigger a large number of irrelevant audits. Provide a tool to nuke them. Test Plan: Ran "audit.php Q" (does not exist), "audit.php P" (phabricator) from various repository states. Reviewers: btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T904, T940 Differential Revision: https://secure.phabricator.com/D1791 --- scripts/repository/audit.php | 99 ++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 scripts/repository/audit.php diff --git a/scripts/repository/audit.php b/scripts/repository/audit.php new file mode 100755 index 0000000000..6e729d5352 --- /dev/null +++ b/scripts/repository/audit.php @@ -0,0 +1,99 @@ +#!/usr/bin/env php +setTagline('manage open Audit requests'); +$args->setSynopsis(<<parseStandardArguments(); +$args->parse( + array( + array( + 'name' => 'more', + 'wildcard' => true, + ), + )); + +$more = $args->getArg('more'); +if (count($more) !== 1) { + $args->printHelpAndExit(); +} +$callsign = reset($more); + +$repository = id(new PhabricatorRepository())->loadOneWhere( + 'callsign = %s', + $callsign); +if (!$repository) { + throw new Exception("No repository exists with callsign '{$callsign}'!"); +} + +$ok = phutil_console_confirm( + 'This will reset all open audit requests ("Audit Required" or "Concern '. + 'Raised") for commits in this repository to "Audit Not Required". This '. + 'operation destroys information and can not be undone! Are you sure '. + 'you want to proceed?'); +if (!$ok) { + echo "OK, aborting.\n"; + die(1); +} + +echo "Loading commits...\n"; +$all_commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( + 'repositoryID = %d', + $repository->getID()); + +echo "Clearing audit requests...\n"; + +foreach ($all_commits as $commit) { + $query = id(new PhabricatorAuditQuery()) + ->withStatus(PhabricatorAuditQuery::STATUS_OPEN) + ->withCommitPHIDs(array($commit->getPHID())); + $requests = $query->execute(); + + echo "Clearing ".$commit->getPHID()."... "; + + if (!$requests) { + echo "nothing to do.\n"; + continue; + } else { + echo count($requests)." requests to clear"; + } + + foreach ($requests as $request) { + $request->setAuditStatus( + PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED); + $request->save(); + echo "."; + } + + $commit->setAuditStatus(PhabricatorAuditCommitStatusConstants::NONE); + $commit->save(); + echo "\n"; +} + +echo "Done.\n";