From 1fec533d4fb8e176871c69b49c46a9d74e4d459b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Sun, 21 Apr 2024 21:21:49 +0200 Subject: [PATCH 1/3] Blueprints: Remove setPhpIniEntry step Removes the setPhpIniEntry step. It cannot work reliably as setting PHP.ini entries must happen before the PHP is initialized, but Blueprints are executed after PHP is initialized. To set php.ini entries, either customize the php.ini files or use an mu-plugin. ## Testing instructions Run a Blueprint with a setPhpIniEntry step, confirm the Playground still loads without a crash. --- .../playground/blueprints/src/lib/compile.ts | 20 +++++++++++- .../blueprints/src/lib/steps/handlers.ts | 1 - .../blueprints/src/lib/steps/index.ts | 3 -- .../src/lib/steps/set-php-ini-entry.ts | 32 ------------------- 4 files changed, 19 insertions(+), 37 deletions(-) delete mode 100644 packages/playground/blueprints/src/lib/steps/set-php-ini-entry.ts diff --git a/packages/playground/blueprints/src/lib/compile.ts b/packages/playground/blueprints/src/lib/compile.ts index 74827f301d..244b910ccc 100644 --- a/packages/playground/blueprints/src/lib/compile.ts +++ b/packages/playground/blueprints/src/lib/compile.ts @@ -85,7 +85,9 @@ export function compileBlueprint( ): CompiledBlueprint { blueprint = { ...blueprint, - steps: (blueprint.steps || []).filter(isStepDefinition), + steps: (blueprint.steps || []) + .filter(isStepDefinition) + .filter(isStepStillSupported), }; // Convert legacy importFile steps to importWxr for (const step of blueprint.steps!) { @@ -414,6 +416,22 @@ function isStepDefinition( return !!(typeof step === 'object' && step); } +/** + * Determines if a step is still supported, or was it deprecated + * and removed. + * + * @param step The object to test + * @returns Whether the object is a StepDefinition + */ +function isStepStillSupported( + step: Record +): step is StepDefinition { + if (step['step'] === 'setPhpIniEntry') { + return false; + } + return true; +} + interface CompileStepArgsOptions { /** Optional semaphore to control access to a shared resource */ semaphore?: Semaphore; diff --git a/packages/playground/blueprints/src/lib/steps/handlers.ts b/packages/playground/blueprints/src/lib/steps/handlers.ts index 27a880c086..10fe89ab81 100644 --- a/packages/playground/blueprints/src/lib/steps/handlers.ts +++ b/packages/playground/blueprints/src/lib/steps/handlers.ts @@ -3,7 +3,6 @@ export { activateTheme } from './activate-theme'; export { runPHP } from './run-php'; export { runPHPWithOptions } from './run-php-with-options'; export { runSql } from './run-sql'; -export { setPhpIniEntry } from './set-php-ini-entry'; export { request } from './request'; export { enableMultisite } from './enable-multisite'; export { cp } from './cp'; diff --git a/packages/playground/blueprints/src/lib/steps/index.ts b/packages/playground/blueprints/src/lib/steps/index.ts index ea17783b5b..e5eaee396c 100644 --- a/packages/playground/blueprints/src/lib/steps/index.ts +++ b/packages/playground/blueprints/src/lib/steps/index.ts @@ -17,7 +17,6 @@ import { RmdirStep } from './rmdir'; import { RunSqlStep } from './run-sql'; import { MkdirStep } from './mkdir'; import { MvStep } from './mv'; -import { SetPhpIniEntryStep } from './set-php-ini-entry'; import { RunPHPStep } from './run-php'; import { RunPHPWithOptionsStep } from './run-php-with-options'; import { RequestStep } from './request'; @@ -65,7 +64,6 @@ export type GenericStep = | RunPHPWithOptionsStep | RunWpInstallationWizardStep | RunSqlStep - | SetPhpIniEntryStep | SetSiteOptionsStep | UnzipStep | UpdateUserMetaStep @@ -96,7 +94,6 @@ export type { RunWpInstallationWizardStep, RunSqlStep, WordPressInstallationOptions, - SetPhpIniEntryStep, SetSiteOptionsStep, UnzipStep, UpdateUserMetaStep, diff --git a/packages/playground/blueprints/src/lib/steps/set-php-ini-entry.ts b/packages/playground/blueprints/src/lib/steps/set-php-ini-entry.ts deleted file mode 100644 index 2d711a13b1..0000000000 --- a/packages/playground/blueprints/src/lib/steps/set-php-ini-entry.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { StepHandler } from '.'; - -/** - * @inheritDoc setPhpIniEntry - * @hasRunnableExample - * @example - * - * - * { - * "step": "setPhpIniEntry", - * "key": "display_errors", - * "value": "1" - * } - * - */ -export interface SetPhpIniEntryStep { - step: 'setPhpIniEntry'; - /** Entry name e.g. "display_errors" */ - key: string; - /** Entry value as a string e.g. "1" */ - value: string; -} - -/** - * Sets a PHP ini entry. - */ -export const setPhpIniEntry: StepHandler = async ( - playground, - { key, value } -) => { - await playground.setPhpIniEntry(key, value); -}; From 8cc0486be1b1cc2363edfa1a0307ab18a6dd95c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Sun, 21 Apr 2024 21:32:36 +0200 Subject: [PATCH 2/3] Add a warning when the setPhpIniEntry is detected --- packages/playground/blueprints/src/lib/compile.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/playground/blueprints/src/lib/compile.ts b/packages/playground/blueprints/src/lib/compile.ts index 244b910ccc..d64ade5818 100644 --- a/packages/playground/blueprints/src/lib/compile.ts +++ b/packages/playground/blueprints/src/lib/compile.ts @@ -427,6 +427,9 @@ function isStepStillSupported( step: Record ): step is StepDefinition { if (step['step'] === 'setPhpIniEntry') { + console.warn( + `The "setPhpIniEntry" Blueprint is no longer supported and you can remove it from your Blueprint.` + ); return false; } return true; From b0c7f9a2acb399cbb99881f9377f47d9101bfdcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Sun, 21 Apr 2024 21:44:49 +0200 Subject: [PATCH 3/3] Improve docstring --- packages/playground/blueprints/src/lib/compile.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground/blueprints/src/lib/compile.ts b/packages/playground/blueprints/src/lib/compile.ts index d64ade5818..4be2ea30c0 100644 --- a/packages/playground/blueprints/src/lib/compile.ts +++ b/packages/playground/blueprints/src/lib/compile.ts @@ -420,8 +420,8 @@ function isStepDefinition( * Determines if a step is still supported, or was it deprecated * and removed. * - * @param step The object to test - * @returns Whether the object is a StepDefinition + * @param step The step definition to test. + * @returns Whether the step is still supported. */ function isStepStillSupported( step: Record