Skip to content

Commit 86989c9

Browse files
author
epriestley
committedAug 5, 2013
Provide a more flexible script for administrative management of audits
Summary: Fixes T3679. This comes up every so often and the old script is extremely broad (nuke everything in a repository). Provide a more surgical tool. Test Plan: Ran a bunch of variations of the script and they all seemed to work OK. Reviewers: btrahan Reviewed By: btrahan CC: aran, staticshock Maniphest Tasks: T3679 Differential Revision: https://secure.phabricator.com/D6678
1 parent 02ccca4 commit 86989c9

7 files changed

+342
-81
lines changed
 

‎bin/audit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/setup/manage_audit.php

‎scripts/repository/audit.php

+2-80
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,5 @@
11
#!/usr/bin/env php
22
<?php
33

4-
$root = dirname(dirname(dirname(__FILE__)));
5-
require_once $root.'/scripts/__init_script__.php';
6-
7-
$args = new PhutilArgumentParser($argv);
8-
$args->setTagline('manage open Audit requests');
9-
$args->setSynopsis(<<<EOSYNOPSIS
10-
**audit.php** __repository_callsign__
11-
Close all open audit requests in a repository. This is intended to
12-
reset the state of an imported repository which triggered a bunch of
13-
spurious audit requests during import.
14-
15-
EOSYNOPSIS
16-
);
17-
$args->parseStandardArguments();
18-
$args->parse(
19-
array(
20-
array(
21-
'name' => 'more',
22-
'wildcard' => true,
23-
),
24-
));
25-
26-
$more = $args->getArg('more');
27-
if (count($more) !== 1) {
28-
$args->printHelpAndExit();
29-
}
30-
$callsign = reset($more);
31-
32-
$repository = id(new PhabricatorRepository())->loadOneWhere(
33-
'callsign = %s',
34-
$callsign);
35-
if (!$repository) {
36-
throw new Exception("No repository exists with callsign '{$callsign}'!");
37-
}
38-
39-
$ok = phutil_console_confirm(
40-
'This will reset all open audit requests ("Audit Required" or "Concern '.
41-
'Raised") for commits in this repository to "Audit Not Required". This '.
42-
'operation destroys information and can not be undone! Are you sure '.
43-
'you want to proceed?');
44-
if (!$ok) {
45-
echo "OK, aborting.\n";
46-
die(1);
47-
}
48-
49-
echo "Loading commits...\n";
50-
$all_commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
51-
'repositoryID = %d',
52-
$repository->getID());
53-
54-
echo "Clearing audit requests...\n";
55-
56-
foreach ($all_commits as $commit) {
57-
$query = id(new PhabricatorAuditQuery())
58-
->withStatus(PhabricatorAuditQuery::STATUS_OPEN)
59-
->withCommitPHIDs(array($commit->getPHID()));
60-
$requests = $query->execute();
61-
62-
echo "Clearing ".$commit->getPHID()."... ";
63-
64-
if (!$requests) {
65-
echo "nothing to do.\n";
66-
continue;
67-
} else {
68-
echo count($requests)." requests to clear";
69-
}
70-
71-
foreach ($requests as $request) {
72-
$request->setAuditStatus(
73-
PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED);
74-
$request->save();
75-
echo ".";
76-
}
77-
78-
$commit->setAuditStatus(PhabricatorAuditCommitStatusConstants::NONE);
79-
$commit->save();
80-
echo "\n";
81-
}
82-
83-
echo "Done.\n";
4+
echo "This script has been replaced with `bin/audit`.\n";
5+
exit(1);

‎scripts/setup/manage_audit.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$root = dirname(dirname(dirname(__FILE__)));
5+
require_once $root.'/scripts/__init_script__.php';
6+
7+
$args = new PhutilArgumentParser($argv);
8+
$args->setTagline('manage audits');
9+
$args->setSynopsis(<<<EOSYNOPSIS
10+
**audit** __command__ [__options__]
11+
Manage Phabricator audits.
12+
13+
EOSYNOPSIS
14+
);
15+
$args->parseStandardArguments();
16+
17+
$workflows = array(
18+
new PhabricatorAuditManagementDeleteWorkflow(),
19+
new PhutilHelpArgumentWorkflow(),
20+
);
21+
22+
$args->parseWorkflows($workflows);

‎src/__phutil_library_map__.php

+4
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,8 @@
862862
'PhabricatorAuditListController' => 'applications/audit/controller/PhabricatorAuditListController.php',
863863
'PhabricatorAuditListView' => 'applications/audit/view/PhabricatorAuditListView.php',
864864
'PhabricatorAuditMailReceiver' => 'applications/audit/mail/PhabricatorAuditMailReceiver.php',
865+
'PhabricatorAuditManagementDeleteWorkflow' => 'applications/audit/management/PhabricatorAuditManagementDeleteWorkflow.php',
866+
'PhabricatorAuditManagementWorkflow' => 'applications/audit/management/PhabricatorAuditManagementWorkflow.php',
865867
'PhabricatorAuditPreviewController' => 'applications/audit/controller/PhabricatorAuditPreviewController.php',
866868
'PhabricatorAuditQuery' => 'applications/audit/query/PhabricatorAuditQuery.php',
867869
'PhabricatorAuditReplyHandler' => 'applications/audit/mail/PhabricatorAuditReplyHandler.php',
@@ -2884,6 +2886,8 @@
28842886
'PhabricatorAuditListController' => 'PhabricatorAuditController',
28852887
'PhabricatorAuditListView' => 'AphrontView',
28862888
'PhabricatorAuditMailReceiver' => 'PhabricatorObjectMailReceiver',
2889+
'PhabricatorAuditManagementDeleteWorkflow' => 'PhabricatorAuditManagementWorkflow',
2890+
'PhabricatorAuditManagementWorkflow' => 'PhutilArgumentWorkflow',
28872891
'PhabricatorAuditPreviewController' => 'PhabricatorAuditController',
28882892
'PhabricatorAuditReplyHandler' => 'PhabricatorMailReplyHandler',
28892893
'PhabricatorAuthAccountView' => 'AphrontView',

0 commit comments

Comments
 (0)
Failed to load comments.