Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/275519
Change subject: Turn dumpBackup into proper Maintenance script
......................................................................
Turn dumpBackup into proper Maintenance script
Change-Id: Ib484f55ef349304a3279b85762b0ee0ac6c97b5d
---
M maintenance/dumpBackup.php
1 file changed, 96 insertions(+), 75 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/19/275519/1
diff --git a/maintenance/dumpBackup.php b/maintenance/dumpBackup.php
index cc55e27..496df2c 100644
--- a/maintenance/dumpBackup.php
+++ b/maintenance/dumpBackup.php
@@ -4,23 +4,71 @@
use Flow\Dump\Exporter;
use Flow\Model\UUID;
-$originalDir = getcwd();
-
-$optionsWithArgs = array( 'pagelist', 'start', 'end', 'revstart', 'revend' );
-
$maintPath = ( getenv( 'MW_INSTALL_PATH' ) !== false
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance'
: dirname( __FILE__ ) . '/../../../maintenance' );
-require_once $maintPath . '/commandLine.inc';
+require_once $maintPath . '/Maintenance.php';
require_once $maintPath . '/backup.inc';
-// Stop if Flow not enabled on the wiki
-if ( !class_exists( 'FlowHooks' ) ) {
- echo "Flow isn't enabled on this wiki.\n";
- die( 1 );
-}
+class FlowDumpBackup extends BackupDumper {
+ function __construct( $args = null ) {
+ parent::__construct();
-class FlowBackupDumper extends BackupDumper {
+ $this->addDescription( <<<TEXT
+This script dumps the Flow discussion database into an
+XML interchange wrapper format for export.
+
+It can either export only the current revision, or full history.
+
+Although the --full will export all public revisions, non-public revisions
+are removed, and the remaining revisions are renormalized to accomodate this.
+It is recommended that you keep database backups as well.
+
+XML output is sent to stdout; progress reports are sent to stderr.
+TEXT
+ );
+ $this->stderr = fopen( "php://stderr", "wt" );
+
+ $this->addOption( 'full', 'Dump all revisions of every
description/post/summary' );
+ $this->addOption( 'current', 'Dump only the latest revision of
every description/post/summary' );
+ $this->addOption( 'revrange', 'Dump range of revisions
specified by revstart and revend parameters' );
+ $this->addOption( 'pagelist', 'Dump only pages of which the
title is included in the file', false, true );
+
+ $this->addOption( 'start', 'Start from page_id or log_id n',
false, true );
+ $this->addOption( 'end', 'Stop before page_id or log_id n
(exclusive)', false, true );
+ $this->addOption( 'revstart', 'Start from rev_id n', false,
true );
+ $this->addOption( 'revend', 'Stop before rev_id n (exclusive)',
false, true );
+ $this->addOption( 'skip-header', 'Don\'t output the <mediawiki>
header' );
+ $this->addOption( 'skip-footer', 'Don\'t output the
</mediawiki> footer' );
+
+ if ( $args ) {
+ $this->loadWithArgv( $args );
+ $this->processOptions();
+ }
+ }
+
+ function execute() {
+ // Stop if Flow not enabled on the wiki
+ if ( !class_exists( 'FlowHooks' ) ) {
+ echo "Flow isn't enabled on this wiki.\n";
+ die( 1 );
+ }
+
+ $this->processOptions();
+
+ $textMode = $this->hasOption( 'stub' ) ? WikiExporter::STUB :
WikiExporter::TEXT;
+
+ if ( $this->hasOption( 'full' ) ) {
+ $this->dump( WikiExporter::FULL, $textMode );
+ } elseif ( $this->hasOption( 'current' ) ) {
+ $this->dump( WikiExporter::CURRENT, $textMode );
+ } elseif ( $this->hasOption( 'revrange' ) ) {
+ $this->dump( WikiExporter::RANGE, $textMode );
+ } else {
+ $this->error( 'No valid action specified.', 1 );
+ }
+ }
+
function dump( $history, $text = Exporter::TEXT ) {
# Notice messages will foul up your XML output even if they're
# relatively harmless.
@@ -39,8 +87,8 @@
$workflowIterator = $exporter->getWorkflowIterator(
$this->pages, $this->startId, $this->endId );
- $revStartId = $this->revStartId ? UUID::create(
$this->revStartId ) : null;
- $revEndId = $this->revEndId ? UUID::create( $this->revEndId ) :
null;
+ $revStartId = $history === WikiExporter::RANGE &&
$this->revStartId ? UUID::create( $this->revStartId ) : null;
+ $revEndId = $history === WikiExporter::RANGE && $this->revEndId
? UUID::create( $this->revEndId ) : null;
$exporter->dump( $workflowIterator, $revStartId, $revEndId );
if ( !$this->skipFooter ) {
@@ -49,70 +97,43 @@
$this->report( true );
}
-}
-$dumper = new FlowBackupDumper( $argv );
+ function processOptions() {
+ parent::processOptions();
-if ( isset( $options['pagelist'] ) ) {
- $olddir = getcwd();
- chdir( $originalDir );
- $pages = file( $options['pagelist'] );
- chdir( $olddir );
- if ( $pages === false ) {
- echo "Unable to open file {$options['pagelist']}\n";
- die( 1 );
+ // Evaluate options specific to this class
+ $this->reporting = !$this->hasOption( 'quiet' );
+
+ if ( $this->hasOption( 'pagelist' ) ) {
+ $filename = $this->getOption( 'pagelist' );
+ $pages = file( $filename );
+ if ( $pages === false ) {
+ $this->fatalError( "Unable to open file
{$filename}\n" );
+ }
+ $pages = array_map( 'trim', $pages );
+ $this->pages = array_filter( $pages, create_function(
'$x', 'return $x !== "";' ) );
+ }
+
+ if ( $this->hasOption( 'start' ) ) {
+ $this->startId = intval( $this->getOption( 'start' ) );
+ }
+
+ if ( $this->hasOption( 'end' ) ) {
+ $this->endId = intval( $this->getOption( 'end' ) );
+ }
+
+ if ( $this->hasOption( 'revstart' ) ) {
+ $this->revStartId = intval( $this->getOption(
'revstart' ) );
+ }
+
+ if ( $this->hasOption( 'revend' ) ) {
+ $this->revEndId = intval( $this->getOption( 'revend' )
);
+ }
+
+ $this->skipHeader = $this->hasOption( 'skip-header' );
+ $this->skipFooter = $this->hasOption( 'skip-footer' );
}
- $pages = array_map( 'trim', $pages );
- $dumper->pages = array_filter( $pages, create_function( '$x', 'return
$x !== "";' ) );
}
-if ( isset( $options['start'] ) ) {
- $dumper->startId = intval( $options['start'] );
-}
-if ( isset( $options['end'] ) ) {
- $dumper->endId = intval( $options['end'] );
-}
-
-if ( isset( $options['revstart'] ) ) {
- $dumper->revStartId = intval( $options['revstart'] );
-}
-if ( isset( $options['revend'] ) ) {
- $dumper->revEndId = intval( $options['revend'] );
-}
-$dumper->skipHeader = isset( $options['skip-header'] );
-$dumper->skipFooter = isset( $options['skip-footer'] );
-
-if ( isset( $options['full'] ) ) {
- $dumper->dump( WikiExporter::FULL );
-} elseif ( isset( $options['current'] ) ) {
- $dumper->dump( WikiExporter::CURRENT );
-} else {
- $dumper->progress( <<<ENDS
-This script dumps the Flow discussion database into an
-XML interchange wrapper format for export.
-
-It can either export only the current revision, or full history.
-
-Although the --full will export all public revisions, non-public revisions
-are removed, and the remaining revisions are renormalized to accomodate this.
-It is recommended that you keep database backups as well.
-
-XML output is sent to stdout; progress reports are sent to stderr.
-
-Usage: php dumpBackup.php <action> [<options>]
-Actions:
- --full Dump all revisions of every description/post/summary.
- --current Dump only the latest revision of every description/post/summary.
- --pagelist=<file>
- Where <file> is a list of page titles to be dumped
-Options:
- --start=n Start from page_id or log_id n
- --end=n Stop before page_id or log_id n (exclusive)
- --revstart=n Start from rev_id n
- --revend=n Stop before rev_id n (exclusive)
- --skip-header Don't output the <mediawiki> header
- --skip-footer Don't output the </mediawiki> footer
-
-ENDS
- );
-}
+$maintClass = 'FlowDumpBackup';
+require_once RUN_MAINTENANCE_IF_MAIN;
--
To view, visit https://gerrit.wikimedia.org/r/275519
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib484f55ef349304a3279b85762b0ee0ac6c97b5d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits