Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PopulateShortUrlTable | |
0.00% |
0 / 37 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
insertRows | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | use MediaWiki\Maintenance\Maintenance; |
4 | |
5 | $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | if ( $IP === false ) { |
7 | $IP = __DIR__ . '/../..'; |
8 | } |
9 | require_once "$IP/maintenance/Maintenance.php"; |
10 | |
11 | class PopulateShortUrlTable extends Maintenance { |
12 | public function __construct() { |
13 | parent::__construct(); |
14 | $this->addDescription( 'Populates ShortUrls Table with all existing articles' ); |
15 | $this->requireExtension( 'ShortUrl' ); |
16 | } |
17 | |
18 | /** |
19 | * @param mixed $a |
20 | */ |
21 | private function insertRows( $a ) { |
22 | $dbw = $this->getPrimaryDB(); |
23 | $dbw->newInsertQueryBuilder() |
24 | ->insertInto( 'shorturls' ) |
25 | ->ignore() |
26 | ->rows( $a ) |
27 | ->caller( __METHOD__ ) |
28 | ->execute(); |
29 | } |
30 | |
31 | /** |
32 | * @todo FIXME: Refactor out code in ShortUrlUtils.php so it can be used here |
33 | */ |
34 | public function execute() { |
35 | $rowCount = 0; |
36 | $dbr = $this->getReplicaDB(); |
37 | |
38 | $last_processed_id = 0; |
39 | |
40 | while ( true ) { |
41 | $insertBuffer = []; |
42 | $res = $dbr->newSelectQueryBuilder() |
43 | ->select( [ 'page_id', 'page_namespace', 'page_title' ] ) |
44 | ->from( 'page' ) |
45 | ->where( $dbr->expr( 'page_id', '>', $last_processed_id ) ) |
46 | ->limit( 100 ) |
47 | ->orderBy( 'page_id' ) |
48 | ->caller( __METHOD__ ) |
49 | ->fetchResultSet(); |
50 | if ( $res->numRows() == 0 ) { |
51 | break; |
52 | } |
53 | |
54 | foreach ( $res as $row ) { |
55 | $rowCount++; |
56 | |
57 | $rowData = [ |
58 | 'su_namespace' => $row->page_namespace, |
59 | 'su_title' => $row->page_title |
60 | ]; |
61 | $insertBuffer[] = $rowData; |
62 | |
63 | $last_processed_id = $row->page_id; |
64 | } |
65 | |
66 | $this->insertRows( $insertBuffer ); |
67 | $this->waitForReplication(); |
68 | $this->output( $rowCount . " titles done\n" ); |
69 | } |
70 | $this->output( "Done\n" ); |
71 | } |
72 | } |
73 | |
74 | $maintClass = PopulateShortUrlTable::class; |
75 | require_once RUN_MAINTENANCE_IF_MAIN; |