Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
PopulateFollowupRevisions | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
56 |
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 PopulateFollowupRevisions extends Maintenance { |
13 | public function __construct() { |
14 | parent::__construct(); |
15 | $this->addDescription( 'Populates followup revisions. Useful for setting them on old ' . |
16 | 'revisions, without reimporting' ); |
17 | $this->addArg( 'repo', 'The name of the repo. Cannot be all.' ); |
18 | $this->addArg( 'revisions', |
19 | 'The revisions to set followups revisions for. Format: start:end' ); |
20 | $this->addOption( 'dry-run', 'Perform a dry run' ); |
21 | |
22 | $this->requireExtension( 'CodeReview' ); |
23 | } |
24 | |
25 | public function execute() { |
26 | $repoName = $this->getArg( 0 ); |
27 | |
28 | if ( $repoName == 'all' ) { |
29 | $this->fatalError( "Cannot use the 'all' repo" ); |
30 | } |
31 | |
32 | $repo = CodeRepository::newFromName( $repoName ); |
33 | if ( !$repo ) { |
34 | $this->fatalError( "Repo '{$repoName}' is not a valid Repository" ); |
35 | } |
36 | |
37 | $revisions = $this->getArg( 1 ); |
38 | if ( strpos( $revisions, ':' ) !== false ) { |
39 | $revisionVals = explode( ':', $revisions, 2 ); |
40 | } else { |
41 | $this->fatalError( "Invalid revision range" ); |
42 | } |
43 | |
44 | $start = intval( $revisionVals[0] ); |
45 | $end = intval( $revisionVals[1] ); |
46 | |
47 | $revisions = range( $start, $end ); |
48 | |
49 | $dryrun = $this->hasOption( 'dry-run' ); |
50 | |
51 | $dbr = wfGetDB( DB_REPLICA ); |
52 | |
53 | $res = $dbr->select( |
54 | 'code_rev', |
55 | '*', |
56 | [ 'cr_id' => $revisions, 'cr_repo_id' => $repo->getId() ], |
57 | __METHOD__ |
58 | ); |
59 | |
60 | foreach ( $res as $row ) { |
61 | $rev = CodeRevision::newFromRow( $repo, $row ); |
62 | |
63 | $affectedRevs = $rev->getUniqueAffectedRevs(); |
64 | |
65 | $this->output( "r{$row->cr_id}: " ); |
66 | |
67 | if ( count( $affectedRevs ) ) { |
68 | $this->output( 'associating revs ' . implode( ',', $affectedRevs ) . "\n" ); |
69 | |
70 | if ( !$dryrun ) { |
71 | $rev->addReferencesTo( $affectedRevs ); |
72 | } |
73 | } else { |
74 | $this->output( "no revisions followed up\n" ); |
75 | } |
76 | } |
77 | $this->output( "Done!\n" ); |
78 | } |
79 | } |
80 | |
81 | $maintClass = PopulateFollowupRevisions::class; |
82 | require_once RUN_MAINTENANCE_IF_MAIN; |