diff --git a/packages/playground/data-liberation/bootstrap.php b/packages/playground/data-liberation/bootstrap.php index 8b5910c217..6dbe09c7be 100644 --- a/packages/playground/data-liberation/bootstrap.php +++ b/packages/playground/data-liberation/bootstrap.php @@ -10,6 +10,10 @@ require_once __DIR__ . '/blueprints-library/src/WordPress/AsyncHttp/HttpError.php'; require_once __DIR__ . '/blueprints-library/src/WordPress/AsyncHttp/Connection.php'; require_once __DIR__ . '/blueprints-library/src/WordPress/AsyncHttp/Client.php'; +require_once __DIR__ . '/blueprints-library/src/WordPress/Zip/ZipStreamWriter.php'; +require_once __DIR__ . '/blueprints-library/src/WordPress/Zip/ZipFileEntry.php'; +require_once __DIR__ . '/blueprints-library/src/WordPress/Zip/ZipCentralDirectoryEntry.php'; +require_once __DIR__ . '/blueprints-library/src/WordPress/Zip/ZipEndCentralDirectoryEntry.php'; require_once __DIR__ . '/src/byte-readers/WP_Byte_Reader.php'; require_once __DIR__ . '/src/byte-readers/WP_File_Reader.php'; @@ -64,6 +68,7 @@ require_once __DIR__ . '/src/import/WP_Entity_Iterator_Chain.php'; require_once __DIR__ . '/src/import/WP_Retry_Frontloading_Iterator.php'; require_once __DIR__ . '/src/import/WP_Markdown_Importer.php'; +require_once __DIR__ . '/src/export/WP_Exporter.php'; require_once __DIR__ . '/src/utf8_decoder.php'; diff --git a/packages/playground/data-liberation/plugin.php b/packages/playground/data-liberation/plugin.php index f17704ebcc..5aeed6cbd2 100644 --- a/packages/playground/data-liberation/plugin.php +++ b/packages/playground/data-liberation/plugin.php @@ -657,3 +657,15 @@ function () { ); } ); + +add_action('wp_loaded', 'data_liberation_maybe_test_export'); +function data_liberation_maybe_test_export() { + $request_path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); + if( $request_path !== '/_data_liberation_test_export' ) { + return; + } + + $exporter = new WP_Exporter(); + $exporter->stream_export(); + die(); +} \ No newline at end of file diff --git a/packages/playground/data-liberation/src/export/WP_Exporter.php b/packages/playground/data-liberation/src/export/WP_Exporter.php new file mode 100644 index 0000000000..d751830098 --- /dev/null +++ b/packages/playground/data-liberation/src/export/WP_Exporter.php @@ -0,0 +1,72 @@ +writeFileFromString( 'META-INF/export.wxr', $wxr_content ); + + $uploads_path = $uploads['basedir']; + + $flags = \FilesystemIterator::SKIP_DOTS; + $uploads_iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator( + $uploads_path, + $flags + ) + ); + + foreach ( $uploads_iterator as $file ) { + if ( $file->isDir() ) { + continue; + } + $absolute_path = $file->getPathname(); + $relative_path = substr( $absolute_path, strlen($uploads_path) + 1 ); + $zip_writer->writeFileFromPath( + // TODO: How to handle unconventional upload locations? + "wp-content/uploads/$relative_path", + $absolute_path + ); + + // TODO: Is this necessary to make sure per-file output is flushed? + fflush( $output_stream ); + } + + $zip_writer->finish(); + } +} \ No newline at end of file