MediaWiki REL1_34
populateExternallinksIndex60.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
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 }
80 $start = $end;
81 }
82 $this->output( "Done, $count rows updated.\n" );
83
84 return true;
85 }
86}
87
88$maintClass = "PopulateExternallinksIndex60";
89require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
const RUN_MAINTENANCE_IF_MAIN
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
int $mBatchSize
Batch size.
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Set the batch size.
Maintenance script that populates the el_index_60 field in the externallinks table.
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
getUpdateKey()
Get the update key name to go in the update log table.
$last
const DB_MASTER
Definition defines.php:26