raw( 'confirm' ) ) { throw new HttpException( 'om_confirm_required', sprintf( /* translators: %s: the word to type, RESET */ esc_html__( 'Type %s to confirm.', 'migratex' ), esc_html( ResetScope::CONFIRM ) ), 400 ); } $scope = $request->str( 'scope' ); if ( ! ResetScope::isValid( $scope ) ) { throw new HttpException( 'om_bad_scope', esc_html__( 'Unknown reset tool.', 'migratex' ), 400 ); } if ( ResetScope::blockedOnNetwork( $scope ) ) { throw new HttpException( 'om_multisite_blocked', esc_html( ResetScope::networkMessage( $scope ) ), 403 ); } // A page reload or a second tab re-attaches instead of starting a second reset. $active = $this->store->findActive( 'reset', get_current_user_id() ); if ( null !== $active ) { return Response::job( $active ); } $this->assertNothingElseRunning(); $default_theme = ResetScope::defaultTheme(); if ( in_array( $scope, array( ResetScope::THEMES, ResetScope::FULL ), true ) && null === $default_theme ) { throw new HttpException( 'om_no_default_theme', esc_html__( 'No default WordPress theme is installed to fall back to, so nothing was removed. Install one (for example Twenty Twenty-Five) and try again.', 'migratex' ), 409 ); } $job = $this->store->create( 'reset', get_current_user_id(), array( 'scope' => $scope, // A database reset keeps the current theme when no default one is installed. 'default_theme' => (string) $default_theme, ) ); return Response::job( $job ); } public function tick( Request $request ): Response { $job = $this->ownedJob( $request, 'reset' ); return Response::job( $this->runner->tick( $job ) ); } /** * Deleting files while an export is reading them would produce a damaged backup, and a * restore replaces the same things a reset removes. * * @throws HttpException */ private function assertNothingElseRunning(): void { foreach ( $this->store->ids() as $id ) { $job = $this->store->load( $id ); if ( null !== $job && ! $job->isTerminal() && in_array( $job->type(), array( JobState::TYPE_EXPORT, JobState::TYPE_IMPORT ), true ) ) { throw new HttpException( 'om_busy', esc_html__( 'An export or import is still running. Let it finish, or cancel it, before resetting.', 'migratex' ), 409 ); } } } }