build: Upgrade mediawiki-codesniffer from 26.0.0 to 28.0.0
[lhc/web/wiklou.git] / maintenance / populateExternallinksIndex60.php
1 <?php
2 /**
3 * Populates the el_index_60 field in the externallinks table.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24 require_once __DIR__ . '/Maintenance.php';
25
26 /**
27 * Maintenance script that populates the el_index_60 field in the externallinks
28 * table.
29 *
30 * @ingroup Maintenance
31 * @since 1.32
32 */
33 class PopulateExternallinksIndex60 extends LoggedUpdateMaintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription(
37 'Populates the el_index_60 field in the externallinks table' );
38 $this->setBatchSize( 200 );
39 }
40
41 protected function getUpdateKey() {
42 return 'populate externallinks.el_index_60';
43 }
44
45 protected function updateSkippedMessage() {
46 return 'externallinks.el_index_60 already populated.';
47 }
48
49 protected function doDBUpdates() {
50 $dbw = $this->getDB( DB_MASTER );
51 $this->output( "Populating externallinks.el_index_60...\n" );
52
53 $count = 0;
54 $start = 0;
55 $last = $dbw->selectField( 'externallinks', 'MAX(el_id)', '', __METHOD__ );
56 while ( $start <= $last ) {
57 $end = $start + $this->mBatchSize;
58 $this->output( "el_id $start - $end of $last\n" );
59 $res = $dbw->select( 'externallinks', [ 'el_id', 'el_index' ],
60 [
61 "el_id > $start",
62 "el_id <= $end",
63 'el_index_60' => '',
64 ],
65 __METHOD__,
66 [ 'ORDER BY' => 'el_id' ]
67 );
68 foreach ( $res as $row ) {
69 $count++;
70 $dbw->update( 'externallinks',
71 [
72 'el_index_60' => substr( $row->el_index, 0, 60 ),
73 ],
74 [
75 'el_id' => $row->el_id,
76 ], __METHOD__
77 );
78 }
79 wfWaitForSlaves();
80 $start = $end;
81 }
82 $this->output( "Done, $count rows updated.\n" );
83
84 return true;
85 }
86 }
87
88 $maintClass = "PopulateExternallinksIndex60";
89 require_once RUN_MAINTENANCE_IF_MAIN;