MediaWiki REL1_35
populateExternallinksIndex60.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
27
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 );
41 }
42
43 protected function getUpdateKey() {
44 return 'populate externallinks.el_index_60';
45 }
46
47 protected function updateSkippedMessage() {
48 return 'externallinks.el_index_60 already populated.';
49 }
50
51 protected function doDBUpdates() {
52 $dbw = $this->getDB( DB_MASTER );
53 $this->output( "Populating externallinks.el_index_60...\n" );
54
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' ],
63 [
64 "el_id > $start",
65 "el_id <= $end",
66 'el_index_60' => '',
67 ],
68 __METHOD__,
69 [ 'ORDER BY' => 'el_id' ]
70 );
71 foreach ( $res as $row ) {
72 $count++;
73 $dbw->update( 'externallinks',
74 [
75 'el_index_60' => substr( $row->el_index, 0, 60 ),
76 ],
77 [
78 'el_id' => $row->el_id,
79 ], __METHOD__
80 );
81 }
82 $lbFactory->waitForReplication();
83 $start = $end;
84 }
85 $this->output( "Done, $count rows updated.\n" );
86
87 return true;
88 }
89}
90
91$maintClass = PopulateExternallinksIndex60::class;
92require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
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.
MediaWikiServices is the service locator for the application scope of MediaWiki.
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.
const DB_MASTER
Definition defines.php:29