Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
UpdateIndexGranularity | |
0.00% |
0 / 33 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
6 |
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 UpdateIndexGranularity extends Maintenance { |
12 | |
13 | public function __construct() { |
14 | parent::__construct(); |
15 | $this->addDescription( |
16 | 'Updates GeoData database after $wgGeoDataIndexGranularity has been changed' ); |
17 | $this->setBatchSize( 500 ); |
18 | $this->requireExtension( 'GeoData' ); |
19 | } |
20 | |
21 | public function execute() { |
22 | $batchSize = $this->getBatchSize(); |
23 | $id = 0; |
24 | $dbw = $this->getPrimaryDB(); |
25 | |
26 | do { |
27 | $ids = []; |
28 | |
29 | $this->beginTransaction( $dbw, __METHOD__ ); |
30 | $res = $dbw->newSelectQueryBuilder() |
31 | ->select( 'gt_id' ) |
32 | ->from( 'geo_tags' ) |
33 | ->where( $dbw->expr( 'gt_id', '>', $id ) ) |
34 | ->limit( $batchSize ) |
35 | ->caller( __METHOD__ ) |
36 | ->fetchResultSet(); |
37 | foreach ( $res as $row ) { |
38 | $id = $row->gt_id; |
39 | $ids[] = $id; |
40 | } |
41 | $indexGranularity = $this->getConfig()->get( 'GeoDataIndexGranularity' ); |
42 | $dbw->newUpdateQueryBuilder() |
43 | ->update( 'geo_tags' ) |
44 | ->set( [ |
45 | "gt_lat_int = ROUND(gt_lat * $indexGranularity)", |
46 | "gt_lon_int = ROUND(gt_lon * $indexGranularity)" |
47 | ] ) |
48 | ->where( [ 'gt_id' => $ids ] ) |
49 | ->caller( __METHOD__ ) |
50 | ->execute(); |
51 | $this->commitTransaction( $dbw, __METHOD__ ); |
52 | |
53 | $this->output( "$id\n" ); |
54 | } while ( count( $ids ) === $batchSize ); |
55 | } |
56 | } |
57 | |
58 | $maintClass = UpdateIndexGranularity::class; |
59 | require_once RUN_MAINTENANCE_IF_MAIN; |