Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 34
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetRevisionDiffs
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 2
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3use MediaWiki\Extension\CodeReview\Backend\CodeRepository;
4use MediaWiki\MediaWikiServices;
5
6$IP = getenv( 'MW_INSTALL_PATH' );
7if ( $IP === false ) {
8    $IP = __DIR__ . '/../../..';
9}
10require_once "$IP/maintenance/Maintenance.php";
11
12class GetRevisionDiffs extends Maintenance {
13    public function __construct() {
14        parent::__construct();
15        $this->addDescription( 'Populates the cr_diff column (where possible) for all rows in a repo' );
16        $this->addArg( 'repo', 'The name of the repo. Cannot be all.' );
17
18        $this->requireExtension( 'CodeReview' );
19    }
20
21    public function execute() {
22        $repoName = $this->getArg( 0 );
23
24        if ( $repoName == 'all' ) {
25            $this->fatalError( "Cannot use the 'all' repo" );
26        }
27
28        $repo = CodeRepository::newFromName( $repoName );
29        if ( !$repo ) {
30            $this->fatalError( "Repo '{$repoName}' is not a valid Repository" );
31        }
32
33        $dbr = wfGetDB( DB_REPLICA );
34        $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
35
36        $res = $dbr->select(
37            'code_rev',
38            'cr_id',
39            [ 'cr_repo_id' => $repo->getId(), 'cr_diff IS NULL' ],
40            __METHOD__
41        );
42
43        $count = 0;
44        foreach ( $res as $row ) {
45            $id = $row->cr_id;
46            try {
47                $diff = $repo->getDiff( $row->cr_id, '' );
48            } catch ( Exception $mwe ) {
49                // Suppress errors
50                $this->output( "$id - error {$mwe->getMessage()}\n" );
51                continue;
52            }
53            if ( is_int( $diff ) ) {
54                $error = CodeRepository::getDiffErrorMessage( $diff );
55                $this->output( "$id - $error\n" );
56            } else {
57                $this->output( "$id\n" );
58            }
59
60            if ( ++$count % 100 == 0 ) {
61                $lbFactory->waitForReplication();
62            }
63        }
64        $this->output( "Done!\n" );
65    }
66}
67
68$maintClass = GetRevisionDiffs::class;
69require_once RUN_MAINTENANCE_IF_MAIN;