44 $blockQuery = DatabaseBlock::getQueryInfo();
46 $max = $db->newSelectQueryBuilder()
47 ->select(
'MAX(ipb_user)' )
49 ->caller( __METHOD__ )
54 for ( $from = 1; $from <= $max; $from += $batchSize ) {
55 $to = min( $max, $from + $batchSize - 1 );
56 $this->
output(
"Cleaning up duplicate ipb_user ($from-$to of $max)\n" );
60 $res = $db->newSelectQueryBuilder()
61 ->select(
'ipb_user' )
64 'ipb_user >= ' . $from,
65 'ipb_user <= ' . (
int)$to,
67 ->groupBy(
'ipb_user' )
68 ->having(
'COUNT(*) > 1' )
69 ->caller( __METHOD__ )
71 foreach (
$res as $row ) {
73 $res2 = $db->newSelectQueryBuilder()
74 ->select( $blockQuery[
'fields'] )
75 ->tables( $blockQuery[
'tables'] )
77 'ipb_user' => $row->ipb_user,
79 ->joinConds( $blockQuery[
'joins'] )
80 ->caller( __METHOD__ )
82 foreach ( $res2 as $row2 ) {
83 $block = DatabaseBlock::newFromRow( $row2 );
91 if ( $keep ===
null && $block->getExpiry() !== $bestBlock->getExpiry() ) {
93 $keep = $block->getExpiry() > $bestBlock->getExpiry();
95 if ( $keep ===
null ) {
96 if ( $block->isCreateAccountBlocked() xor $bestBlock->isCreateAccountBlocked() ) {
97 $keep = $block->isCreateAccountBlocked();
98 } elseif ( $block->isEmailBlocked() xor $bestBlock->isEmailBlocked() ) {
99 $keep = $block->isEmailBlocked();
100 } elseif ( $block->isUsertalkEditAllowed() xor $bestBlock->isUsertalkEditAllowed() ) {
101 $keep = $block->isUsertalkEditAllowed();
106 $delete[] = $bestBlock->getId();
109 $delete[] = $block->getId();
117 [
'ipb_id' => $delete ],
124 for ( $from = 1; $from <= $max; $from += $batchSize ) {
125 $to = min( $max, $from + $batchSize - 1 );
126 $this->
output(
"Cleaning up mismatched user name ($from-$to of $max)\n" );
128 $res = $db->newSelectQueryBuilder()
129 ->select( [
'ipb_id',
'user_name' ] )
130 ->tables( [
'ipblocks',
'user' ] )
132 'ipb_user = user_id',
133 "ipb_user >= " . $from,
134 "ipb_user <= " . (
int)$to,
135 'ipb_address != user_name',
137 ->caller( __METHOD__ )
139 foreach (
$res as $row ) {
142 [
'ipb_address' => $row->user_name ],
143 [
'ipb_id' => $row->ipb_id ],
149 $this->
output(
"Done!\n" );