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

Commit

Permalink
internal: implements review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Apr 1, 2020
1 parent 92414ee commit 6683876
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 25 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ Install package globally:

| Config | Value |
|-----------------|---------------------------------------------------------------------------------------------------------------------|
| projectId | Id of Kentico Kontent project (required) |
| apiKey | Content management Api key (required) |
| action | Action. Possible values are: 'restore' & 'backup' & 'clean' (required) |
| **projectId** | Id of Kentico Kontent project **(required)** |
| **apiKey** | Content management Api key **(required)** |
| **action** | Action. Possible values are: 'restore' & 'backup' & 'clean' **(required)** |
| zipFilename | Name of zip used for export / restoring data. E.g. 'kontent-backup'. |
| enableLog | Indicates if default logging is enabled (useful to indicate progress) |
| importLanguages | Indicates if languages should be imported |
| force | If enabled, project will we exported / restored even if there are data inconsistencies. This is enabled by default. |
| enableLog | Indicates if default logging is enabled (useful to indicate progress)
| force | If enabled, project will we exported / restored even if there are data inconsistencies. Enabled by default. |


### Execution
Expand Down Expand Up @@ -50,7 +49,6 @@ Create a `json` configuration file in the folder where you are attempting to run
"zipFilename": "backup",
"action": "backup",
"enableLog": true,
"importLanguages": false,
"force": true
}
```
Expand Down
10 changes: 5 additions & 5 deletions src/clean/clean.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class CleanService {
.deleteTaxonomy()
.byTaxonomyId(taxonomy.id)
.toPromise()
.then(m => {
.then(response => {
this.processItem(taxonomy.name, 'taxonomy', taxonomy);
})
.catch(error => this.handleCleanError(error));
Expand All @@ -57,7 +57,7 @@ export class CleanService {
.deleteContentTypeSnippet()
.byTypeId(contentTypeSnippet.id)
.toPromise()
.then(m => {
.then(response => {
this.processItem(contentTypeSnippet.name, 'contentTypeSnippet', contentTypeSnippet);
})
.catch(error => this.handleCleanError(error));
Expand All @@ -72,7 +72,7 @@ export class CleanService {
.deleteContentType()
.byTypeId(contentType.id)
.toPromise()
.then(m => {
.then(response => {
this.processItem(contentType.name, 'contentType', contentType);
})
.catch(error => this.handleCleanError(error));
Expand Down Expand Up @@ -128,7 +128,7 @@ export class CleanService {
.deleteContentItem()
.byItemId(contentItem.id)
.toPromise()
.then(m => {
.then(response => {
this.processItem(contentItem.name, 'contentItem', contentItem);
})
.catch(error => this.handleCleanError(error));
Expand Down Expand Up @@ -156,7 +156,7 @@ export class CleanService {
.byItemId(itemId)
.byLanguageId(languageId)
.toPromise()
.then(m => {
.then(response => {
this.processItem(itemId, 'languageVariant', languageVariant);
})
.catch(error => this.handleCleanError(error));
Expand Down
5 changes: 1 addition & 4 deletions src/cli/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const restoreAsync = async (config: ICliFileConfig) => {
enableLog: config.enableLog,
workflowIdForImportedItems: '00000000-0000-0000-0000-000000000000',
process: {
language: item => config.importLanguages === true,
contentItem: item => {
return true;
}
Expand All @@ -105,7 +104,7 @@ const restoreAsync = async (config: ICliFileConfig) => {
}
};

const validateConfig = (config: any) => {
const validateConfig = (config?: ICliFileConfig) => {
if (!config) {
throw Error(`Invalid config file`);
}
Expand Down Expand Up @@ -182,7 +181,6 @@ const getConfig = async() => {
const apiKey: string | undefined = argv.apiKey as string | undefined;
const enableLog: boolean | undefined = (argv.enableLog as boolean | undefined) ?? true;
const force: boolean | undefined = (argv.force as boolean | undefined) ?? true;
const importLanguages: boolean | undefined = (argv.importLanguages as boolean | undefined) ?? true;
const projectId: string | undefined = argv.projectId as string | undefined;
const zipFilename: string | undefined = (argv.zipFilename as string | undefined) ?? getDefaultBackupFilename()

Expand All @@ -204,7 +202,6 @@ const getConfig = async() => {
apiKey,
enableLog,
force,
importLanguages,
projectId,
zipFilename
};
Expand Down
1 change: 0 additions & 1 deletion src/cli/sample-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"zipFilename": "backup",
"action": "backup",
"enableLog": true,
"importLanguages": false,
"force": false
}
1 change: 0 additions & 1 deletion src/core/core.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface ICliFileConfig {
action: CliAction;
zipFilename: string;
enableLog: boolean;
importLanguages: boolean;
force: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion src/import/import.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface IImportAllResult {
};
}

export interface IPreparedImportItem<TItem = any> {
export interface IPreparedImportItem<TItem> {
type: ItemType;
codename: string;
item: TItem;
Expand Down
19 changes: 13 additions & 6 deletions src/import/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ManagementClient,
TaxonomyContracts,
TaxonomyModels,
SharedModels,
} from '@kentico/kontent-management';

import {
Expand All @@ -32,6 +33,11 @@ import { IBinaryFile, IImportConfig, IImportSource } from './import.models';
export class ImportService {
private readonly defaultLanguageId: string = '00000000-0000-0000-0000-000000000000';
private readonly client: IManagementClient;

/**
* Maximum allowed size of asset in Bytes.
* Currently 1e8 = 100 MB
*/
private readonly maxAllowedAssetSizeInBytes: number = 1e8;

constructor(private config: IImportConfig) {
Expand Down Expand Up @@ -75,7 +81,9 @@ export class ImportService {
if (this.config.enableLog) {
console.log(`Removing skipped items`);
}
// once ids are translated, remove skipped items from import

// this is an optional step where users can exclude certain objects from being
// imported via import configuration.
this.removeSkippedItemsFromImport(sourceData);

if (this.config.enableLog) {
Expand Down Expand Up @@ -417,7 +425,7 @@ export class ImportService {
>[] = [];

for (const contentType of contentTypes) {
const createdContentType = await this.client
await this.client
.addContentType()
.withData(builder => {
return contentType;
Expand Down Expand Up @@ -540,8 +548,7 @@ export class ImportService {
>[] = [];

for (const contentTypeSnippet of contentTypeSnippets) {
// not yet processed ones
const createdContentTypeSnippet = await this.client
await this.client
.addContentTypeSnippet()
.withData(builder => {
return {
Expand Down Expand Up @@ -591,9 +598,9 @@ export class ImportService {
return importedItems;
}

private handleImportError(error: any): void {
private handleImportError(error: any | SharedModels.ContentManagementBaseKontentError): void {
console.log(error);
throw Error(error);
throw error;
}

private processItem(title: string, type: ItemType, data: any): void {
Expand Down
Empty file removed src/services/index.ts
Empty file.
4 changes: 4 additions & 0 deletions src/zip/zip.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export class ZipService {
return binaryFiles;
}

/**
* Gets path to asset within zip folder. Uses tree format using asset ids such as:
* "files/3b4/3b42f36c-2e67-4605-a8d3-fee2498e5224/image.jpg"
*/
private getFullAssetPath(assetId: string, filename: string): string {
return `${this.filesName}/${assetId.substr(0, 3)}/${assetId}/${filename}`;
}
Expand Down

0 comments on commit 6683876

Please sign in to comment.