Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml reader: don't block attempt to read from stdin using wxr-importer import php://stdin #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public function import( $args, $assoc_args ) {
}
}

$path = realpath( $args[0] );
if ( ! $path ) {
WP_CLI::error( sprintf( 'Specified file %s does not exist', $args[0] ) );
}

$options = array(
'fetch_attachments' => true,
);
Expand All @@ -48,6 +43,12 @@ public function import( $args, $assoc_args ) {
WP_CLI::error( 'Invalid default author ID specified.' );
}
}

$path = realpath( $args[0] );
if ( ! $path ) {
$path = in_array( $args[0], array ( 'stdin', '-' ) ) ? 'php://stdin' : $args[0];
}

$importer = new WXR_Importer( $options );
$importer->set_logger( $logger );
$result = $importer->import( $path );
Expand Down
12 changes: 6 additions & 6 deletions class-wxr-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function get_reader( $file ) {
}

if ( ! $status ) {
return new WP_Error( 'wxr_importer.cannot_parse', __( 'Could not open the file for parsing', 'wordpress-importer' ) );
return new WP_Error( 'wxr_importer.cannot_parse', sprintf( __( 'Could not open the file for parsing', 'wordpress-importer' ), $file ) );
}

return $reader;
Expand Down Expand Up @@ -321,17 +321,17 @@ public function import( $file ) {
add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );

$result = $this->import_start( $file );
if ( is_wp_error( $result ) ) {
return $result;
}

// Let's run the actual importer now, woot
$reader = $this->get_reader( $file );
if ( is_wp_error( $reader ) ) {
return $reader;
}

$result = $this->import_start( $file );
if ( is_wp_error( $result ) ) {
return $result;
}

// Set the version to compatibility mode first
$this->version = '1.0';

Expand Down