Skip to content

Commit

Permalink
Add re-entrancy semantics support
Browse files Browse the repository at this point in the history
  • Loading branch information
zaerl committed Nov 22, 2024
1 parent 92c830e commit fab4f2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
29 changes: 18 additions & 11 deletions packages/playground/data-liberation/src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,28 @@ function wp_visit_file_tree( $dir ) {
}

/**
* Import a WXR file. Used in the CLI.
* Import a WXR file. Used by the CLI.
*
* @param string $file The path to the WXR file.
* @param string $path The path to the WXR file.
* @return void
*/
function data_liberation_import( $file ) {
$entity_iterator_factory = function () use ( $file ) {
$wxr = new WP_WXR_Reader();
$wxr->connect_upstream( new WP_File_Reader( $file ) );
function data_liberation_import( $path ) {
$importer = WP_Stream_Importer::create_for_wxr_file( $path );
$is_wp_cli = defined( 'WP_CLI' ) && WP_CLI;

return $wxr;
};
if ( $is_wp_cli ) {
WP_CLI::line( "Importing from {$path}" );
}

$importer = WP_Stream_Importer::create( $entity_iterator_factory );
while ( $importer->next_step() ) {
// Output the current stage if running in WP-CLI.
if ( $is_wp_cli ) {
$current_stage = $importer->get_current_stage();
WP_CLI::line( "Import: stage {$current_stage}" );
}
}

$importer->frontload_assets();
$importer->import_entities();
if ( $is_wp_cli ) {
WP_CLI::success( 'Import ended' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ public function next_step() {
}
}

/**
* Get the current stage.
*
* @return string
*/
public function get_current_stage() {
return $this->stage;
}

/**
* Advance the cursor to the oldest finished download. For example:
*
Expand Down

0 comments on commit fab4f2f

Please sign in to comment.