-
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.
Blueprints: Rename importFile to importWxr, switch to humanmade/WordP…
…ress importer (#1192) The importFile step works by interacting with HTML form like a user would. Problem is, the WXR importer requires some interactions with the forms which we fake by adjusting the POST data before submitting the form. This approach causes a number of issues listed below. More context: #1183. ## Implementation Refactors the importFile Blueprint step to: * Be named importWxz. The old name continues to work, though. * Use the humanmade/WordPress-Importer for importing content – it is more reliable than the official wordpress-importer and has a convenient PHP API. * Drop WXZ support – it's a maintenance burden and doesn't add clear value. * Remove dependency on DOMParser – this step should now work in `wp-now` ## Testing instructions 1. Go to http://localhost:5400/website-server/?import-wxr=https://raw.githubusercontent.com/helgatheviking/Simple-User-Listing/3e38ea3eb3a057424fbae4305cba2fd9f73d896b/demo-content/demo-content.xml&php=8.0&wp=6.5&storage=none&php-extension-bundle=kitchen-sink 2. Confirm the "Simple User Listing Block" page was created 3. Confirm in wp-admin a bunch of user accounts were created 4. Confirm in wp-admin the WordPress Importer plugin was installed Closes #1183 Closes #379 Closes #1158 Closes #1161 cc @dmsnell
- Loading branch information
Showing
805 changed files
with
156,368 additions
and
158,473 deletions.
There are no files selected for viewing
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
15 changes: 0 additions & 15 deletions
15
packages/playground/blueprints/src/lib/steps/export-wxz.ts
This file was deleted.
Oops, something went wrong.
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
93 changes: 0 additions & 93 deletions
93
packages/playground/blueprints/src/lib/steps/import-file.ts
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
packages/playground/blueprints/src/lib/steps/import-wxr.ts
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,55 @@ | ||
import { StepHandler } from '.'; | ||
import { writeFile } from './write-file'; | ||
import { phpVar } from '@php-wasm/util'; | ||
|
||
/** | ||
* @inheritDoc importWxr | ||
* @example | ||
* | ||
* <code> | ||
* { | ||
* "step": "importWxr", | ||
* "file": { | ||
* "resource": "url", | ||
* "url": "https://your-site.com/starter-content.wxr" | ||
* } | ||
* } | ||
* </code> | ||
*/ | ||
export interface ImportWxrStep<ResourceType> { | ||
step: 'importWxr'; | ||
/** The file to import */ | ||
file: ResourceType; | ||
} | ||
|
||
/** | ||
* Imports a WXR file into WordPress. | ||
* | ||
* @param playground Playground client. | ||
* @param file The file to import. | ||
*/ | ||
export const importWxr: StepHandler<ImportWxrStep<File>> = async ( | ||
playground, | ||
{ file }, | ||
progress? | ||
) => { | ||
progress?.tracker?.setCaption('Importing content'); | ||
await writeFile(playground, { | ||
path: '/tmp/import.wxr', | ||
data: file, | ||
}); | ||
const docroot = await playground.documentRoot; | ||
await playground.run({ | ||
code: `<?php | ||
require ${phpVar(docroot)} . '/wp-load.php'; | ||
$admin_id = get_users(array('role' => 'Administrator') )[0]; | ||
$importer = new WXR_Importer( array( | ||
'fetch_attachments' => true, | ||
'default_author' => $admin_id | ||
) ); | ||
$logger = new WP_Importer_Logger_CLI(); | ||
$importer->set_logger( $logger ); | ||
$result = $importer->import( '/tmp/import.wxr' ); | ||
`, | ||
}); | ||
}; |
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
Oops, something went wrong.