Moved the bulk of dbsource() to Database.php. Added support for updating wikis with...
[lhc/web/wiklou.git] / maintenance / importDump.php
index 21894a6..a5a3c10 100644 (file)
@@ -45,6 +45,7 @@ class BackupReader {
        function handleRevision( $rev ) {
                $title = $rev->getTitle();
                if (!$title) {
+                       $this->progress( "Got bogus revision with null title!" );
                        return;
                }
                $display = $title->getPrefixedText();
@@ -88,12 +89,12 @@ class BackupReader {
                        $filename = 'compress.zlib://' . $filename;
                }
                $file = fopen( $filename, 'rt' );
-               $this->importFromHandle( $file );
+               return $this->importFromHandle( $file );
        }
 
        function importFromStdin() {
                $file = fopen( 'php://stdin', 'rt' );
-               $this->importFromHandle( $file );
+               return $this->importFromHandle( $file );
        }
 
        function importFromHandle( $handle ) {
@@ -106,10 +107,14 @@ class BackupReader {
                $this->importCallback =  $importer->setRevisionCallback(
                        array( &$this, 'handleRevision' ) );
 
-               $importer->doImport();
+               return $importer->doImport();
        }
 }
 
+if( wfReadOnly() ) {
+       wfDie( "Wiki is in read-only mode; you'll need to disable it for import to work.\n" );
+}
+
 $reader = new BackupReader();
 if( isset( $options['quiet'] ) ) {
        $reader->reporting = false;
@@ -122,9 +127,15 @@ if( isset( $options['dry-run'] ) ) {
 }
 
 if( isset( $args[0] ) ) {
-       $reader->importFromFile( $args[0] );
+       $result = $reader->importFromFile( $args[0] );
+} else {
+       $result = $reader->importFromStdin();
+}
+
+if( WikiError::isError( $result ) ) {
+       echo $result->getMessage() . "\n";
 } else {
-       $reader->importFromStdin();
+       echo "Done!\n";
 }
 
 ?>