jenkins-bot has submitted this change and it was merged.

Change subject: Turn dumpBackup into proper Maintenance script
......................................................................


Turn dumpBackup into proper Maintenance script

Change-Id: Ib484f55ef349304a3279b85762b0ee0ac6c97b5d
---
M maintenance/dumpBackup.php
1 file changed, 98 insertions(+), 76 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/dumpBackup.php b/maintenance/dumpBackup.php
index cc55e27..d40dbed 100644
--- a/maintenance/dumpBackup.php
+++ b/maintenance/dumpBackup.php
@@ -4,24 +4,73 @@
 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 {
+       public function __construct( $args = null ) {
+               parent::__construct();
 
-class FlowBackupDumper extends BackupDumper {
-       function dump( $history, $text = Exporter::TEXT ) {
+               $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->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 n', false, true 
);
+               $this->addOption( 'end', 'Stop before page_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();
+               }
+       }
+
+       public 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();
+
+               if ( $this->hasOption( 'full' ) ) {
+                       $this->dump( WikiExporter::FULL );
+               } elseif ( $this->hasOption( 'current' ) ) {
+                       $this->dump( WikiExporter::CURRENT );
+               } elseif ( $this->hasOption( 'revrange' ) ) {
+                       $this->dump( WikiExporter::RANGE );
+               } else {
+                       $this->error( 'No valid action specified.', 1 );
+               }
+       }
+
+       /**
+        * @param int $history WikiExporter::FULL, WikiExporter::CURRENT or 
WikiExporter::RANGE
+        * @param int $text Unused, but exists for compat with parent
+        */
+       public function dump( $history, $text = WikiExporter::TEXT ) {
                # Notice messages will foul up your XML output even if they're
                # relatively harmless.
                if ( ini_get( 'display_errors' ) ) {
@@ -39,8 +88,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 ? $this->revStartId : null;
+               $revEndId = $history === WikiExporter::RANGE && $this->revEndId 
? $this->revEndId : null;
                $exporter->dump( $workflowIterator, $revStartId, $revEndId );
 
                if ( !$this->skipFooter ) {
@@ -49,70 +98,43 @@
 
                $this->report( true );
        }
-}
 
-$dumper = new FlowBackupDumper( $argv );
+       public 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 = UUID::create( $this->getOption( 
'revstart' ) );
+               }
+
+               if ( $this->hasOption( 'revend' ) ) {
+                       $this->revEndId = UUID::create( $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: merged
Gerrit-Change-Id: Ib484f55ef349304a3279b85762b0ee0ac6c97b5d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: ArielGlenn <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to