53 if ( !$dbw->tableExists(
'externallinks', __METHOD__ ) ) {
54 $this->
error(
"externallinks table does not exist" );
57 $this->
output(
"Updating externallinks table index fields\n" );
59 $minmax = $dbw->selectRow(
61 [
'min' =>
'MIN(el_id)',
'max' =>
'MAX(el_id)' ],
68 $start = $minmax->min - 1;
69 $last = (int)$minmax->max;
70 while ( $start < $last ) {
71 $end = min( $start + $this->mBatchSize, $last );
72 $this->
output(
"el_id $start - $end of $last\n" );
73 $res = $dbw->select(
'externallinks', [
'el_id',
'el_to',
'el_index' ],
79 [
'ORDER BY' =>
'el_id' ]
81 foreach (
$res as $row ) {
82 $newIndexes = LinkFilter::makeIndexes( $row->el_to );
84 $dbw->delete(
'externallinks', [
'el_id' => $row->el_id ], __METHOD__ );
89 foreach ( $newIndexes as $newIndex ) {
90 $newIndexes2[] = implode(
'', $newIndex );
92 if ( in_array( $row->el_index, $newIndexes2,
true ) ) {
96 if ( count( $newIndexes2 ) === 1 ) {
97 $newIndex = $newIndexes2[0];
101 $newIndex = substr( $row->el_index, 0, strpos( $row->el_index,
':' ) ) .
102 substr( $newIndexes2[0], strpos( $newIndexes2[0],
':' ) );
104 $dbw->update(
'externallinks',
106 'el_index' => $newIndex,
107 'el_index_60' => substr( $newIndex, 0, 60 ),
109 [
'el_id' => $row->el_id ],
117 $this->
output(
"Done, $updated rows updated, $deleted deleted.\n" );