Skip to content

Commit a3fe1d0

Browse files
authored
Remove Data Liberation PHP modules (#79)
Removes the PHP Data Liberation plumbing originally introduced in #1888. The codebase has since moved to https://github.com/Automattic/php-toolkit and is not maintained in the Playground repository anymore. It's only a cause of test failures at the moment for little added benefit. This PR also removes the possibility of importing WXR files using the data liberation importer. It will have to be re-architected anyway to accomodate for the changes in the php-toolkit repository structure. ## Testing instructions This PR mostly removes code. Just confirm the CI checks pass
1 parent f5df251 commit a3fe1d0

File tree

864 files changed

+12
-358676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

864 files changed

+12
-358676
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ __pycache__
77
packages/playground/wordpress-builds/src/wordpress
88
packages/playground/wordpress-builds/public
99
packages/playground/sync/src/test/wp-*
10-
packages/playground/data-liberation/tests/fixtures
1110
packages/php-wasm/node/src/test/__test*
1211
*.timestamp-1678999213403.mjs
1312
.local

.github/workflows/ci.yml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,6 @@ jobs:
2323
- uses: ./.github/actions/prepare-playground
2424
- run: npx nx affected --target=lint
2525
- run: npx nx affected --target=typecheck
26-
lint-and-test-php:
27-
name: 'Lint and test PHP'
28-
runs-on: wordpress-playground-private
29-
steps:
30-
- uses: actions/checkout@v4
31-
with:
32-
submodules: true
33-
- uses: actions/setup-node@v4
34-
with:
35-
node-version: 20
36-
- run: npm install
37-
- name: Set up PHP
38-
uses: shivammathur/setup-php@v2
39-
with:
40-
# @TODO: Running the tests on PHP 7.2
41-
php-version: '8.1'
42-
tools: phpunit-polyfills
43-
- name: Install Composer dependencies
44-
uses: ramsey/composer-install@v3
45-
with:
46-
ignore-cache: 'yes'
47-
composer-options: '--optimize-autoloader'
48-
working-directory: 'packages/playground/data-liberation'
49-
- run: npx nx run playground-data-liberation:lint:php
50-
- run: npx nx run playground-data-liberation:test:phpunit
5126
test-unit-asyncify:
5227
runs-on: wordpress-playground-private
5328
needs: [lint-and-typecheck]

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ packages/docs/site/src/model.json
1414
dist.zip
1515
rollup.d.ts
1616
.phpunit.cache
17-
packages/playground/data-liberation/vendor
1817

1918
# dependencies
2019
node_modules

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
[submodule "isomorphic-git"]
22
path="isomorphic-git"
33
url=https://github.com/adamziel/isomorphic-git.git
4-
[submodule "blueprints-library"]
5-
path="packages/playground/data-liberation/blueprints-library"
6-
url=https://github.com/WordPress/blueprints-library.git
7-

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
/packages/playground/wordpress-builds/build/build-assets
99
/packages/playground/wordpress-builds/src/wordpress
1010
/packages/playground/wordpress-builds/public/
11-
/packages/playground/data-liberation/tests/fixtures
1211
/packages/php-wasm/node/src/test/__test*
1312
__pycache__
1413
*.timestamp-1678999213403.mjs

package-lock.json

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/playground/blueprints/public/blueprint-schema-validator.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,6 @@ const schema11 = {
453453
$ref: '#/definitions/FileReference',
454454
description: 'The file to import',
455455
},
456-
importer: {
457-
type: 'string',
458-
enum: ['data-liberation', 'default'],
459-
description:
460-
'The importer to use. Possible values:\n\n- `default`: The importer from https://github.com/humanmade/WordPress-Importer\n- `data-liberation`: The experimental Data Liberation WXR importer developed at https://github.com/WordPress/wordpress-playground/issues/1894\n\nThis option is deprecated. The syntax will not be removed, but once the Data Liberation importer matures, it will become the only supported importer and the `importer` option will be ignored.',
461-
deprecated: true,
462-
},
463456
},
464457
required: ['file', 'step'],
465458
},
@@ -3162,13 +3155,6 @@ const schema22 = {
31623155
$ref: '#/definitions/FileReference',
31633156
description: 'The file to import',
31643157
},
3165-
importer: {
3166-
type: 'string',
3167-
enum: ['data-liberation', 'default'],
3168-
description:
3169-
'The importer to use. Possible values:\n\n- `default`: The importer from https://github.com/humanmade/WordPress-Importer\n- `data-liberation`: The experimental Data Liberation WXR importer developed at https://github.com/WordPress/wordpress-playground/issues/1894\n\nThis option is deprecated. The syntax will not be removed, but once the Data Liberation importer matures, it will become the only supported importer and the `importer` option will be ignored.',
3170-
deprecated: true,
3171-
},
31723158
},
31733159
required: ['file', 'step'],
31743160
},
@@ -10056,38 +10042,6 @@ function validate14(
1005610042
];
1005710043
return false;
1005810044
}
10059-
if (
10060-
!(
10061-
data40 ===
10062-
'data-liberation' ||
10063-
data40 ===
10064-
'default'
10065-
)
10066-
) {
10067-
validate14.errors =
10068-
[
10069-
{
10070-
instancePath:
10071-
instancePath +
10072-
'/importer',
10073-
schemaPath:
10074-
'#/oneOf/6/properties/importer/enum',
10075-
keyword:
10076-
'enum',
10077-
params: {
10078-
allowedValues:
10079-
schema22
10080-
.oneOf[6]
10081-
.properties
10082-
.importer
10083-
.enum,
10084-
},
10085-
message:
10086-
'must be equal to one of the allowed values',
10087-
},
10088-
];
10089-
return false;
10090-
}
1009110045
var valid21 =
1009210046
_errs109 === errors;
1009310047
} else {

packages/playground/blueprints/public/blueprint-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@
542542
},
543543
"importer": {
544544
"type": "string",
545-
"enum": ["data-liberation", "default"],
545+
"enum": ["default"],
546546
"description": "The importer to use. Possible values:\n\n- `default`: The importer from https://github.com/humanmade/WordPress-Importer\n- `data-liberation`: The experimental Data Liberation WXR importer developed at https://github.com/WordPress/wordpress-playground/issues/1894\n\nThis option is deprecated. The syntax will not be removed, but once the Data Liberation importer matures, it will become the only supported importer and the `importer` option will be ignored.",
547547
"deprecated": true
548548
}

packages/playground/blueprints/src/lib/compile.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ import {
77
UniversalPHP,
88
} from '@php-wasm/universal';
99
import { FileReference, isResourceReference, Resource } from './resources';
10-
import { ImportWxrStep, Step, StepDefinition, WriteFileStep } from './steps';
10+
import { Step, StepDefinition, WriteFileStep } from './steps';
1111
import * as allStepHandlers from './steps/handlers';
1212
import { Blueprint, ExtraLibrary } from './blueprint';
1313
import { logger } from '@php-wasm/logger';
14-
/* @ts-ignore */
15-
// eslint-disable-next-line
16-
import dataLiberationCoreUrl from '../../../data-liberation/dist/data-liberation-core.phar.gz?url';
1714

1815
// @TODO: Configure this in the `wp-cli` step, not here.
1916
const { wpCLI, ...otherStepHandlers } = allStepHandlers;
@@ -231,29 +228,14 @@ export function compileBlueprint(
231228
(step) => typeof step === 'object' && step?.step === 'importWxr'
232229
);
233230
if (importWxrStepIndex !== undefined && importWxrStepIndex > -1) {
234-
const importWxrStep = blueprint.steps![
235-
importWxrStepIndex
236-
]! as ImportWxrStep<any>;
237-
if (importWxrStep.importer === 'data-liberation') {
238-
blueprint.steps?.splice(importWxrStepIndex, 0, {
239-
step: 'writeFile',
240-
path: '/internal/shared/data-liberation-core.phar',
241-
data: {
242-
resource: 'url',
243-
url: dataLiberationCoreUrl,
244-
caption: 'Downloading the Data Liberation WXR importer',
245-
},
246-
});
247-
} else {
248-
blueprint.steps?.splice(importWxrStepIndex, 0, {
249-
step: 'installPlugin',
250-
pluginData: {
251-
resource: 'url',
252-
url: 'https://playground.wordpress.net/wordpress-importer.zip',
253-
caption: 'Downloading the WordPress Importer plugin',
254-
},
255-
});
256-
}
231+
blueprint.steps?.splice(importWxrStepIndex, 0, {
232+
step: 'installPlugin',
233+
pluginData: {
234+
resource: 'url',
235+
url: 'https://playground.wordpress.net/wordpress-importer.zip',
236+
caption: 'Downloading the WordPress Importer plugin',
237+
},
238+
});
257239
}
258240

259241
const { valid, errors } = validateBlueprint(blueprint);

packages/playground/blueprints/src/lib/steps/import-wxr.ts

Lines changed: 2 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ export interface ImportWxrStep<ResourceType> {
4545
*/
4646
export const importWxr: StepHandler<ImportWxrStep<File>> = async (
4747
playground,
48-
{ file, importer = 'default' },
48+
{ file },
4949
progress?
5050
) => {
51-
if (importer === 'data-liberation') {
52-
await importWithDataLiberationImporter(playground, file, progress);
53-
} else {
54-
await importWithDefaultImporter(playground, file, progress);
55-
}
51+
await importWithDefaultImporter(playground, file, progress);
5652
};
5753

5854
async function importWithDefaultImporter(
@@ -107,133 +103,3 @@ async function importWithDefaultImporter(
107103
`,
108104
});
109105
}
110-
111-
async function importWithDataLiberationImporter(
112-
playground: UniversalPHP,
113-
file: File,
114-
progress?: StepProgress | undefined
115-
) {
116-
progress?.tracker?.setCaption('Preparing content import');
117-
await writeFile(playground, {
118-
path: '/tmp/import.wxr',
119-
data: file,
120-
});
121-
const docroot = await playground.documentRoot;
122-
/**
123-
* Surface the import progress information in the Blueprint progress bar.
124-
* This temporary message handler is cleared at the end of this step.
125-
*/
126-
const clearProgressListener = await playground.onMessage(
127-
(messageString) => {
128-
const message = JSON.parse(messageString) as any;
129-
if (message?.type === 'import-wxr-progress') {
130-
progress?.tracker?.setCaption(message.progress);
131-
}
132-
}
133-
);
134-
try {
135-
await playground.run({
136-
code: `<?php
137-
require ${phpVar(docroot)} . '/wp-load.php';
138-
require ${phpVar(docroot)} . '/wp-admin/includes/admin.php';
139-
140-
// Defines the constants expected by the Box .phar stub when "cli" is used
141-
// as the SAPI name.
142-
// @TODO: Don't use the "cli" SAPI string and don't allow composer to run platform checks.
143-
if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'w'));
144-
if(!defined('STDIN')) define('STDIN', fopen('php://stdin', 'r'));
145-
if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'w'));
146-
147-
// Preloaded by the Blueprint compile() function
148-
require '/internal/shared/data-liberation-core.phar';
149-
150-
$admin_id = get_users(array('role' => 'Administrator') )[0]->ID;
151-
wp_set_current_user( $admin_id );
152-
153-
$new_site_url = get_site_url();
154-
$importer = WP_Stream_Importer::create_for_wxr_file(
155-
'/tmp/import.wxr',
156-
array(
157-
'new_site_url' => $new_site_url,
158-
)
159-
);
160-
$session = WP_Import_Session::create(
161-
array(
162-
'data_source' => 'wxr_file',
163-
'file_name' => '/tmp/import.wxr',
164-
)
165-
);
166-
while ( true ) {
167-
if ( true === $importer->next_step() ) {
168-
/**
169-
* We're ignoring any importing errors.
170-
* This script is a part of Blueprints and is expected to finish
171-
* without stopping. We won't be gathering additional user input
172-
* along the way. Instead, we'll just decide not to ignore the
173-
* errors.
174-
*
175-
* @TODO: Consider extracting this code into a CLI script and
176-
* using it here instead of this custom script. Note it's
177-
* about a simple CLI script, not a WP-CLI command, as the
178-
* latter would require downloading 5MB of WP-CLI code.
179-
*/
180-
switch ( $importer->get_stage() ) {
181-
case WP_Stream_Importer::STAGE_INITIAL:
182-
$message = 'Preparing content import';
183-
break;
184-
185-
case WP_Stream_Importer::STAGE_INDEX_ENTITIES:
186-
// Bump the total number of entities to import.
187-
$indexed = $session->count_all_total_entities();
188-
$message = 'Content import 1/4: Indexing records (' . $indexed . ' so far)';
189-
$session->create_frontloading_placeholders( $importer->get_indexed_assets_urls() );
190-
$session->bump_total_number_of_entities(
191-
$importer->get_indexed_entities_counts()
192-
);
193-
break;
194-
195-
case WP_Stream_Importer::STAGE_TOPOLOGICAL_SORT:
196-
$message = 'Content import 2/4: Indexing data';
197-
break;
198-
199-
case WP_Stream_Importer::STAGE_FRONTLOAD_ASSETS:
200-
$session->bump_frontloading_progress(
201-
$importer->get_frontloading_progress(),
202-
$importer->get_frontloading_events()
203-
);
204-
$nb_media = $session->count_awaiting_frontloading_placeholders();
205-
$message = 'Content import 3/4: Downloading media (' . $nb_media . ' remaining)';
206-
break;
207-
208-
case WP_Stream_Importer::STAGE_IMPORT_ENTITIES:
209-
$session->bump_imported_entities_counts(
210-
$importer->get_imported_entities_counts()
211-
);
212-
$nb_remaining_entities = $session->count_remaining_entities();
213-
$message = 'Content import 4/4: Inserting data (' . $nb_remaining_entities . ' remaining)';
214-
break;
215-
216-
default:
217-
$message = 'Importing content';
218-
break;
219-
}
220-
221-
// Report progress to the UI
222-
post_message_to_js(json_encode([
223-
'type' => 'import-wxr-progress',
224-
'progress' => $message,
225-
]));
226-
continue;
227-
}
228-
if ( $importer->advance_to_next_stage() ) {
229-
continue;
230-
}
231-
// Import finished
232-
break;
233-
}
234-
`,
235-
});
236-
} finally {
237-
await clearProgressListener();
238-
}
239-
}

0 commit comments

Comments
 (0)