Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
fix: fixes error when restoring backup created with skipped validatio…
Browse files Browse the repository at this point in the history
…n endpoint
  • Loading branch information
Enngage committed Jul 12, 2022
1 parent 5817112 commit 2652531
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/export/export.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export interface IExportData {
export interface IExportAllResult {
metadata: IPackageMetadata;
data: IExportData;
validation: ProjectContracts.IProjectReportResponseContract | undefined;
validation: ProjectContracts.IProjectReportResponseContract | string;
}
9 changes: 5 additions & 4 deletions lib/export/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ export class ExportService {
workflowSteps: this.config.exportFilter?.includes('workflowStep') ?? true
};

let projectValidation: undefined | ProjectContracts.IProjectReportResponseContract;
let projectValidation: string | ProjectContracts.IProjectReportResponseContract;
let isInconsistentExport: boolean = false;

if (!this.config.skipValidation) {
projectValidation = await this.exportProjectValidationAsync();
isInconsistentExport = projectValidation.type_issues.length > 0 || projectValidation.variant_issues.length > 0;
console.log(`Project validation - ${projectValidation.type_issues.length} type issues, ${projectValidation.variant_issues.length} variant issues`);
} else {
projectValidation = '{}';
console.log('Skipping project validation endpoint');
}

Expand Down Expand Up @@ -80,9 +83,7 @@ export class ExportService {
version,
timestamp: new Date(),
projectId: this.config.projectId,
isInconsistentExport: projectValidation
? projectValidation.type_issues.length > 0 || projectValidation.variant_issues.length > 0
: false,
isInconsistentExport: isInconsistentExport,
dataOverview: {
assetFoldersCount: data.assetFolders.length,
assetsCount: data.assets.length,
Expand Down
26 changes: 7 additions & 19 deletions lib/node/cli/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ICliFileConfig, getFilenameWithoutExtension, CliAction, ItemType } from
import { ExportService } from '../../export';
import { IImportSource, ImportService } from '../../import';
import { ZipService } from '../../zip';
import { ProjectContracts, SharedModels } from '@kentico/kontent-management';
import { SharedModels } from '@kentico/kontent-management';
import { FileService } from '../file/file.service';
import { fileHelper } from '../file/file-helper';

Expand Down Expand Up @@ -78,17 +78,13 @@ const backupAsync = async (config: ICliFileConfig) => {

const response = await exportService.exportAllAsync();

const validation = response.validation;

if (validation) {
if (exportContainsInconsistencies(validation)) {
const logFilename: string = getLogFilename(config.zipFilename);
if (response.metadata.isInconsistentExport) {
const logFilename: string = getLogFilename(config.zipFilename);

console.log(`Project contains inconsistencies which may cause errors during project import.`);
console.log(`See '${logFilename}' for more details.`);
} else {
console.log(`Project does not contain any inconsistencies`);
}
console.log(`Project contains inconsistencies which may cause errors during project import.`);
console.log(`See '${logFilename}' for more details.`);
} else {
console.log(`Project does not contain any inconsistencies`);
}

const zipFileData = await zipService.createZipAsync(response);
Expand Down Expand Up @@ -206,14 +202,6 @@ const run = async () => {
}
};

const exportContainsInconsistencies = (projectReport: ProjectContracts.IProjectReportResponseContract) => {
if (projectReport.variant_issues.length > 0 || projectReport.type_issues.length > 0) {
return true;
}

return false;
};

const canImport = (importData: IImportSource, config: ICliFileConfig) => {
if (!importData.metadata.isInconsistentExport) {
return true;
Expand Down

0 comments on commit 2652531

Please sign in to comment.