Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Studio: Ensure wp-config constants are defined after import #758

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from

Conversation

katinthehatsite
Copy link
Contributor

@katinthehatsite katinthehatsite commented Dec 20, 2024

Related issues

Closes https://github.com/Automattic/dotcom-forge/issues/10148

Proposed Changes

This PR adds polyfill for database constants in case they are not defined in the wp-config.php file when it is being imported. This ensures that the database constants are defined when the site is started.

Testing Instructions

  • Pull the changes from this branch
  • Download a backup from this site: https://mc.a8c.com/rewind/debugger.php?site=138657400
  • Navigate to Import/Export tab in Studio
  • Drop this backup to import it into a site
  • Observe that the import succeeds and the site starts successfully

Alternatively, you can export a Studio site, edit wp-config.php file and remove the constants such as DB_HOST etc. from that file. You can then attempt to import it and confirm that the import succeeds and that the site starts successfully.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@katinthehatsite katinthehatsite self-assigned this Dec 20, 2024
@katinthehatsite katinthehatsite changed the title Studio: Activating Mailpoet from Jetpack import throws undefined constant DB_HOST error Studio: Ensure wp-config constants are defined after import Dec 20, 2024
@wojtekn
Copy link
Contributor

wojtekn commented Dec 20, 2024

@katinthehatsite, what if we simplified it and skipped the wp-config.php import if it's invalid, leaving the default one in place? Or maybe we could have a PHP polyfill that sets each constant if it doesn't exist?

@katinthehatsite
Copy link
Contributor Author

Or maybe we could have a PHP polyfill that sets each constant if it doesn't exist?

For now I went with this approach so that user's config gets preserved. Happy to change it though if it seems overly complicated.

what if we simplified it and skipped the wp-config.php import if it's invalid, leaving the default one in place?

We can also do that as an alternative. Could there be any data that would be vital in the user's config that we could miss by keeping the default config in place?

const configContent = await readFile( wpConfigPath, 'utf8' );

// Add a unique marker comment to identify our polyfill
if ( ! configContent.includes( '/* WP_POLYFILL_MARKER */' ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort of added this check for the case when the user imports a config and the config might have polyfill added already (if they imported a site into Studio from elsewhere and then exported it again out of Studio and imported it the second time) to avoid adding this twice.

There might be a better approach though, not completely sure on this one.

@katinthehatsite
Copy link
Contributor Author

what if we simplified it and skipped the wp-config.php import if it's invalid, leaving the default one in place?

The more I think about this, the more I think it is the better approach. I will wait for the clarification on my question and will adjust accordingly.

@katinthehatsite katinthehatsite requested a review from a team December 23, 2024 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants