Skip to content

Commit abd53d2

Browse files
authored
Fix port replacement on creating new site from backup (#944)
1 parent c2f2baa commit abd53d2

15 files changed

Lines changed: 30 additions & 6 deletions

‎src/components/tests/assistant-code-block.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const selectedSite: SiteDetails = {
2525
path: '/test-site',
2626
phpVersion: '8.0',
2727
adminPassword: btoa( 'test-password' ),
28+
port: 9999,
2829
};
2930

3031
( useSiteDetails as jest.Mock ).mockReturnValue( {

‎src/components/tests/content-tab-import-export.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const selectedSite: SiteDetails = {
1919
path: '/test-site',
2020
phpVersion: '8.0',
2121
adminPassword: btoa( 'test-password' ),
22+
port: 9999,
2223
};
2324

2425
beforeEach( () => {

‎src/hooks/tests/use-import-export.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const selectedSite: SiteDetails = {
1919
path: '/test-site',
2020
phpVersion: '8.0',
2121
adminPassword: btoa( 'test-password' ),
22+
port: 9999,
2223
};
2324

2425
const wrapper = ( { children }: { children: React.ReactNode } ) => (

‎src/hooks/tests/use-update-demo-site.test.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ describe( 'useUpdateDemoSite', () => {
4949
phpVersion: '8.0',
5050
id: '54321',
5151
path: '/path/to/site',
52+
port: 9999,
5253
};
5354
const clientReqPost = jest.fn().mockResolvedValue( {
5455
data: 'success',
@@ -160,6 +161,7 @@ describe( 'useUpdateDemoSite', () => {
160161
phpVersion: '8.0',
161162
id: '09876',
162163
path: '/path/to/site2',
164+
port: 9999,
163165
};
164166

165167
// Mock different response times for each site

‎src/hooks/use-add-site.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ export function useAddSite() {
6767
isNewSite: true,
6868
} );
6969
clearImportState( newSite.id );
70+
} else {
71+
// when we import file we start the server automatically, so doesn't make sense to run it again, to avoid unexpected behaviour
72+
await startServer( newSite.id );
7073
}
71-
await startServer( newSite.id );
74+
7275
getIpcApi().showNotification( {
7376
title: newSite.name,
7477
body: __( 'Your new site is up and running' ),

‎src/hooks/use-site-details.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export function SiteDetailsProvider( { children }: SiteDetailsProviderProps ) {
218218
id: tempSiteId,
219219
name: siteName || path,
220220
path,
221+
port: -1, // Set a temporary port
221222
running: false,
222223
isAddingSite: true,
223224
phpVersion: '',

‎src/ipc-handlers.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { StoredToken } from 'src/lib/oauth';
3838
import * as oauthClient from 'src/lib/oauth';
3939
import { createPassword } from 'src/lib/passwords';
4040
import { phpGetThemeDetails } from 'src/lib/php-get-theme-details';
41+
import { portFinder } from 'src/lib/port-finder';
4142
import { shellOpenExternalWrapper } from 'src/lib/shell-open-external-wrapper';
4243
import { sortSites } from 'src/lib/sort-sites';
4344
import { installSqliteIntegration, keepSqliteIntegrationUpdated } from 'src/lib/sqlite-versions';
@@ -161,11 +162,14 @@ export async function createSite(
161162
}
162163
}
163164

165+
const port = await portFinder.getOpenPort();
166+
164167
const details = {
165168
id: crypto.randomUUID(),
166169
name: siteName || nodePath.basename( path ),
167170
path,
168171
adminPassword: createPassword(),
172+
port,
169173
running: false,
170174
phpVersion: DEFAULT_PHP_VERSION,
171175
} as const;

‎src/ipc-types.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface StoppedSiteDetails {
1717
id: string;
1818
name: string;
1919
path: string;
20-
port?: number;
20+
port: number;
2121
phpVersion: string;
2222
adminPassword?: string;
2323
themeDetails?: {

‎src/lib/import-export/tests/export/exporters/default-exporter.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => {
147147
id: '123',
148148
name: '123',
149149
path: normalize( '/path/to/site' ),
150+
port: 9999,
150151
phpVersion: '7.4',
151152
},
152153
backupFile: normalize( '/path/to/backup.tar.gz' ),

‎src/lib/import-export/tests/export/exporters/sql-exporter.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ platformTestSuite( 'SqlExporter', ( { normalize } ) => {
2323
id: '123',
2424
name: '123',
2525
path: '/path/to/site',
26+
port: 9999,
2627
phpVersion: '7.4',
2728
},
2829
backupFile: normalize( '/path/to/backup.sql' ),

0 commit comments

Comments
 (0)