This repository was archived by the owner on Jun 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Add a hotfix for missing DB_NAME
constant
#44
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just make this change in Playground in that case and skip adding temporary solutions to the SQLite plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bgrgicak I'm not sure what that will involve. Do you think it's a small and quick fix? I'm not yet familiar enough with the Playground codebase to have an idea of what needs to be done — do we do something similar in Playground already? Will it reuse a Blueprint step logic? Etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be quick to do. We can update the
bootWordPress
function and define the constant if it's missing, similarly to how we add the WP_HOME constant.Or we could add it to
preloadSqliteIntegration
, where we defineSQLITE_MAIN_FILE
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with Bero. It would be something like this in boot.ts:
We don't have the
isConstantDefined
implementation. I don't think we can boot WP at this point yet and just calldefined( "DB_NAME" )
so we might need to statically analyze wp-config.php. Here's one way to do it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, we already have some static analysis PHP code in the Playground repo, we might need to refactor it to also have a separate function just for checking the constant's presence:
https://github.com/Automattic/wordpress-playground-private/blob/53d691faa17193c49a40aa2a747f032c505d34f2/packages/playground/blueprints/src/lib/steps/rewrite-wp-config-to-define-constants.php#L70
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JanJakes we would need to check which constants are already defined find and only add the
DB_NAME
constant if it's not already a part of wp-config.php. rewrite_wp_config_to_define_constants has all the relevant logic in it, it just doesn't do the thing we need here. It seems like we need to split outget_constants_defined_in_wp_config( $code )
oris_constant_defined_in_wp_config( $code, $constant )
.The only way to include the
DB_NAME
with the site export seems to be updating the wp-config.php.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel What if the
wp-config.php
already contains some conditional for defining the constant:Would
is_constant_defined_in_wp_config
returntrue
orfalse
, and how would we rewrite it? I guess we could assume the likely 99% scenario, and just say "if there's anydefine( DB_NAME, ... )
anywhere in the file, we don't inject it, otherwise we do".Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first, I was tempted to say we could cover those cases with
if(!defined('DB_NAME', ...))
beforerequire ABSPATH . "wp-settings.php";
. I wonder if that's true, though. If a site only defines aDB_NAME
conditionally, they seem to have a very specific intention for what they want to do, e.g. run multiple WordPress instances from a single directory. Adding another definition would likely collide with that intent. I'd say, in those cases, we should just bale, throw a meaningful error, and let them handle it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel I agree. To summarize, I think we should only inject the default
DB_NAME
value if there is nodefine( 'DB_NAME', ... )
at all in the config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's continue the discussion in https://github.com/Automattic/wordpress-playground-private/pull/140.