MediaWiki  master
populateExternallinksIndex60.php
Go to the documentation of this file.
1 <?php
24 require_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;
92 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:38
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:108
PopulateExternallinksIndex60\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: populateExternallinksIndex60.php:47
PopulateExternallinksIndex60\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: populateExternallinksIndex60.php:51
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:165
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:327
$res
$res
Definition: testCompression.php:57
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: LoggedUpdateMaintenance.php:26
$maintClass
$maintClass
Definition: populateExternallinksIndex60.php:91
PopulateExternallinksIndex60
Maintenance script that populates the el_index_60 field in the externallinks table.
Definition: populateExternallinksIndex60.php:35
DB_MASTER
const DB_MASTER
Definition: defines.php:26
PopulateExternallinksIndex60\__construct
__construct()
Default constructor.
Definition: populateExternallinksIndex60.php:36
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1369
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:433
PopulateExternallinksIndex60\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: populateExternallinksIndex60.php:43
Maintenance\setBatchSize
setBatchSize( $s=0)
Definition: Maintenance.php:373