From: Alexandre Emsenhuber Date: Fri, 10 Sep 2010 17:34:06 +0000 (+0000) Subject: Copied cleanupDupes.inc in FiveUpgrade.inc since it's only used there X-Git-Tag: 1.31.0-rc.0~35054 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dcompta/operations/modifier.php?a=commitdiff_plain;h=a86d87325442fb122654fb97e6dbbe3fcc528c23;p=lhc%2Fweb%2Fwiklou.git Copied cleanupDupes.inc in FiveUpgrade.inc since it's only used there --- diff --git a/maintenance/FiveUpgrade.inc b/maintenance/FiveUpgrade.inc index 6723bd9f5d..fda34b9b1f 100644 --- a/maintenance/FiveUpgrade.inc +++ b/maintenance/FiveUpgrade.inc @@ -4,7 +4,6 @@ * @ingroup Maintenance */ -require_once( 'cleanupDupes.inc' ); require_once( 'updaters.inc' ); define( 'MW_UPGRADE_COPY', false ); @@ -350,7 +349,7 @@ class FiveUpgrade { } $this->log( "Checking cur table for unique title index and applying if necessary" ); - checkDupes( true ); + $this->checkDupes(); $this->log( "...converting from cur/old to page/revision/text DB structure." ); @@ -1155,6 +1154,101 @@ ENDS; $this->copyTable( 'querycache', $tabledef, $fields ); } + /** + * Check for duplicate rows in "cur" table and move duplicates entries in + * "old" table. + * + * This was in cleanupDupes.inc before. + */ + function checkDupes() { + $dbw = wfGetDB( DB_MASTER ); + if ( $dbw->indexExists( 'cur', 'name_title' ) && + $dbw->indexUnique( 'cur', 'name_title' ) ) { + echo wfWikiID() . ": cur table has the current unique index; no duplicate entries.\n"; + return; + } elseif ( $dbw->indexExists( 'cur', 'name_title_dup_prevention' ) ) { + echo wfWikiID() . ": cur table has a temporary name_title_dup_prevention unique index; no duplicate entries.\n"; + return; + } + + echo wfWikiID() . ": cur table has the old non-unique index and may have duplicate entries.\n"; + + $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 ) { + echo "Correcting...\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"; + } + } + } + + $dbw->query( <<query( <<query( 'UNLOCK TABLES' ); + echo "Done.\n"; + } + /** * Rename all our temporary tables into final place. * We've left things in place so a read-only wiki can continue running diff --git a/maintenance/cleanupDupes.inc b/maintenance/cleanupDupes.inc deleted file mode 100644 index 4ce5052542..0000000000 --- a/maintenance/cleanupDupes.inc +++ /dev/null @@ -1,128 +0,0 @@ - -# 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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... - * - * @file - * @ingroup 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 ) { - $dbw = wfGetDB( DB_MASTER ); - if ( $dbw->indexExists( 'cur', 'name_title' ) && - $dbw->indexUnique( 'cur', 'name_title' ) ) { - echo wfWikiID() . ": cur table has the current unique index; no duplicate entries.\n"; - } elseif ( $dbw->indexExists( 'cur', 'name_title_dup_prevention' ) ) { - echo wfWikiID() . ": cur table has a temporary name_title_dup_prevention unique index; no duplicate entries.\n"; - } else { - echo wfWikiID() . ": cur table has the old non-unique index and may have duplicate entries.\n"; - if ( !$indexonly ) { - fixDupes( $fixthem ); - } - } -}