fix: handle invalid package uploads
This commit is contained in:
@@ -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' )
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user