7require_once __DIR__ .
'/Maintenance.php';
18 parent::__construct();
20 'Migrate externallinks data'
24 'Sleep time (in seconds) between every batch. Default: 0',
37 $table =
'externallinks';
38 if ( !$dbw->fieldExists( $table,
'el_to', __METHOD__ ) ) {
39 $this->
output(
"Old fields don't exist. There is no need to run this script\n" );
42 if ( !$dbw->fieldExists( $table,
'el_to_path', __METHOD__ ) ) {
43 $this->
output(
"Run update.php to create the el_to_path column.\n" );
47 $this->
output(
"Populating el_to_domain_index and el_to_path columns\n" );
50 $highestId = $dbw->newSelectQueryBuilder()
54 ->caller( __METHOD__ )
55 ->orderBy(
'el_id',
'DESC' )
56 ->fetchResultSet()->fetchRow();
58 $this->
output(
"Page table is empty.\n" );
61 $highestId = $highestId[0];
63 while ( $id <= $highestId ) {
64 $updated += $this->handleBatch( $id );
68 $this->
output(
"Completed normalization of $table, $updated rows updated.\n" );
73 private function handleBatch( $lowId ) {
74 $batchSize = $this->getBatchSize();
76 $highId = $lowId + $batchSize - 1;
77 $dbw = $this->getPrimaryDB();
79 $res = $dbw->newSelectQueryBuilder()
80 ->select( [
'el_id',
'el_to' ] )
81 ->from(
'externallinks' )
83 'el_to_domain_index' =>
'',
84 $dbw->expr(
'el_id',
'>=', $lowId ),
85 $dbw->expr(
'el_id',
'<=', $highId ),
88 ->caller( __METHOD__ )
90 if ( !$res->numRows() ) {
93 foreach ( $res as $row ) {
95 $paths = LinkFilter::makeIndexes(
$url );
99 $dbw->newUpdateQueryBuilder()
100 ->update(
'externallinks' )
103 'el_to_domain_index' => substr( $paths[0][0], 0, 255 ),
104 'el_to_path' => $paths[0][1]
106 ->where( [
'el_id' => $row->el_id ] )
107 ->caller( __METHOD__ )->execute();
109 $updated += $dbw->affectedRows();
111 $this->
output(
"Updated $updated rows\n" );
114 $sleep = (int)$this->
getOption(
'sleep', 0 );
125require_once RUN_MAINTENANCE_IF_MAIN;
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
waitForReplication()
Wait for replica DB servers to catch up.
getOption( $name, $default=null)
Get an option, or return the default.
addDescription( $text)
Set the description text.
Maintenance script that migrates externallinks data.
__construct()
Default constructor.
getUpdateKey()
Get the update key name to go in the update log table.
doDBUpdates()
Do the actual work.