fix: handle invalid package uploads

This commit is contained in:
Keith Solomon
2026-04-26 20:45:18 -05:00
parent 90b56e13bb
commit cce40907d5
4 changed files with 98 additions and 2 deletions
+29 -2
View File
@@ -49,7 +49,23 @@ final class FileImportController {
throw new \RuntimeException( 'The package file could not be read.' );
}
$package = $this->transport->import( $contents );
try {
$package = $this->transport->import( $contents );
} catch ( \InvalidArgumentException $exception ) {
$this->logger->warning(
'Rejected imported content package.',
array(
'error' => $exception->getMessage(),
)
);
$this->redirectToDashboard(
array(
'wpcs_import_error' => $exception->getMessage(),
)
);
return;
}
$this->logger->info(
'Validated imported content package.',
@@ -59,9 +75,20 @@ final class FileImportController {
)
);
$this->redirectToDashboard(
array(
'wpcs_imported' => '1',
)
);
}
/**
* @param array<string, string> $args Redirect query args.
*/
private function redirectToDashboard( array $args ): void {
wp_safe_redirect(
add_query_arg(
array( 'wpcs_imported' => '1' ),
$args,
admin_url( 'admin.php?page=wp-content-sync' )
)
);