diff --git a/packages/core/data-transfer/src/engine/index.ts b/packages/core/data-transfer/src/engine/index.ts index 1706fd1df6..821beefb9c 100644 --- a/packages/core/data-transfer/src/engine/index.ts +++ b/packages/core/data-transfer/src/engine/index.ts @@ -27,6 +27,7 @@ import type { SchemaDiffHandler, SchemaDiffHandlerContext, AssetsBackupErrorHandler, + AssetsBackupErrorHandlerContext, } from '../../types'; import type { Diff } from '../utils/json'; @@ -749,9 +750,20 @@ class TransferEngine< async beforeTransfer(): Promise { const runWithDiagnostic = async (provider: IProvider) => { + const context: AssetsBackupErrorHandlerContext = {}; + try { await provider.beforeTransfer?.(); } catch (error) { + await utils.middleware.runMiddleware( + context, + this.#handlers.assetsBackupError + ); + console.log('context', context); + if (context.ignore) { + console.log('Entering here'); + return; + } // Error happening during the before transfer step should be considered fatal errors if (error instanceof Error) { this.panic(error); diff --git a/packages/core/data-transfer/types/transfer-engine.d.ts b/packages/core/data-transfer/types/transfer-engine.d.ts index e486611fb3..d4d7170e0d 100644 --- a/packages/core/data-transfer/types/transfer-engine.d.ts +++ b/packages/core/data-transfer/types/transfer-engine.d.ts @@ -18,7 +18,11 @@ export type SchemaDiffHandlerContext = { }; export type SchemaDiffHandler = Middleware; -export type AssetsBackupErrorHandler = Middleware; +export type AssetsBackupErrorHandlerContext = { + ignore?: boolean; +}; + +export type AssetsBackupErrorHandler = Middleware; /** * Defines the capabilities and properties of the transfer engine diff --git a/packages/core/strapi/lib/commands/utils/data-transfer.js b/packages/core/strapi/lib/commands/utils/data-transfer.js index d957497147..103112f854 100644 --- a/packages/core/strapi/lib/commands/utils/data-transfer.js +++ b/packages/core/strapi/lib/commands/utils/data-transfer.js @@ -349,16 +349,19 @@ const getAssetsBackupHandler = (engine, { force, action }) => { exitWith(1, exitMessageText(action, true)); }); - await confirmMessage( - 'There are differences in schema between the source and destination, and the data listed above will be lost. Are you sure you want to continue?', + const confirmed = await confirmMessage( + 'The backup folder for the assets could not be created inside the public folder. Maybe Strapi does not have write permissions on the public directory. Do you want to continue without the backup?', { force, } ); + if (confirmed) { + context.ignore = true; + } + // reset handler back to normal setSignalHandler(() => abortTransfer({ engine, strapi })); - return next(context); }; };