* much older versions, etc.
* Run this, FOLLOWED BY update.php, for upgrading from 1.4.5 release to 1.5.
*
+ * 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
+ *
* @file
* @ingroup Maintenance
*/
* @ingroup Maintenance
*/
class FiveUpgrade extends Maintenance {
+
+ /**
+ * @var DatabaseBase
+ */
+ protected $db;
+
function __construct() {
parent::__construct();
$this->cleanupSwaps = array();
$this->emailAuth = false; # don't preauthenticate emails
- $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait
$this->step = $this->getOption( 'step', null );
}
/**
* Open a connection to the master server with the admin rights.
- * @return Database
+ * @return DatabaseBase
* @access private
*/
function newConnection() {
$lb = wfGetLBFactory()->newMainLB();
$db = $lb->getConnection( DB_MASTER );
-
+
$this->loadBalancers[] = $lb;
return $db;
}
-
+
/**
* Commit transactions and close the connections when we're done...
*/
* Open a second connection to the master server, with buffering off.
* This will let us stream large datasets in and write in chunks on the
* other end.
- * @return Database
+ * @return DatabaseBase
* @access private
*/
function streamConnection() {
- global $wgDBtype;
-
$timeout = 3600 * 24;
$db = $this->newConnection();
$db->bufferResults( false );
- if ( $wgDBtype == 'mysql' ) {
+ if ( $db->getType() == 'mysql' ) {
$db->query( "SET net_read_timeout=$timeout" );
$db->query( "SET net_write_timeout=$timeout" );
}
*/
function insertChunk( &$chunk ) {
// Give slaves a chance to catch up
- wfWaitForSlaves( $this->maxLag );
+ wfWaitForSlaves();
$this->dbw->insert( $this->chunkTable, $chunk, $this->chunkFunction, $this->chunkOptions );
}
+ /**
+ * Helper function for copyTable array_filter
+ * @param $x
+ * @return bool
+ */
+ static private function notUpgradeNull( $x ) {
+ return $x !== MW_UPGRADE_NULL;
+ }
/**
* Copy and transcode a table to table_temp.
* MW_UPGRADE_COPY - straight copy
* MW_UPGRADE_ENCODE - for old Latin1 wikis, conv to UTF-8
* MW_UPGRADE_NULL - just put NULL
- * @param callable $callback An optional callback to modify the data
+ * @param $callback callback An optional callback to modify the data
* or perform other processing. Func should be
* ( object $row, array $copy ) and return $copy
* @access private
$this->setChunkScale( 100, $numRecords, $name_temp, __METHOD__ );
// Pull all records from the second, streaming database connection.
- $sourceFields = array_keys( array_filter( $fields,
- create_function( '$x', 'return $x !== MW_UPGRADE_NULL;' ) ) );
+ $sourceFields = array_keys( array_filter( $fields, 'FiveUpgrade::notUpgradeNull' ) );
$result = $this->dbr->select( $name,
$sourceFields,
'',
$this->log( "Creating page and revision tables..." );
$this->dbw->query( "CREATE TABLE $page (
- page_id int(8) unsigned NOT NULL auto_increment,
- page_namespace int NOT NULL,
- page_title varchar(255) binary NOT NULL,
- page_restrictions tinyblob NOT NULL default '',
- page_counter bigint(20) unsigned NOT NULL default '0',
- page_is_redirect tinyint(1) unsigned NOT NULL default '0',
- page_is_new tinyint(1) unsigned NOT NULL default '0',
- page_random real unsigned NOT NULL,
- page_touched char(14) binary NOT NULL default '',
- page_latest int(8) unsigned NOT NULL,
- page_len int(8) unsigned NOT NULL,
-
- PRIMARY KEY page_id (page_id),
- UNIQUE INDEX name_title (page_namespace,page_title),
- INDEX (page_random),
- INDEX (page_len)
+ page_id int(8) unsigned NOT NULL auto_increment,
+ page_namespace int NOT NULL,
+ page_title varchar(255) binary NOT NULL,
+ page_restrictions tinyblob NOT NULL default '',
+ page_counter bigint(20) unsigned NOT NULL default '0',
+ page_is_redirect tinyint(1) unsigned NOT NULL default '0',
+ page_is_new tinyint(1) unsigned NOT NULL default '0',
+ page_random real unsigned NOT NULL,
+ page_touched char(14) binary NOT NULL default '',
+ page_latest int(8) unsigned NOT NULL,
+ page_len int(8) unsigned NOT NULL,
+
+ PRIMARY KEY page_id (page_id),
+ UNIQUE INDEX name_title (page_namespace,page_title),
+ INDEX (page_random),
+ INDEX (page_len)
) TYPE=InnoDB", __METHOD__ );
$this->dbw->query( "CREATE TABLE $revision (
- rev_id int(8) unsigned NOT NULL auto_increment,
- rev_page int(8) unsigned NOT NULL,
- rev_text_id int(8) unsigned NOT NULL,
- rev_comment tinyblob NOT NULL default '',
- rev_user int(5) unsigned NOT NULL default '0',
- rev_user_text varchar(255) binary NOT NULL default '',
- rev_timestamp char(14) binary NOT NULL default '',
- rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
+ rev_id int(8) unsigned NOT NULL auto_increment,
+ rev_page int(8) unsigned NOT NULL,
+ rev_text_id int(8) unsigned NOT NULL,
+ rev_comment tinyblob NOT NULL default '',
+ rev_user int(5) unsigned NOT NULL default '0',
+ rev_user_text varchar(255) binary NOT NULL default '',
+ rev_timestamp char(14) binary NOT NULL default '',
+ rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
rev_deleted tinyint(1) unsigned NOT NULL default '0',
- PRIMARY KEY rev_page_id (rev_page, rev_id),
- UNIQUE INDEX rev_id (rev_id),
- INDEX rev_timestamp (rev_timestamp),
- INDEX page_timestamp (rev_page,rev_timestamp),
- INDEX user_timestamp (rev_user,rev_timestamp),
- INDEX usertext_timestamp (rev_user_text,rev_timestamp)
+ PRIMARY KEY rev_page_id (rev_page, rev_id),
+ UNIQUE INDEX rev_id (rev_id),
+ INDEX rev_timestamp (rev_timestamp),
+ INDEX page_timestamp (rev_page,rev_timestamp),
+ INDEX user_timestamp (rev_user,rev_timestamp),
+ INDEX usertext_timestamp (rev_user_text,rev_timestamp)
) TYPE=InnoDB", __METHOD__ );
$maxold = intval( $this->dbw->selectField( 'old', 'max(old_id)', '', __METHOD__ ) );
$result = $this->dbr->query(
"SELECT cur_id, cur_namespace, cur_title, $cur_text AS text, cur_comment,
cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags AS flags
- FROM $cur
- ORDER BY cur_id", __METHOD__ );
- $add = array();
+ FROM $cur
+ ORDER BY cur_id", __METHOD__ );
+ $add = array();
foreach ( $result as $row ) {
$add[] = array(
'old_namespace' => $row->cur_namespace,
$this->setChunkScale( $chunksize, $maxcur, 'page', __METHOD__ );
$result = $this->dbr->query( "
SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
- cur_random, cur_touched, rev_id, LENGTH(cur_text) AS len
- FROM $cur,$revision
- WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}
- ORDER BY cur_id", __METHOD__ );
+ cur_random, cur_touched, rev_id, LENGTH(cur_text) AS len
+ FROM $cur,$revision
+ WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}
+ ORDER BY cur_id", __METHOD__ );
$add = array();
foreach ( $result as $row ) {
$add[] = array(
$this->log( 'Done with links.' );
}
+ function userDupeCallback( $str ) {
+ echo $str;
+ }
+
function upgradeUser() {
// Apply unique index, if necessary:
- $duper = new UserDupes( $this->dbw );
+ $duper = new UserDupes( $this->dbw, array( $this, 'userDupeCallback' ) );
if ( $duper->hasUniqueIndex() ) {
$this->log( "Already have unique user_name index." );
} else {
* Rename a given image or archived image file to the converted filename,
* leaving a symlink for URL compatibility.
*
- * @param string $oldname pre-conversion filename
- * @param string $basename pre-conversion base filename for dir hashing, if an archive
+ * @param $oldname string pre-conversion filename
+ * @param $subdirCallback string
+ * @param $basename string pre-conversion base filename for dir hashing, if an archive
+ * @return bool|string
* @access private
*/
function renameFile( $oldname, $subdirCallback = 'wfImageDir', $basename = null ) {
$dbw->query( <<<END
INSERT
INTO $old
- (old_namespace, old_title, old_text,
- old_comment, old_user, old_user_text,
- old_timestamp, old_minor_edit, old_flags,
- inverse_timestamp)
+ (old_namespace, old_title, old_text,
+ old_comment, old_user, old_user_text,
+ old_timestamp, old_minor_edit, old_flags,
+ inverse_timestamp)
SELECT cur_namespace, cur_title, cur_text,
- cur_comment, cur_user, cur_user_text,
- cur_timestamp, cur_minor_edit, '',
- inverse_timestamp
+ cur_comment, cur_user, cur_user_text,
+ cur_timestamp, cur_minor_edit, '',
+ inverse_timestamp
FROM $cur
WHERE cur_namespace=$ns
AND cur_title=$title
}
$maintClass = 'FiveUpgrade';
-require( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );