From 0b98b0489dd3ff2477e70051f07953427a38c37f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 11 Oct 2004 07:44:37 +0000 Subject: [PATCH] If wiki has the old non-unique indexes on cur, check for duplicate cur entries and remove the extras. --- maintenance/cleanupDupes.php | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 maintenance/cleanupDupes.php diff --git a/maintenance/cleanupDupes.php b/maintenance/cleanupDupes.php new file mode 100644 index 0000000000..af85e7b4aa --- /dev/null +++ b/maintenance/cleanupDupes.php @@ -0,0 +1,79 @@ + +# 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 + */ + +require_once( "commandLine.inc" ); +require_once( "rebuildtextindex.inc" ); +$wgTitle = Title::newFromText( "Rebuild text index script" ); + +checkDupes(); + +function fixDupes() { + $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 ) { + echo "Correcting...\n"; + while( $row = $dbw->fetchObject( $res ) ) { + $ns = IntVal( $row->cur_namespace ); + $title = $dbw->addQuotes( $row->cur_title ); + $id = IntVal( $row->id ); + $dbw->query( <<query( 'UNLOCK TABLES' ); + echo "Done.\n"; +} + +function checkDupes() { + $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(); + } +} + +?> \ No newline at end of file -- 2.20.1