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
21 * @ingroup Maintenance
24 require_once __DIR__
. '/Maintenance.php';
26 use MediaWiki\MediaWikiServices
;
29 * Maintenance script that populates the el_index_60 field in the externallinks
32 * @ingroup Maintenance
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" );
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' ],
69 [ 'ORDER BY' => 'el_id' ]
71 foreach ( $res as $row ) {
73 $dbw->update( 'externallinks',
75 'el_index_60' => substr( $row->el_index
, 0, 60 ),
78 'el_id' => $row->el_id
,
82 $lbFactory->waitForReplication();
85 $this->output( "Done, $count rows updated.\n" );
91 $maintClass = PopulateExternallinksIndex60
::class;
92 require_once RUN_MAINTENANCE_IF_MAIN
;