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

Pick right PHP version for sites created before introducing the PHP selector #262

Merged
merged 4 commits into from
Jun 17, 2024

Conversation

fluiddot
Copy link
Contributor

@fluiddot fluiddot commented Jun 17, 2024

Related to #240 (comment) and #225.

Proposed Changes

  • Populate the PHP version for sites without this property specified when loading site details from user data. The PHP version used for those sites is 8.0, as it was the default version used before Bump default PHP version to 8.1 #240 got merged.

Testing Instructions

New sites

  1. Create a new site.
  2. Go to the Settings tab.
  3. Observe that the PHP version is 8.1.
  4. Open WP admin and navigate to wp-admin/site-health.php?tab=debug.
  5. Open the Server section.
  6. Observe that the PHP version is 8.1.

Old sites

  1. Install a version of the Studio app before changes from Allow PHP version to be changed from Site Settings #225 were applied.
    • Alternatively, you can edit the file ~/Library/Application\ Support/Studio/appdata-v1.json and remove phpVersion property from sites.
  2. Create a new site.
  3. Build/install a version with the changes from this PR.
  4. Select the previously created site.
  5. Go to the Settings tab.
  6. Observe that its PHP version is 8.0.
  7. Edit the PHP version.
  8. Observe that in the "Edit PHP version" modal, the version 8.0 is selected.

Pre-merge Checklist

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

@fluiddot fluiddot requested review from a team June 17, 2024 15:17
@fluiddot fluiddot self-assigned this Jun 17, 2024
Copy link
Contributor

@wojtekn wojtekn left a comment

Choose a reason for hiding this comment

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

The code change looks clear and the feature works as expected.

@wojtekn wojtekn merged commit 0019e5b into trunk Jun 17, 2024
11 checks passed
@wojtekn wojtekn deleted the fix/default-php-version-old-sites branch June 17, 2024 16:09
Comment on lines +5 to +11
type RecursivePartial< T > = {
[ P in keyof T ]?: T[ P ] extends ( infer U )[]
? RecursivePartial< U >[]
: T[ P ] extends object | undefined
? RecursivePartial< T[ P ] >
: T[ P ];
};
Copy link
Member

Choose a reason for hiding this comment

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

@fluiddot alright, I'm going to "bite." 😄 What is this doing and why is it necessary? 😆

Joking aside, I'd love to understand this logic. It's a bit cryptic to me. Would you be willing to share any insight you have? Thanks! 🙇🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dcalhoun I'm glad you asked about this 😃 .

This type is basically an extension of Partial's TypeScript utility type to make all nested properties optional. Partial only sets as optional the root ones. As an example, here's the UserData type:

export interface UserData {
	sites: SiteDetails[];
	snapshots: Snapshot[];
	devToolsOpen?: boolean;
	authToken?: StoredToken;
	onboardingCompleted?: boolean;
	lastBumpStats?: {
		[ group: string ]: {
			[ stat: string ]: number;
		};
	};
	promptWindowsSpeedUpResult?: PromptWindowsSpeedUpResult;
}

If you make Partial<UserData>, all the above properties will be optional:

{
    sites?: SiteDetails[] | undefined;
    snapshots?: Snapshot[] | undefined;
    devToolsOpen?: boolean | undefined;
    authToken?: StoredToken | undefined;
    onboardingCompleted?: boolean | undefined;
    lastBumpStats?: {
        ...;
    } | undefined;
    promptWindowsSpeedUpResult?: PromptWindowsSpeedUpResult | undefined;
}

However, for instance, the nested properties of SiteDetails like SiteDetails.id won't be optional. I found this situation while writing this unit test, and needed to mock the persisted user data. In my case, I only wanted to define part of the site details. That's why I introduced this extra utility type. I presume that we might need it in the future in similar cases, mostly when adding unit tests.

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.

3 participants