Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 39
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 / 33
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 / 28
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->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            $dbw->newUpdateQueryBuilder()
42                ->update( 'geo_tags' )
43                ->set( [
44                    "gt_lat_int = ROUND(gt_lat * $wgGeoDataIndexGranularity)",
45                    "gt_lon_int = ROUND(gt_lon * $wgGeoDataIndexGranularity)"
46                ] )
47                ->where( [ 'gt_id' => $ids ] )
48                ->caller( __METHOD__ )
49                ->execute();
50            $this->commitTransaction( $dbw, __METHOD__ );
51
52            $this->output( "$id\n" );
53        } while ( count( $ids ) === $batchSize );
54    }
55}
56
57$maintClass = UpdateIndexGranularity::class;
58require_once RUN_MAINTENANCE_IF_MAIN;