MediaWiki  1.34.0
populateExternallinksIndex60.php
Go to the documentation of this file.
1 <?php
24 require_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";
89 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:135
PopulateExternallinksIndex60\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: populateExternallinksIndex60.php:45
PopulateExternallinksIndex60\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: populateExternallinksIndex60.php:49
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
$last
$last
Definition: profileinfo.php:419
$res
$res
Definition: testCompression.php:52
wfWaitForSlaves
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition: GlobalFunctions.php:2718
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1727
$maintClass
$maintClass
Definition: populateExternallinksIndex60.php:88
PopulateExternallinksIndex60
Maintenance script that populates the el_index_60 field in the externallinks table.
Definition: populateExternallinksIndex60.php:33
DB_MASTER
const DB_MASTER
Definition: defines.php:26
PopulateExternallinksIndex60\__construct
__construct()
Default constructor.
Definition: populateExternallinksIndex60.php:34
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1396
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
PopulateExternallinksIndex60\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: populateExternallinksIndex60.php:41
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:394