15 parent::__construct();
17 'Migrate externallinks data'
21 'Sleep time (in seconds) between every batch. Default: 0',
34 $table =
'externallinks';
35 if ( !$dbw->fieldExists( $table,
'el_to', __METHOD__ ) ) {
36 $this->
output(
"Old fields don't exist. There is no need to run this script\n" );
39 if ( !$dbw->fieldExists( $table,
'el_to_path', __METHOD__ ) ) {
40 $this->
output(
"Run update.php to create the el_to_path column.\n" );
44 $this->
output(
"Populating el_to_domain_index and el_to_path columns\n" );
47 $highestId = $dbw->newSelectQueryBuilder()
51 ->caller( __METHOD__ )
52 ->orderBy(
'el_id',
'DESC' )
53 ->fetchResultSet()->fetchRow();
55 $this->
output(
"Page table is empty.\n" );
58 $highestId = $highestId[0];
60 while ( $id <= $highestId ) {
61 $updated += $this->handleBatch( $id );
65 $this->
output(
"Completed normalization of $table, $updated rows updated.\n" );
70 private function handleBatch( $lowId ) {
71 $batchSize = $this->getBatchSize();
73 $highId = $lowId + $batchSize - 1;
74 $dbw = $this->getPrimaryDB();
76 $res = $dbw->newSelectQueryBuilder()
77 ->select( [
'el_id',
'el_to' ] )
78 ->from(
'externallinks' )
80 'el_to_domain_index' =>
'',
81 $dbw->expr(
'el_id',
'>=', $lowId ),
82 $dbw->expr(
'el_id',
'<=', $highId ),
85 ->caller( __METHOD__ )
87 if ( !$res->numRows() ) {
90 foreach ( $res as $row ) {
92 $paths = LinkFilter::makeIndexes( $url );
96 $dbw->newUpdateQueryBuilder()
97 ->update(
'externallinks' )
100 'el_to_domain_index' => substr( $paths[0][0], 0, 255 ),
101 'el_to_path' => $paths[0][1]
103 ->where( [
'el_id' => $row->el_id ] )
104 ->caller( __METHOD__ )->execute();
106 $updated += $dbw->affectedRows();
108 $this->
output(
"Updated $updated rows\n" );
111 $sleep = (int)$this->
getOption(
'sleep', 0 );
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
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.