7require_once __DIR__ .
'/Maintenance.php';
18 parent::__construct();
20 'Migrate externallinks data'
24 'Sleep time (in seconds) between every batch. Default: 0',
39 $table =
'externallinks';
40 if ( !$dbw->fieldExists( $table,
'el_to', __METHOD__ ) ) {
41 $this->
output(
"Old fields don't exist. There is no need to run this script\n" );
44 if ( !$dbw->fieldExists( $table,
'el_to_path', __METHOD__ ) ) {
45 $this->
output(
"Run update.php to create the el_to_path column.\n" );
49 $this->
output(
"Populating el_to_domain_index and el_to_path columns\n" );
52 $highestId = $dbw->newSelectQueryBuilder()
56 ->caller( __METHOD__ )
57 ->orderBy(
'el_id',
'DESC' )
58 ->fetchResultSet()->fetchRow();
60 $this->
output(
"Page table is empty.\n" );
63 $highestId = $highestId[0];
65 while ( $id <= $highestId ) {
66 $updated += $this->handleBatch( $id );
70 $this->
output(
"Completed normalization of $table, $updated rows updated.\n" );
75 private function handleBatch(
int $lowId ): int {
76 $batchSize = $this->getBatchSize();
78 $highId = $lowId + $batchSize - 1;
79 $dbw = $this->getPrimaryDB();
81 $res = $dbw->newSelectQueryBuilder()
82 ->select( [
'el_id',
'el_to' ] )
83 ->from(
'externallinks' )
85 'el_to_domain_index' =>
'',
86 $dbw->expr(
'el_id',
'>=', $lowId ),
87 $dbw->expr(
'el_id',
'<=', $highId ),
90 ->caller( __METHOD__ )
92 if ( !$res->numRows() ) {
95 foreach ( $res as $row ) {
97 $paths = LinkFilter::makeIndexes(
$url );
101 $dbw->newUpdateQueryBuilder()
102 ->update(
'externallinks' )
105 'el_to_domain_index' => substr( $paths[0][0], 0, 255 ),
106 'el_to_path' => $paths[0][1]
108 ->where( [
'el_id' => $row->el_id ] )
109 ->caller( __METHOD__ )->execute();
111 $updated += $dbw->affectedRows();
113 $this->
output(
"Updated $updated rows\n" );
116 $sleep = (int)$this->
getOption(
'sleep', 0 );
127require_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.string
doDBUpdates()
Do the actual work.All child classes will need to implement this. Return true to log the update as do...