From f02fffe8e57c7326492925d2524c4825d2b9d10d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 23 Jun 2005 20:06:35 +0000 Subject: [PATCH] Copy updates from REL1_4, break out function definition to an include file so it can be used from the updgrade script. --- maintenance/cleanupDupes.inc | 131 +++++++++++++++++++++++++++++++++++ maintenance/cleanupDupes.php | 66 ++---------------- 2 files changed, 136 insertions(+), 61 deletions(-) create mode 100644 maintenance/cleanupDupes.inc diff --git a/maintenance/cleanupDupes.inc b/maintenance/cleanupDupes.inc new file mode 100644 index 0000000000..12c296fe55 --- /dev/null +++ b/maintenance/cleanupDupes.inc @@ -0,0 +1,131 @@ + +# http://www.mediawiki.org/ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# http://www.gnu.org/copyleft/gpl.html + +/** + * If on the old non-unique indexes, check the cur table for duplicate + * entries and remove them... + * + * @package MediaWiki + * @subpackage Maintenance + */ + +function fixDupes( $fixthem = false) { + $dbw =& wfGetDB( DB_MASTER ); + $cur = $dbw->tableName( 'cur' ); + $old = $dbw->tableName( 'old' ); + $dbw->query( "LOCK TABLES $cur WRITE, $old WRITE" ); + echo "Checking for duplicate cur table entries... (this may take a while on a large wiki)\n"; + $res = $dbw->query( << 1 +END + ); + $n = $dbw->numRows( $res ); + echo "Found $n titles with duplicate entries.\n"; + if( $n > 0 ) { + if( $fixthem ) { + echo "Correcting...\n"; + } else { + echo "Just a demo...\n"; + } + while( $row = $dbw->fetchObject( $res ) ) { + $ns = IntVal( $row->cur_namespace ); + $title = $dbw->addQuotes( $row->cur_title ); + + # Get the first responding ID; that'll be the one we keep. + $id = $dbw->selectField( 'cur', 'cur_id', array( + 'cur_namespace' => $row->cur_namespace, + 'cur_title' => $row->cur_title ) ); + + echo "$ns:$row->cur_title (canonical ID $id)\n"; + if( $id != $row->id ) { + echo " ** minimum ID $row->id; "; + $timeMin = $dbw->selectField( 'cur', 'cur_timestamp', array( + 'cur_id' => $row->id ) ); + $timeFirst = $dbw->selectField( 'cur', 'cur_timestamp', array( + 'cur_id' => $id ) ); + if( $timeMin == $timeFirst ) { + echo "timestamps match at $timeFirst; ok\n"; + } else { + echo "timestamps don't match! min: $timeMin, first: $timeFirst; "; + if( $timeMin > $timeFirst ) { + $id = $row->id; + echo "keeping minimum: $id\n"; + } else { + echo "keeping first: $id\n"; + } + } + } + + if( $fixthem ) { + $dbw->query( <<query( <<query( 'UNLOCK TABLES' ); + if( $fixthem ) { + echo "Done.\n"; + } else { + echo "Run again with --fix option to delete the duplicates.\n"; + } +} + +function checkDupes( $fixthem = false, $indexonly = false ) { + global $wgDBname; + $dbw =& wfGetDB( DB_MASTER ); + if( $dbw->indexExists( 'cur', 'name_title' ) && + $dbw->indexUnique( 'cur', 'name_title' ) ) { + echo "$wgDBname: cur table has the current unique index; no duplicate entries.\n"; + } elseif( $dbw->indexExists( 'cur', 'name_title_dup_prevention' ) ) { + echo "$wgDBname: cur table has a temporary name_title_dup_prevention unique index; no duplicate entries.\n"; + } else { + echo "$wgDBname: cur table has the old non-unique index and may have duplicate entries.\n"; + if( !$indexonly ) { + fixDupes( $fixthem ); + } + } +} + +?> \ No newline at end of file diff --git a/maintenance/cleanupDupes.php b/maintenance/cleanupDupes.php index f75ea92415..ed2e472b14 100644 --- a/maintenance/cleanupDupes.php +++ b/maintenance/cleanupDupes.php @@ -21,72 +21,16 @@ * If on the old non-unique indexes, check the cur table for duplicate * entries and remove them... * - * @author * @package MediaWiki * @subpackage Maintenance */ -$options = array( 'fix' ); +$options = array( 'fix', 'index' ); -/** */ -require_once( 'commandLine.inc' ); -$wgTitle = Title::newFromText( 'Dupe cur entry cleanup script' ); +require_once( "commandLine.inc" ); +require_once( 'cleanupDupes.inc' ); +$wgTitle = Title::newFromText( "Dupe cur entry cleanup script" ); -checkDupes( isset( $options['fix'] ) ); +checkDupes( isset( $options['fix'] ), isset( $options['index'] ) ); -function fixDupes( $fixthem = false) { - $dbw =& wfGetDB( DB_MASTER ); - $cur = $dbw->tableName( 'cur' ); - $dbw->query( "LOCK TABLES $cur WRITE" ); - echo "Checking for duplicate cur table entries... (this may take a while on a large wiki)\n"; - $res = $dbw->query( << 1 -END - ); - $n = $dbw->numRows( $res ); - echo "Found $n titles with duplicate entries.\n"; - if( $n > 0 ) { - if( $fixthem ) { - echo "Correcting...\n"; - } else { - echo "Just a demo...\n"; - } - while( $row = $dbw->fetchObject( $res ) ) { - $ns = IntVal( $row->cur_namespace ); - $title = $dbw->addQuotes( $row->cur_title ); - $id = IntVal( $row->id ); - echo "$ns:$row->cur_title (canonical ID $id)\n"; - if( $fixthem ) { - $dbw->query( <<$id -END - ); - } - } - } - $dbw->query( 'UNLOCK TABLES' ); - if( $fixthem ) { - echo "Done.\n"; - } else { - echo "Run again with --fix option to delete the duplicates.\n"; - } -} - -function checkDupes( $fixthem = false ) { - $dbw =& wfGetDB( DB_MASTER ); - if( $dbw->indexExists( 'cur', 'name_title' ) && - $dbw->indexUnique( 'cur', 'name_title' ) ) { - echo "Your cur table has the current unique index; no duplicate entries.\n"; - } else { - echo "Your cur table has the old non-unique index and may have duplicate entries.\n"; - fixDupes( $fixthem ); - } -} ?> \ No newline at end of file -- 2.20.1