-
Notifications
You must be signed in to change notification settings - Fork 20
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
Allow PHP version to be changed from Site Settings #225
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7e4bcdb
Display the PHP version on Site Settings screen
danielbachhuber f81552f
Add a modal for editing the PHP version
danielbachhuber 7d93cb5
First pass at saving selected PHP version
danielbachhuber 9e856ec
Update site details to allow user to set PHP version (#226)
derekblank 5006fce
Abstract available PHP versions to a constant
danielbachhuber 673606a
Use PHP constants from `wp-now` (#231)
fluiddot 64d1bf7
Add unit tests to cover changing PHP version functionality (#233)
fluiddot de6ed02
Remove `getPhpVersion` hook and IPC handler (#239)
fluiddot f47f515
Bump default PHP version to `8.1` (#240)
fluiddot 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 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { SelectControl } from '@wordpress/components'; | ||
import { useI18n } from '@wordpress/react-i18n'; | ||
import { FormEvent, useCallback, useEffect, useState } from 'react'; | ||
import { DEFAULT_PHP_VERSION, AVAILABLE_PHP_VERSIONS } from '../constants'; | ||
import { useSiteDetails } from '../hooks/use-site-details'; | ||
import Button from './button'; | ||
import Modal from './modal'; | ||
|
||
export default function EditPhpVersion() { | ||
const { __ } = useI18n(); | ||
const { updateSite, selectedSite, stopServer, startServer } = useSiteDetails(); | ||
const [ editPhpVersionError, setEditPhpVersionError ] = useState( '' ); | ||
const [ selectedPhpVersion, setSelectedPhpVersion ] = useState( DEFAULT_PHP_VERSION ); | ||
const [ needsToEditPhpVersion, setNeedsToEditPhpVersion ] = useState( false ); | ||
const [ isEditingSite, setIsEditingSite ] = useState( false ); | ||
|
||
useEffect( () => { | ||
if ( selectedSite ) { | ||
setSelectedPhpVersion( selectedSite.phpVersion ); | ||
} | ||
}, [ selectedSite ] ); | ||
|
||
const resetLocalState = useCallback( () => { | ||
setNeedsToEditPhpVersion( false ); | ||
setSelectedPhpVersion( '' ); | ||
setEditPhpVersionError( '' ); | ||
}, [] ); | ||
|
||
const onSiteEdit = useCallback( | ||
async ( event: FormEvent ) => { | ||
event.preventDefault(); | ||
if ( ! selectedSite ) { | ||
return; | ||
} | ||
setIsEditingSite( true ); | ||
try { | ||
const running = selectedSite.running; | ||
await updateSite( { | ||
...selectedSite, | ||
phpVersion: selectedPhpVersion, | ||
} ); | ||
if ( running ) { | ||
await stopServer( selectedSite.id ); | ||
await startServer( selectedSite.id ); | ||
} | ||
setNeedsToEditPhpVersion( false ); | ||
resetLocalState(); | ||
} catch ( e ) { | ||
setEditPhpVersionError( ( e as Error )?.message ); | ||
} | ||
setIsEditingSite( false ); | ||
}, | ||
[ updateSite, selectedSite, selectedPhpVersion, resetLocalState, startServer, stopServer ] | ||
); | ||
|
||
return ( | ||
<> | ||
{ needsToEditPhpVersion && ( | ||
<Modal | ||
size="medium" | ||
title={ __( 'Edit PHP version' ) } | ||
isDismissible | ||
focusOnMount="firstContentElement" | ||
onRequestClose={ resetLocalState } | ||
> | ||
<form onSubmit={ onSiteEdit }> | ||
<label className="flex flex-col gap-1.5 leading-4"> | ||
<span className="font-semibold">{ __( 'PHP version' ) }</span> | ||
<SelectControl | ||
value={ selectedPhpVersion } | ||
options={ AVAILABLE_PHP_VERSIONS.map( ( version ) => ( { | ||
label: version, | ||
value: version, | ||
} ) ) } | ||
onChange={ ( version ) => setSelectedPhpVersion( version ) } | ||
/> | ||
</label> | ||
<div className="flex flex-row justify-end gap-x-5 mt-6"> | ||
<Button onClick={ resetLocalState } disabled={ isEditingSite } variant="tertiary"> | ||
{ __( 'Cancel' ) } | ||
</Button> | ||
<Button | ||
type="submit" | ||
variant="primary" | ||
isBusy={ isEditingSite } | ||
disabled={ Boolean( | ||
isEditingSite || | ||
! selectedSite || | ||
selectedSite?.phpVersion === selectedPhpVersion || | ||
editPhpVersionError | ||
) } | ||
> | ||
{ isEditingSite ? __( 'Restarting server…' ) : __( 'Save' ) } | ||
</Button> | ||
</div> | ||
</form> | ||
</Modal> | ||
) } | ||
<Button | ||
disabled={ ! selectedSite } | ||
className="!mx-4 shrink-0" | ||
onClick={ () => { | ||
if ( selectedSite ) { | ||
setSelectedPhpVersion( selectedSite.phpVersion ); | ||
} | ||
setNeedsToEditPhpVersion( true ); | ||
} } | ||
label={ __( 'Edit PHP version' ) } | ||
variant="link" | ||
> | ||
{ __( 'Edit' ) } | ||
</Button> | ||
</> | ||
); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { DEFAULT_PHP_VERSION } from '../constants'; | ||
import { getIpcApi } from '../lib/get-ipc-api'; | ||
|
||
export function useGetPhpVersion( site: SiteDetails ) { | ||
const [ phpVersion, setPhpVersion ] = useState( DEFAULT_PHP_VERSION ); | ||
useEffect( () => { | ||
getIpcApi().getPhpVersion( site.id ).then( setPhpVersion ); | ||
}, [ site.id, site.running, site.phpVersion ] ); | ||
return phpVersion; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import * as Sentry from '@sentry/electron/main'; | |||||
import { getWpNowConfig } from '../vendor/wp-now/src'; | ||||||
import { WPNowMode } from '../vendor/wp-now/src/config'; | ||||||
import { getWordPressVersionPath } from '../vendor/wp-now/src/download'; | ||||||
import { DEFAULT_PHP_VERSION } from './constants'; | ||||||
import { pathExists, recursiveCopyDirectory, isEmptyDir } from './lib/fs-utils'; | ||||||
import { decodePassword } from './lib/passwords'; | ||||||
import { phpGetThemeDetails } from './lib/php-get-theme-details'; | ||||||
|
@@ -74,6 +75,7 @@ export class SiteServer { | |||||
port, | ||||||
adminPassword: decodePassword( this.details.adminPassword ?? '' ), | ||||||
siteTitle: this.details.name, | ||||||
php: this.details.phpVersion ?? DEFAULT_PHP_VERSION, | ||||||
} ); | ||||||
const absoluteUrl = `http://localhost:${ port }`; | ||||||
options.absoluteUrl = absoluteUrl; | ||||||
|
@@ -99,6 +101,7 @@ export class SiteServer { | |||||
...this.details, | ||||||
url: this.server.url, | ||||||
port: this.server.options.port, | ||||||
phpVersion: this.server.options.phpVersion || DEFAULT_PHP_VERSION, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: The
Suggested change
|
||||||
running: true, | ||||||
themeDetails, | ||||||
}; | ||||||
|
@@ -109,6 +112,7 @@ export class SiteServer { | |||||
...this.details, | ||||||
name: site.name, | ||||||
path: site.path, | ||||||
phpVersion: site.phpVersion, | ||||||
}; | ||||||
} | ||||||
|
||||||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
I think the hook
useGetPhpVersion
is not necessary because the PHP version is already coming from the site details inselectedSite
.Not sure if this approach has been followed based on the other hook
useGetWpVersion
. If so, the WordPress version needs to be retrieved from the WordPress files as it's not referenced in the site details. That's the main reason for needing that hook.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.
I'll add these changes in a separate PR to avoid blocking this one.
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.
#239