Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions apps/cli/commands/site/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,27 @@ export interface SetCommandOptions {
php?: string;
wp?: string;
xdebug?: boolean;
debugLog?: boolean;
debugDisplay?: boolean;
}

export async function runCommand( sitePath: string, options: SetCommandOptions ): Promise< void > {
const { name, domain, https, php, wp, xdebug } = options;
const { name, domain, https, php, wp, xdebug, debugLog, debugDisplay } = options;

if (
name === undefined &&
domain === undefined &&
https === undefined &&
php === undefined &&
wp === undefined &&
xdebug === undefined
xdebug === undefined &&
debugLog === undefined &&
debugDisplay === undefined
) {
throw new LoggerError(
__( 'At least one option (--name, --domain, --https, --php, --wp, --xdebug) is required.' )
__(
'At least one option (--name, --domain, --https, --php, --wp, --xdebug, --debug-log, --debug-display) is required.'
)
);
}

Expand Down Expand Up @@ -112,9 +118,19 @@ export async function runCommand( sitePath: string, options: SetCommandOptions )
const phpChanged = php !== undefined && php !== site.phpVersion;
const wpChanged = wp !== undefined;
const xdebugChanged = xdebug !== undefined && xdebug !== site.enableXdebug;
const debugLogChanged = debugLog !== undefined && debugLog !== site.enableDebugLog;
const debugDisplayChanged =
debugDisplay !== undefined && debugDisplay !== site.enableDebugDisplay;

const hasChanges =
nameChanged || domainChanged || httpsChanged || phpChanged || wpChanged || xdebugChanged;
nameChanged ||
domainChanged ||
httpsChanged ||
phpChanged ||
wpChanged ||
xdebugChanged ||
debugLogChanged ||
debugDisplayChanged;
if ( ! hasChanges ) {
throw new LoggerError(
__( 'No changes to apply. The site already has the specified settings.' )
Expand All @@ -127,6 +143,8 @@ export async function runCommand( sitePath: string, options: SetCommandOptions )
phpChanged,
wpChanged,
xdebugChanged,
debugLogChanged,
debugDisplayChanged,
} );
const oldDomain = site.customDomain;

Expand All @@ -153,6 +171,12 @@ export async function runCommand( sitePath: string, options: SetCommandOptions )
if ( xdebugChanged ) {
foundSite.enableXdebug = xdebug;
}
if ( debugLogChanged ) {
foundSite.enableDebugLog = debugLog;
}
if ( debugDisplayChanged ) {
foundSite.enableDebugDisplay = debugDisplay;
}

await saveAppdata( appdata );
site = foundSite;
Expand Down Expand Up @@ -287,6 +311,14 @@ export const registerCommand = ( yargs: StudioArgv ) => {
.option( 'xdebug', {
type: 'boolean',
description: __( 'Enable Xdebug' ),
} )
.option( 'debug-log', {
type: 'boolean',
description: __( 'Enable WP_DEBUG_LOG' ),
} )
.option( 'debug-display', {
type: 'boolean',
description: __( 'Enable WP_DEBUG_DISPLAY' ),
} );
},
handler: async ( argv ) => {
Expand All @@ -298,6 +330,8 @@ export const registerCommand = ( yargs: StudioArgv ) => {
php: argv.php,
wp: argv.wp,
xdebug: argv.xdebug,
debugLog: argv.debugLog,
debugDisplay: argv.debugDisplay,
} );
} catch ( error ) {
if ( error instanceof LoggerError ) {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/commands/site/tests/set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe( 'CLI: studio site set', () => {
describe( 'Validation', () => {
it( 'should throw when no options provided', async () => {
await expect( runCommand( testSitePath, {} ) ).rejects.toThrow(
'At least one option (--name, --domain, --https, --php, --wp, --xdebug) is required.'
'At least one option (--name, --domain, --https, --php, --wp, --xdebug, --debug-log, --debug-display) is required.'
);
} );

Expand Down
2 changes: 2 additions & 0 deletions apps/cli/lib/types/wordpress-server-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const serverConfig = z.object( {
siteLanguage: z.string().optional(),
isWpAutoUpdating: z.boolean().optional(),
enableXdebug: z.boolean().optional(),
enableDebugLog: z.boolean().optional(),
enableDebugDisplay: z.boolean().optional(),
blueprint: z
.object( {
contents: z.any(), // Blueprint type is complex, allow any for now
Expand Down
16 changes: 16 additions & 0 deletions apps/cli/lib/wordpress-server-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ export async function startWordPressServer(
serverConfig.enableXdebug = true;
}

if ( site.enableDebugLog ) {
serverConfig.enableDebugLog = true;
}

if ( site.enableDebugDisplay ) {
serverConfig.enableDebugDisplay = true;
}

const env = {
ELECTRON_RUN_AS_NODE: '1',
STUDIO_WORDPRESS_SERVER_CONFIG: JSON.stringify( serverConfig ),
Expand Down Expand Up @@ -371,6 +379,14 @@ export async function runBlueprint(
serverConfig.enableXdebug = true;
}

if ( site.enableDebugLog ) {
serverConfig.enableDebugLog = true;
}

if ( site.enableDebugDisplay ) {
serverConfig.enableDebugDisplay = true;
}

const env = {
ELECTRON_RUN_AS_NODE: '1',
STUDIO_WORDPRESS_SERVER_CONFIG: JSON.stringify( serverConfig ),
Expand Down
30 changes: 28 additions & 2 deletions apps/cli/patches/@wp-playground+wordpress+3.1.1.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/@wp-playground/wordpress/index.cjs b/node_modules/@wp-playground/wordpress/index.cjs
index 9c468e3..3e5ab08 100644
index 9c468e3..324e27d 100644
--- a/node_modules/@wp-playground/wordpress/index.cjs
+++ b/node_modules/@wp-playground/wordpress/index.cjs
@@ -352,7 +352,7 @@ function skip_whitespace($tokens) {
Expand All @@ -11,8 +11,21 @@ index 9c468e3..3e5ab08 100644
ob_start();
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
if (!file_exists($wp_load)) {
@@ -619,7 +619,11 @@ function skip_whitespace($tokens) {

$log_file = WP_CONTENT_DIR . '/debug.log';
define('ERROR_LOG_FILE', $log_file);
- ini_set('error_log', $log_file);
+ if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
+ ini_set('error_log', $log_file);
+ } else {
+ ini_set('log_errors', '0');
+ }
?>`),await e.writeFile("/internal/shared/mu-plugins/sitemap-redirect.php",`<?php
/**
* Redirect sitemap.xml to wp-sitemap.xml for non-root installations.
diff --git a/node_modules/@wp-playground/wordpress/index.js b/node_modules/@wp-playground/wordpress/index.js
index 356bdc9..3fa4beb 100644
index 356bdc9..e1e3fcf 100644
--- a/node_modules/@wp-playground/wordpress/index.js
+++ b/node_modules/@wp-playground/wordpress/index.js
@@ -366,7 +366,6 @@ async function v(e, n, t, i = "rewrite") {
Expand All @@ -23,3 +36,16 @@ index 356bdc9..3fa4beb 100644
};
!e.fileExists(t) && e.fileExists(o(n, "wp-config-sample.php")) && await e.writeFile(
t,
@@ -873,7 +872,11 @@ async function A(e) {

$log_file = WP_CONTENT_DIR . '/debug.log';
define('ERROR_LOG_FILE', $log_file);
- ini_set('error_log', $log_file);
+ if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
+ ini_set('error_log', $log_file);
+ } else {
+ ini_set('log_errors', '0');
+ }
?>`
), await e.writeFile(
"/internal/shared/mu-plugins/sitemap-redirect.php",
8 changes: 7 additions & 1 deletion apps/cli/wordpress-server-child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ async function getBaseRunCLIArgs(
},
];

const defaultConstants = {
const enableDebugLog = config.enableDebugLog ?? false;
const enableDebugDisplay = config.enableDebugDisplay ?? false;

const defaultConstants: Record< string, boolean > = {
WP_SQLITE_AST_DRIVER: true,
WP_DEBUG: enableDebugLog || enableDebugDisplay,
WP_DEBUG_LOG: enableDebugLog,
WP_DEBUG_DISPLAY: enableDebugDisplay,
};

let blueprintBundle: BlueprintBundle | undefined;
Expand Down
11 changes: 11 additions & 0 deletions apps/studio/src/components/content-tab-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,20 @@ export function ContentTabSettings( { selectedSite }: ContentTabSettingsProps )
<span className="line-clamp-1 break-all">{ selectedSite.phpVersion }</span>
</div>
</SettingsRow>
<tr>
<th colSpan={ 2 } className="pb-4 ltr:text-left rtl:text-right">
<h3 className="text-black text-sm font-semibold mt-4">{ __( 'Debugging' ) }</h3>
</th>
</tr>
<SettingsRow label={ __( 'Xdebug' ) }>
<span>{ selectedSite.enableXdebug ? __( 'Enabled' ) : __( 'Disabled' ) }</span>
</SettingsRow>
<SettingsRow label={ __( 'Debug log' ) }>
<span>{ selectedSite.enableDebugLog ? __( 'Enabled' ) : __( 'Disabled' ) }</span>
</SettingsRow>
<SettingsRow label={ __( 'Debug display' ) }>
<span>{ selectedSite.enableDebugDisplay ? __( 'Enabled' ) : __( 'Disabled' ) }</span>
</SettingsRow>

<tr>
<th colSpan={ 2 } className="pb-4 ltr:text-left rtl:text-right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ describe( 'ContentTabSettings', () => {
).toHaveTextContent( 'localhost:8881' );
expect( screen.getByText( 'HTTPS' ) ).toBeVisible();
expect( screen.getByText( 'Xdebug' ) ).toBeVisible();
// Both HTTPS and Xdebug show "Disabled"
expect( screen.getAllByText( 'Disabled' ) ).toHaveLength( 2 );
// HTTPS, Xdebug, Debug log, and Debug display show "Disabled"
expect( screen.getAllByText( 'Disabled' ) ).toHaveLength( 4 );
expect( screen.getByRole( 'button', { name: 'Copy local path to clipboard' } ) ).toBeVisible();
expect( screen.getByText( '7.7.7' ) ).toBeVisible();
expect(
Expand Down
8 changes: 8 additions & 0 deletions apps/studio/src/ipc-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ export async function updateSite(
options.xdebug = updatedSite.enableXdebug ?? false;
}

if ( updatedSite.enableDebugLog !== currentSite.enableDebugLog ) {
options.debugLog = updatedSite.enableDebugLog ?? false;
}

if ( updatedSite.enableDebugDisplay !== currentSite.enableDebugDisplay ) {
options.debugDisplay = updatedSite.enableDebugDisplay ?? false;
}

const hasCliChanges = Object.keys( options ).length > 2;

if ( hasCliChanges ) {
Expand Down
2 changes: 2 additions & 0 deletions apps/studio/src/ipc-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface StoppedSiteDetails {
autoStart?: boolean;
latestCliPid?: number;
enableXdebug?: boolean;
enableDebugLog?: boolean;
enableDebugDisplay?: boolean;
sortOrder?: number;
}

Expand Down
10 changes: 10 additions & 0 deletions apps/studio/src/modules/cli/lib/cli-site-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface EditSiteOptions {
php?: string;
wp?: string;
xdebug?: boolean;
debugLog?: boolean;
debugDisplay?: boolean;
}

export async function editSiteViaCli( options: EditSiteOptions ): Promise< void > {
Expand Down Expand Up @@ -79,5 +81,13 @@ function buildCliArgs( options: EditSiteOptions ): string[] {
args.push( options.xdebug ? '--xdebug' : '--no-xdebug' );
}

if ( options.debugLog !== undefined ) {
args.push( options.debugLog ? '--debug-log' : '--no-debug-log' );
}

if ( options.debugDisplay !== undefined ) {
args.push( options.debugDisplay ? '--debug-display' : '--no-debug-display' );
}

return args;
}
Loading