Skip to content
2 changes: 2 additions & 0 deletions src/hooks/tests/use-update-demo-site.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jest.mock( '../../lib/get-ipc-api', () => ( {
getIpcApi: jest.fn().mockReturnValue( {
archiveSite: jest.fn().mockResolvedValue( { zipContent: new Blob( [ 'zipContent' ] ) } ),
showMessageBox: jest.fn().mockResolvedValue( { response: 1 } ), // Assuming '1' is the cancel button
getWpVersion: jest.fn().mockResolvedValue( '6.5' ),
} ),
} ) );
jest.mock( '@sentry/electron/renderer', () => ( {
Expand Down Expand Up @@ -90,6 +91,7 @@ describe( 'useUpdateDemoSite', () => {
type: 'application/zip',
} ),
],
[ 'wordpress_version', '6.5' ],
],
} );

Expand Down
8 changes: 7 additions & 1 deletion src/hooks/use-archive-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export function useArchiveSite() {
type: 'application/zip',
} );

const formData = [ [ 'import', file ] ];
const wordpressVersion = await getIpcApi().getWpVersion( siteId );
if ( wordpressVersion.length >= 3 ) {
formData.push( [ 'wordpress_version', wordpressVersion ] );
}

try {
const response: {
atomic_site_id: number;
Expand All @@ -99,7 +105,7 @@ export function useArchiveSite() {
} = await client.req.post( {
path: '/jurassic-ninja/create-new-site-from-zip',
apiNamespace: 'wpcom/v2',
formData: [ [ 'import', file ] ],
formData,
} );
addSnapshot( {
url: response.domain_name,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/use-get-wp-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getIpcApi } from '../lib/get-ipc-api';
export function useGetWpVersion( site: SiteDetails ) {
const [ wpVersion, setWpVersion ] = useState( '-' );
useEffect( () => {
getIpcApi().getWpVersion( site.path ).then( setWpVersion );
}, [ site.path, site.running ] );
getIpcApi().getWpVersion( site.id ).then( setWpVersion );
}, [ site.id, site.running ] );
return wpVersion;
}
15 changes: 11 additions & 4 deletions src/hooks/use-update-demo-site.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,21 @@ export const DemoSiteUpdateProvider: React.FC< DemoSiteUpdateProviderProps > = (
type: 'application/zip',
} );

const formData = [
[ 'site_id', snapshot.atomicSiteId ],
[ 'import', file ],
];

const wordpressVersion = await getIpcApi().getWpVersion( localSite.id );
if ( wordpressVersion.length >= 3 ) {
formData.push( [ 'wordpress_version', wordpressVersion ] );
}

try {
const response = await client.req.post( {
path: '/jurassic-ninja/update-site-from-zip',
apiNamespace: 'wpcom/v2',
formData: [
[ 'site_id', snapshot.atomicSiteId ],
[ 'import', file ],
],
formData,
} );
updateSnapshot( {
...snapshot,
Expand Down
7 changes: 6 additions & 1 deletion src/ipc-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,12 @@ export async function getAppGlobals( _event: IpcMainInvokeEvent ): Promise< AppG
};
}

export async function getWpVersion( _event: IpcMainInvokeEvent, wordPressPath: string ) {
export async function getWpVersion( _event: IpcMainInvokeEvent, id: string ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we update

getWpVersion: ( wordPressPath: string ) => ipcRenderer.invoke( 'getWpVersion', wordPressPath ),
as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes!, thanks for the early feedback.

Changed 691fa9a

const server = SiteServer.get( id );
if ( ! server ) {
return '-';
}
const wordPressPath = server.details.path;
let versionFileContent = '';
try {
versionFileContent = fs.readFileSync(
Expand Down
2 changes: 1 addition & 1 deletion src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const api: IpcApi = {
copyText: ( text: string ) => ipcRenderer.invoke( 'copyText', text ),
getAppGlobals: () => ipcRenderer.invoke( 'getAppGlobals' ),
removeTemporalFile: ( path: string ) => ipcRenderer.invoke( 'removeTemporalFile', path ),
getWpVersion: ( wordPressPath: string ) => ipcRenderer.invoke( 'getWpVersion', wordPressPath ),
getWpVersion: ( id: string ) => ipcRenderer.invoke( 'getWpVersion', id ),
generateProposedSitePath: ( siteName: string ) =>
ipcRenderer.invoke( 'generateProposedSitePath', siteName ),
openLocalPath: ( path: string ) => ipcRenderer.invoke( 'openLocalPath', path ),
Expand Down