Skip to content

Commit

Permalink
Extract preloadSqliteIntegration to a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed May 14, 2024
1 parent f059be8 commit ba99209
Showing 1 changed file with 8 additions and 42 deletions.
50 changes: 8 additions & 42 deletions packages/playground/cli/src/setup-wp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
readAsFile,
} from './download';
import { withPHPIniValues } from './setup-php';
import { playgroundMuPlugin } from '@wp-playground/wordpress';
import {
playgroundMuPlugin,
preloadSqliteIntegration,
} from '@wp-playground/wordpress';

/**
* Ensures a functional WordPress installation in php document root.
Expand Down Expand Up @@ -49,7 +52,9 @@ export async function setupWordPress(
monitor
),
]);
await prepareWordPress(php, wpZip, sqliteZip);

await prepareWordPress(php, wpZip);
await preloadSqliteIntegration(php, sqliteZip);

const preinstalledWpContentPath = path.join(
CACHE_FOLDER,
Expand Down Expand Up @@ -105,7 +110,7 @@ export async function setupWordPress(
* accept the limitation, and switch to the PHP implementation as soon
* as that's viable.
*/
async function prepareWordPress(php: NodePHP, wpZip: File, sqliteZip: File) {
async function prepareWordPress(php: NodePHP, wpZip: File) {
php.mkdir('/internal/shared/mu-plugins');
php.writeFile(
'/internal/shared/mu-plugins/0-playground.php',
Expand All @@ -128,43 +133,4 @@ async function prepareWordPress(php: NodePHP, wpZip: File, sqliteZip: File) {
'/wordpress/wp-config.php',
php.readFileAsText('/wordpress/wp-config-sample.php')
);
// }}}

// Setup the SQLite integration {{{
php.mkdir('/tmp/sqlite-database-integration');
await unzip(php, {
zipFile: sqliteZip,
extractToPath: '/tmp/sqlite-database-integration',
});
php.mv(
'/tmp/sqlite-database-integration/sqlite-database-integration-main',
'/internal/shared/mu-plugins/sqlite-database-integration'
);

php.writeFile(
`/internal/mu-plugins/sqlite-test.php`,
`<?php
global $wpdb;
if(!($wpdb instanceof WP_SQLite_DB)) {
var_dump(isset($wpdb));
die("SQLite integration not loaded " . get_class($wpdb));
}
`
);
const dbPhp = php
.readFileAsText(
'/internal/shared/mu-plugins/sqlite-database-integration/db.copy'
)
.replace(
"'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",
"'/internal/shared/mu-plugins/sqlite-database-integration/'"
)
.replace(
"'{SQLITE_PLUGIN}'",
"'/internal/shared/mu-plugins/sqlite-database-integration/load.php'"
);
php.writeFile(
'/internal/mu-plugins/sqlite-database-integration.php',
dbPhp
);
}

0 comments on commit ba99209

Please sign in to comment.