Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 37
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UpdateIndexGranularity
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3$IP = getenv( 'MW_INSTALL_PATH' );
4if ( $IP === false ) {
5    $IP = __DIR__ . '/../../..';
6}
7require_once "$IP/maintenance/Maintenance.php";
8
9class UpdateIndexGranularity extends Maintenance {
10
11    public function __construct() {
12        parent::__construct();
13        $this->addDescription(
14            'Updates GeoData database after $wgGeoDataIndexGranularity has been changed' );
15        $this->setBatchSize( 500 );
16        $this->requireExtension( 'GeoData' );
17    }
18
19    public function execute() {
20        global $wgGeoDataIndexGranularity;
21
22        $batchSize = $this->getBatchSize();
23        $id = 0;
24        $dbw = $this->getDB( DB_PRIMARY );
25
26        do {
27            $ids = [];
28
29            $this->beginTransaction( $dbw, __METHOD__ );
30            $res = $dbw->select( 'geo_tags', 'gt_id',
31                [ "gt_id > $id" ],
32                __METHOD__,
33                [ 'LIMIT' => $batchSize ]
34            );
35            foreach ( $res as $row ) {
36                $id = $row->gt_id;
37                $ids[] = $id;
38            }
39            $dbw->newUpdateQueryBuilder()
40                ->update( 'geo_tags' )
41                ->set( [
42                    "gt_lat_int = ROUND(gt_lat * $wgGeoDataIndexGranularity)",
43                    "gt_lon_int = ROUND(gt_lon * $wgGeoDataIndexGranularity)"
44                ] )
45                ->where( [ 'gt_id' => $ids ] )
46                ->caller( __METHOD__ )
47                ->execute();
48            $this->commitTransaction( $dbw, __METHOD__ );
49
50            $this->output( "$id\n" );
51        } while ( count( $ids ) === $batchSize );
52    }
53}
54
55$maintClass = UpdateIndexGranularity::class;
56require_once RUN_MAINTENANCE_IF_MAIN;