* the most recent version.
*/
public function allPages() {
- return $this->dumpFrom( '' );
+ $this->dumpFrom( '' );
}
/**
if ( $end ) {
$condition .= ' AND page_id < ' . intval( $end );
}
- return $this->dumpFrom( $condition );
+ $this->dumpFrom( $condition );
}
/**
if ( $end ) {
$condition .= ' AND rev_id < ' . intval( $end );
}
- return $this->dumpFrom( $condition );
+ $this->dumpFrom( $condition );
}
/**
* @param $title Title
*/
public function pageByTitle( $title ) {
- return $this->dumpFrom(
+ $this->dumpFrom(
'page_namespace=' . $title->getNamespace() .
' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
}
if ( is_null( $title ) ) {
throw new MWException( "Can't export invalid title" );
} else {
- return $this->pageByTitle( $title );
+ $this->pageByTitle( $title );
}
}
}
public function allLogs() {
- return $this->dumpFrom( '' );
+ $this->dumpFrom( '' );
}
public function logsByRange( $start, $end ) {
if ( $end ) {
$condition .= ' AND log_id < ' . intval( $end );
}
- return $this->dumpFrom( $condition );
+ $this->dumpFrom( $condition );
}
# Generates the distinct list of authors of an article
wfProfileIn( __METHOD__ );
# For logging dumps...
if ( $this->history & self::LOGS ) {
- if ( $this->buffer == WikiExporter::STREAM ) {
- $prev = $this->db->bufferResults( false );
- }
$where = array( 'user_id = log_user' );
# Hide private logs
$hideLogs = LogEventsList::getExcludeClause( $this->db );
if ( $cond ) $where[] = $cond;
# Get logging table name for logging.* clause
$logging = $this->db->tableName( 'logging' );
- $result = $this->db->select( array( 'logging', 'user' ),
- array( "{$logging}.*", 'user_name' ), // grab the user name
- $where,
- __METHOD__,
- array( 'ORDER BY' => 'log_id', 'USE INDEX' => array( 'logging' => 'PRIMARY' ) )
- );
- $wrapper = $this->db->resultObject( $result );
- $this->outputLogStream( $wrapper );
+
if ( $this->buffer == WikiExporter::STREAM ) {
- $this->db->bufferResults( $prev );
+ $prev = $this->db->bufferResults( false );
+ }
+ $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
+ try {
+ $result = $this->db->select( array( 'logging', 'user' ),
+ array( "{$logging}.*", 'user_name' ), // grab the user name
+ $where,
+ __METHOD__,
+ array( 'ORDER BY' => 'log_id', 'USE INDEX' => array( 'logging' => 'PRIMARY' ) )
+ );
+ $wrapper = $this->db->resultObject( $result );
+ $this->outputLogStream( $wrapper );
+ if ( $this->buffer == WikiExporter::STREAM ) {
+ $this->db->bufferResults( $prev );
+ }
+ } catch ( Exception $e ) {
+ // Throwing the exception does not reliably free the resultset, and
+ // would also leave the connection in unbuffered mode.
+
+ // Freeing result
+ try {
+ if ( $wrapper ) {
+ $wrapper->free();
+ }
+ } catch ( Exception $e2 ) {
+ // Already in panic mode -> ignoring $e2 as $e has
+ // higher priority
+ }
+
+ // Putting database back in previous buffer mode
+ try {
+ if ( $this->buffer == WikiExporter::STREAM ) {
+ $this->db->bufferResults( $prev );
+ }
+ } catch ( Exception $e2 ) {
+ // Already in panic mode -> ignoring $e2 as $e has
+ // higher priority
+ }
+
+ // Inform caller about problem
+ throw $e;
}
# For page dumps...
} else {
$prev = $this->db->bufferResults( false );
}
- wfRunHooks( 'ModifyExportQuery',
+ $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
+ try {
+ wfRunHooks( 'ModifyExportQuery',
array( $this->db, &$tables, &$cond, &$opts, &$join ) );
- # Do the query!
- $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
- $wrapper = $this->db->resultObject( $result );
- # Output dump results
- $this->outputPageStream( $wrapper );
+ # Do the query!
+ $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
+ $wrapper = $this->db->resultObject( $result );
+ # Output dump results
+ $this->outputPageStream( $wrapper );
- if ( $this->buffer == WikiExporter::STREAM ) {
- $this->db->bufferResults( $prev );
+ if ( $this->buffer == WikiExporter::STREAM ) {
+ $this->db->bufferResults( $prev );
+ }
+ } catch ( Exception $e ) {
+ // Throwing the exception does not reliably free the resultset, and
+ // would also leave the connection in unbuffered mode.
+
+ // Freeing result
+ try {
+ if ( $wrapper ) {
+ $wrapper->free();
+ }
+ } catch ( Exception $e2 ) {
+ // Already in panic mode -> ignoring $e2 as $e has
+ // higher priority
+ }
+
+ // Putting database back in previous buffer mode
+ try {
+ if ( $this->buffer == WikiExporter::STREAM ) {
+ $this->db->bufferResults( $prev );
+ }
+ } catch ( Exception $e2 ) {
+ // Already in panic mode -> ignoring $e2 as $e has
+ // higher priority
+ }
+
+ // Inform caller about problem
+ throw $e;
}
}
wfProfileOut( __METHOD__ );
* The result set should be sorted/grouped by page to avoid duplicate
* page records in the output.
*
- * The result set will be freed once complete. Should be safe for
+ * Should be safe for
* streaming (non-buffered) queries, as long as it was made on a
* separate database connection not managed by LoadBalancer; some
* blob storage types will make queries to pull source data.
* @ingroup Dump
*/
class DumpFileOutput extends DumpOutput {
- protected $handle, $filename;
+ protected $handle = false, $filename;
function __construct( $file ) {
$this->handle = fopen( $file, "wt" );
function writeCloseStream( $string ) {
parent::writeCloseStream( $string );
- fclose( $this->handle );
+ if ( $this->handle ) {
+ fclose( $this->handle );
+ $this->handle = false;
+ }
}
function write( $string ) {
function closeAndRename( $newname, $open = false ) {
$newname = $this->checkRenameArgCount( $newname );
if ( $newname ) {
- fclose( $this->handle );
+ if ( $this->handle ) {
+ fclose( $this->handle );
+ $this->handle = false;
+ }
$this->renameOrException( $newname );
if ( $open ) {
$this->handle = fopen( $this->filename, "wt" );
*/
class DumpPipeOutput extends DumpFileOutput {
protected $command, $filename;
+ protected $procOpenResource = false;
function __construct( $command, $file = null ) {
if ( !is_null( $file ) ) {
function writeCloseStream( $string ) {
parent::writeCloseStream( $string );
- proc_close( $this->procOpenResource );
+ if ( $this->procOpenResource ) {
+ proc_close( $this->procOpenResource );
+ $this->procOpenResource = false;
+ }
}
function startCommand( $command ) {
function closeAndRename( $newname, $open = false ) {
$newname = $this->checkRenameArgCount( $newname );
if ( $newname ) {
- fclose( $this->handle );
- proc_close( $this->procOpenResource );
+ if ( $this->handle ) {
+ fclose( $this->handle );
+ $this->handle = false;
+ }
+ if ( $this->procOpenResource ) {
+ proc_close( $this->procOpenResource );
+ $this->procOpenResource = false;
+ }
$this->renameOrException( $newname );
if ( $open ) {
$command = $this->command;