17 parent::__construct();
19 'Migrate externallinks data'
23 'Sleep time (in seconds) between every batch. Default: 0',
36 $table =
'externallinks';
37 if ( !$dbw->fieldExists( $table,
'el_to', __METHOD__ ) ) {
38 $this->
output(
"Old fields don't exist. There is no need to run this script\n" );
41 if ( !$dbw->fieldExists( $table,
'el_to_path', __METHOD__ ) ) {
42 $this->
output(
"Run update.php to create the el_to_path column.\n" );
46 $this->
output(
"Populating el_to_domain_index and el_to_path columns\n" );
49 $highestId = $dbw->newSelectQueryBuilder()
53 ->caller( __METHOD__ )
54 ->orderBy(
'el_id',
'DESC' )
55 ->fetchResultSet()->fetchRow();
57 $this->
output(
"Page table is empty.\n" );
60 $highestId = $highestId[0];
62 while ( $id <= $highestId ) {
63 $updated += $this->handleBatch( $id );
67 $this->
output(
"Completed normalization of $table, $updated rows updated.\n" );
72 private function handleBatch( $lowId ) {
73 $batchSize = $this->getBatchSize();
75 $highId = $lowId + $batchSize - 1;
76 $dbw = $this->getPrimaryDB();
78 $res = $dbw->newSelectQueryBuilder()
79 ->select( [
'el_id',
'el_to' ] )
80 ->from(
'externallinks' )
82 'el_to_domain_index' =>
'',
83 $dbw->expr(
'el_id',
'>=', $lowId ),
84 $dbw->expr(
'el_id',
'<=', $highId ),
87 ->caller( __METHOD__ )
89 if ( !$res->numRows() ) {
92 foreach ( $res as $row ) {
94 $paths = LinkFilter::makeIndexes(
$url );
98 $dbw->newUpdateQueryBuilder()
99 ->update(
'externallinks' )
102 'el_to_domain_index' => substr( $paths[0][0], 0, 255 ),
103 'el_to_path' => $paths[0][1]
105 ->where( [
'el_id' => $row->el_id ] )
106 ->caller( __METHOD__ )->execute();
108 $updated += $dbw->affectedRows();
110 $this->
output(
"Updated $updated rows\n" );
113 $sleep = (int)$this->
getOption(
'sleep', 0 );
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
output( $out, $channel=null)
Throw some output to the user.
waitForReplication()
Wait for replica DBs to catch up.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.