Revision: Remove some unnecessary temporary variables for returns
[mediawiki.git] / maintenance / populateExternallinksIndex60.php
blob5aa28a0ad39d7f6f6fa37ad507d00991e6179f85
1 <?php
2 /**
3 * Populates the el_index_60 field in the externallinks table.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Maintenance
24 require_once __DIR__ . '/Maintenance.php';
26 use MediaWiki\MediaWikiServices;
28 /**
29 * Maintenance script that populates the el_index_60 field in the externallinks
30 * table.
32 * @ingroup Maintenance
33 * @since 1.32
35 class PopulateExternallinksIndex60 extends LoggedUpdateMaintenance {
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription(
39 'Populates the el_index_60 field in the externallinks table' );
40 $this->setBatchSize( 200 );
43 protected function getUpdateKey() {
44 return 'populate externallinks.el_index_60';
47 protected function updateSkippedMessage() {
48 return 'externallinks.el_index_60 already populated.';
51 protected function doDBUpdates() {
52 $dbw = $this->getDB( DB_MASTER );
53 $this->output( "Populating externallinks.el_index_60...\n" );
55 $count = 0;
56 $start = 0;
57 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
58 $last = $dbw->selectField( 'externallinks', 'MAX(el_id)', '', __METHOD__ );
59 while ( $start <= $last ) {
60 $end = $start + $this->mBatchSize;
61 $this->output( "el_id $start - $end of $last\n" );
62 $res = $dbw->select( 'externallinks', [ 'el_id', 'el_index' ],
64 "el_id > $start",
65 "el_id <= $end",
66 'el_index_60' => '',
68 __METHOD__,
69 [ 'ORDER BY' => 'el_id' ]
71 foreach ( $res as $row ) {
72 $count++;
73 $dbw->update( 'externallinks',
75 'el_index_60' => substr( $row->el_index, 0, 60 ),
78 'el_id' => $row->el_id,
79 ], __METHOD__
82 $lbFactory->waitForReplication();
83 $start = $end;
85 $this->output( "Done, $count rows updated.\n" );
87 return true;
91 $maintClass = PopulateExternallinksIndex60::class;
92 require_once RUN_MAINTENANCE_IF_MAIN;