55 if ( !$dbw->tableExists(
'externallinks', __METHOD__ ) ) {
56 $this->
error(
"externallinks table does not exist" );
59 $this->
output(
"Updating externallinks table index fields\n" );
61 $minmax = $dbw->selectRow(
63 [
'min' =>
'MIN(el_id)',
'max' =>
'MAX(el_id)' ],
70 $start = $minmax->min - 1;
71 $last = (int)$minmax->max;
72 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
73 while ( $start < $last ) {
74 $end = min( $start + $this->mBatchSize, $last );
75 $this->
output(
"el_id $start - $end of $last\n" );
76 $res = $dbw->select(
'externallinks', [
'el_id',
'el_to',
'el_index' ],
82 [
'ORDER BY' =>
'el_id' ]
84 foreach (
$res as $row ) {
87 $dbw->delete(
'externallinks', [
'el_id' => $row->el_id ], __METHOD__ );
91 if ( in_array( $row->el_index, $newIndexes,
true ) ) {
95 if ( count( $newIndexes ) === 1 ) {
96 $newIndex = $newIndexes[0];
100 $newIndex = substr( $row->el_index, 0, strpos( $row->el_index,
':' ) ) .
101 substr( $newIndexes[0], strpos( $newIndexes[0],
':' ) );
103 $dbw->update(
'externallinks',
105 'el_index' => $newIndex,
106 'el_index_60' => substr( $newIndex, 0, 60 ),
108 [
'el_id' => $row->el_id ],
113 $lbFactory->waitForReplication();
116 $this->
output(
"Done, $updated rows updated, $deleted deleted.\n" );