Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
BulkStatusUpdate | |
0.00% |
0 / 44 |
|
0.00% |
0 / 2 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
110 |
1 | <?php |
2 | |
3 | use MediaWiki\Extension\CodeReview\Backend\CodeRepository; |
4 | use MediaWiki\Extension\CodeReview\Backend\CodeRevision; |
5 | |
6 | $IP = getenv( 'MW_INSTALL_PATH' ); |
7 | if ( $IP === false ) { |
8 | $IP = __DIR__ . '/../../..'; |
9 | } |
10 | require_once "$IP/maintenance/Maintenance.php"; |
11 | |
12 | class BulkStatusUpdate extends Maintenance { |
13 | |
14 | public function __construct() { |
15 | parent::__construct(); |
16 | $this->addDescription( 'Updates a range of revisions to a specific status' ); |
17 | $this->addArg( 'repo', 'The name of the repo. Cannot be all.' ); |
18 | $this->addArg( 'revisions', 'The revisions to set status for. Format: start:end' ); |
19 | $this->addArg( 'status', "Code States: 'new', 'fixme', 'reverted', " |
20 | . "'resolved', 'ok', 'deferred', 'old'" ); |
21 | $this->addArg( 'user', 'Username for whom to accredit the state changes to.' . |
22 | "The User needs to have the 'codereview-set-status' right" ); |
23 | |
24 | $this->requireExtension( 'CodeReview' ); |
25 | } |
26 | |
27 | public function execute() { |
28 | $repoName = $this->getArg( 0 ); |
29 | |
30 | if ( $repoName == 'all' ) { |
31 | $this->fatalError( "Cannot use the 'all' repo" ); |
32 | } |
33 | |
34 | $repo = CodeRepository::newFromName( $repoName ); |
35 | if ( !$repo ) { |
36 | $this->fatalError( "Repo '{$repoName}' is not a valid Repository" ); |
37 | } |
38 | |
39 | $revisions = $this->getArg( 1 ); |
40 | if ( strpos( $revisions, ':' ) !== false ) { |
41 | $revisionVals = explode( ':', $revisions, 2 ); |
42 | } else { |
43 | $this->fatalError( 'Invalid revision range' ); |
44 | } |
45 | |
46 | $start = intval( $revisionVals[0] ); |
47 | $end = intval( $revisionVals[1] ); |
48 | |
49 | $revisions = range( $start, $end ); |
50 | |
51 | $status = $this->getArg( 2 ); |
52 | |
53 | if ( !CodeRevision::isValidStatus( $status ) ) { |
54 | $this->fatalError( "'{$status}' is not a valid status" ); |
55 | } |
56 | |
57 | $username = $this->getArg( 3 ); |
58 | $user = User::newFromName( $username ); |
59 | |
60 | if ( !$user ) { |
61 | $this->fatalError( "'{$username}' is not a valid username" ); |
62 | } |
63 | |
64 | if ( !$user->isAllowed( 'codereview-set-status' ) ) { |
65 | $this->fatalError( "'{$username}' does not have the 'codereview-set-status' right" ); |
66 | } |
67 | |
68 | $dbr = wfGetDB( DB_REPLICA ); |
69 | |
70 | $res = $dbr->select( |
71 | 'code_rev', |
72 | '*', |
73 | [ 'cr_id' => $revisions, 'cr_repo_id' => $repo->getId() ], |
74 | __METHOD__ |
75 | ); |
76 | |
77 | foreach ( $res as $row ) { |
78 | $rev = CodeRevision::newFromRow( $repo, $row ); |
79 | |
80 | if ( $rev && $rev->setStatus( $status, $user ) ) { |
81 | $this->output( "r{$row->cr_id} updated\n" ); |
82 | } else { |
83 | $this->output( "r{$row->cr_id} not updated\n" ); |
84 | } |
85 | } |
86 | |
87 | $this->output( "Done!\n" ); |
88 | } |
89 | } |
90 | |
91 | $maintClass = BulkStatusUpdate::class; |
92 | require_once RUN_MAINTENANCE_IF_MAIN; |