-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Data Liberation] Add WXR import CLI script (#2012)
- Loading branch information
Showing
12 changed files
with
175 additions
and
47 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/playground/data-liberation/bin/import/blueprint-import-wxr.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"$schema": "../../../blueprints/public/blueprint-schema.json", | ||
"constants": { | ||
"WP_DEBUG": true, | ||
"WP_DEBUG_LOG": true | ||
}, | ||
"login": true, | ||
"steps": [ | ||
{ | ||
"step": "activatePlugin", | ||
"pluginPath": "data-liberation/plugin.php" | ||
}, | ||
{ | ||
"step": "runPHP", | ||
"code": "<?php require_once 'wordpress/wp-load.php';\n$upload_dir = wp_upload_dir();\nforeach ( wp_visit_file_tree( $upload_dir['basedir'] . '/import-wxr' ) as $event ) {\nforeach ( $event->files as $file ) {\nif ( $file->isFile() && pathinfo( $file->getPathname(), PATHINFO_EXTENSION ) === 'xml' ) {\ndata_liberation_import( $file->getPathname() );\n}\n}\n};" | ||
} | ||
] | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/playground/data-liberation/bin/import/import-wxr.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
# | ||
# A script that accepts a folder and imports all WXR files into a WordPress site | ||
# | ||
# Usage: | ||
# ./import-wxr.sh <folder-name> | ||
# | ||
|
||
# Display help message | ||
show_help() { | ||
echo "Usage: $0 [-h|--help] <folder-name>" | ||
echo "Options:" | ||
echo " -h, --help Show this help message" | ||
} | ||
|
||
# Check if no arguments were provided. If so, display help message | ||
if [ $# -eq 0 ]; then | ||
show_help | ||
exit 1 | ||
fi | ||
|
||
# Parse command line arguments. If an invalid argument is provided, display help message | ||
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in | ||
-h | --help ) | ||
show_help | ||
exit 0 | ||
;; | ||
esac; shift; done | ||
if [[ "$1" == '--' ]]; then shift; fi | ||
|
||
# Check if filename is provided. If not, display error message. | ||
if [ -z "$1" ]; then | ||
echo "Error: No folder provided" | ||
show_help | ||
exit 1 | ||
fi | ||
|
||
# Check if the file exists | ||
if [ -d "$1" ]; then | ||
bun ../../../cli/src/cli.ts \ | ||
server \ | ||
--mount=../../:/wordpress/wp-content/plugins/data-liberation \ | ||
--mount=$1:/wordpress/wp-content/uploads/import-wxr \ | ||
--blueprint=./blueprint-import-wxr.json | ||
else | ||
echo "Error: Folder '$1' does not exist" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/playground/data-liberation/tests/WPStreamImporterTests.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Tests for the WPStreamImporter class. | ||
*/ | ||
class WPStreamImporterTests extends TestCase { | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
if ( ! isset( $_SERVER['SERVER_SOFTWARE'] ) || $_SERVER['SERVER_SOFTWARE'] !== 'PHP.wasm' ) { | ||
$this->markTestSkipped( 'Test only runs in Playground' ); | ||
} | ||
} | ||
|
||
public function test_import_simple_wxr() { | ||
$import = data_liberation_import( __DIR__ . '/wxr/small-export.xml' ); | ||
|
||
$this->assertTrue( $import ); | ||
} | ||
} |
9 changes: 4 additions & 5 deletions
9
packages/playground/data-liberation/tests/import/blueprint-import.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
{ | ||
"$schema": "../../../blueprints/public/blueprint-schema.json", | ||
"constants": { | ||
"WP_DEBUG": true, | ||
"WP_DEBUG_DISPLAY": true, | ||
"WP_DEBUG_LOG": true | ||
}, | ||
"login": true, | ||
"steps": [ | ||
{ | ||
"step": "activatePlugin", | ||
"pluginPath": "data-liberation/plugin.php" | ||
}, | ||
{ | ||
"step": "runPHP", | ||
"code": "<?php require_once 'wordpress/wp-load.php'; $base = '/wordpress/wp-content/plugins/data-liberation/';\nrequire $base . 'vendor/autoload.php';\ntry {\n$arguments = [\n'--stderr',\n'--configuration', $base . 'phpunit.xml'\n];\n$res = (new PHPUnit\\TextUI\\Application())->run($arguments);\nif ( $res !== 0 ) {\ntrigger_error('PHPUnit failed', E_USER_ERROR);\n}\n} catch (Throwable $e) {\ntrigger_error('PHPUnit failed: ' . $e->getMessage(), E_USER_ERROR);\n};" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters