import { forceReinstallPlugin, runUpdates } from '@auto-launch/functions/setup'; import { digest } from '@shared/api/digest'; import { Spinner } from '@wordpress/components'; import { useCallback, useEffect } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; // The reload is also the retry; the server bounds how many, so it can't loop. export const LaunchUpdate = ({ pluginUpdateNeeded, themeUpdateNeeded, pluginUpdateViaRest, pluginSlug, attempt, }) => { const cardClass = 'flex w-full flex-col items-center p-6 text-center lg:p-10'; const applyUpdates = useCallback(async () => { // Run serially, not concurrently: two WP upgraders fight over the shared // maintenance flag and filesystem. const phpUpdateNeeded = themeUpdateNeeded || (pluginUpdateNeeded && !pluginUpdateViaRest); try { if (phpUpdateNeeded) { const result = await runUpdates(); if (result?.errors?.length) { throw new Error(result.errors.join('; ')); } } if (pluginUpdateNeeded && pluginUpdateViaRest) { await forceReinstallPlugin(pluginSlug); } } catch (error) { digest({ error, details: { source: 'auto-launch', caller: 'launch-update', attempt }, }); } finally { window.location.reload(); } }, [ pluginUpdateNeeded, themeUpdateNeeded, pluginUpdateViaRest, pluginSlug, attempt, ]); useEffect(() => { applyUpdates(); }, [applyUpdates]); return (

{__('Updating your site', 'extendify-local')}

{__( "We're installing the latest updates. Please don't close this window — it will only take a moment.", 'extendify-local', )}

); };