Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions docs/CONTENT-ITEM.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,17 @@ If no `id` is provided, all content items in all content repositories in the spe

#### Options

| Option | Alias | Description |
| -------------------- | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--destinationHubId` | | The destination hub ID to sync the content item with |
| `--repoId` | | The ID of a content repository to restrict sync scope. _(Optional)_ |
| `--folderId` | | The ID of a folder to restrict sync scope. _(Optional)_ |
| `--facet` | | Filter content using facets. Format: <br>`label:example name,locale:en-GB` <br>Regex supported with `/pattern/`. <br>See README for more examples. |
| `-f`, `--force` | | Skip confirmation prompts before sync. |
| `-s`, `--silent` | | Disable log file creation. |
| `--logFile` | | Path to write the log file. <br>Default: `(log_filename)` |
| Option | Alias | Description |
| -------------------------- | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--destinationHubId` | | The destination hub ID to sync the content item with |
| `--repoId` | | The ID of a content repository to restrict sync scope. _(Optional)_ |
| `--folderId` | | The ID of a folder to restrict sync scope. _(Optional)_ |
| `--facet` | | Filter content using facets. Format: <br>`label:example name,locale:en-GB` <br>Regex supported with `/pattern/`. <br>See README for more examples. |
| `-f`, `--force` | | Skip confirmation prompts before sync. |
| `-s`, `--silent` | | Disable log file creation. |
| `--logFile` | | Path to write the log file. <br>Default: `(log_filename)` |
| `--ignoreSchemaValidation` | | Ignore schema validation when syncing content items. _(Optional)_ |
| `--forceSync` | | Sync destination content item when modified (overwrite destination modifications). _(Optional)_ |

---

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"bottleneck": "2.19.5",
"chalk": "2.4.2",
"cli-progress": "3.12.0",
"dc-management-sdk-js": "3.2.0",
"dc-management-sdk-js": "3.3.0",
"enquirer": "2.3.6",
"fs-extra": "10.1.0",
"graceful-fs": "4.2.11",
Expand Down
14 changes: 10 additions & 4 deletions src/commands/content-item/sync.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('sync.service', () => {
});
describe('ContentItemSyncService', () => {
describe('sync', () => {
it('should add a content item sync job to the queue and process the queue item', async () => {
it('should add a content item sync job to the queue and process the queue item (with sync options enabled)', async () => {
const JOB_ID = '68e5289f0aba3024bde050f9';
const DEST_HUB_ID = '67d2a201642fa239dbe1523d';
const CONTENT_ITEM_ID = 'c5b659df-680e-4711-bfbe-84eaa10d76cc';
Expand All @@ -22,11 +22,15 @@ describe('sync.service', () => {
hub.related.jobs.get.mockResolvedValue(new Job({ id: JOB_ID, status: 'COMPLETED' }));

const syncService = new ContentItemSyncService();
syncService.sync(DEST_HUB_ID, hub as unknown as Hub, contentItem, () => {});
syncService.sync(DEST_HUB_ID, hub as unknown as Hub, contentItem, () => {}, {
ignoreSchemaValidation: true,
forceSync: true
});
await syncService.onIdle();

expect(hub.related.jobs.createDeepSyncJob).toHaveBeenCalledWith({
label: `dc-cli content item: sync service test`,
forceSync: true,
ignoreSchemaValidation: true,
destinationHubId: DEST_HUB_ID,
input: { rootContentItemIds: [CONTENT_ITEM_ID] }
Expand All @@ -47,11 +51,12 @@ describe('sync.service', () => {
.mockResolvedValueOnce(new Job({ id: JOB_ID, status: 'COMPLETED' }));

const syncService = new ContentItemSyncService();
syncService.sync(DEST_HUB_ID, hub as unknown as Hub, contentItem, () => {});
syncService.sync(DEST_HUB_ID, hub as unknown as Hub, contentItem, () => {}, {});
await syncService.onIdle();

expect(hub.related.jobs.createDeepSyncJob).toHaveBeenCalledWith({
label: `dc-cli content item: sync service test`,
forceSync: false,
ignoreSchemaValidation: true,
destinationHubId: DEST_HUB_ID,
input: { rootContentItemIds: [CONTENT_ITEM_ID] }
Expand All @@ -70,11 +75,12 @@ describe('sync.service', () => {
hub.related.jobs.get.mockResolvedValueOnce(new Job({ id: JOB_ID, status: 'FAILED' }));

const syncService = new ContentItemSyncService();
syncService.sync(DEST_HUB_ID, hub as unknown as Hub, contentItem, () => {});
syncService.sync(DEST_HUB_ID, hub as unknown as Hub, contentItem, () => {}, {});
await syncService.onIdle();

expect(hub.related.jobs.createDeepSyncJob).toHaveBeenCalledWith({
label: `dc-cli content item: sync service test`,
forceSync: false,
ignoreSchemaValidation: true,
destinationHubId: DEST_HUB_ID,
input: { rootContentItemIds: [CONTENT_ITEM_ID] }
Expand Down
11 changes: 9 additions & 2 deletions src/commands/content-item/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ export class ContentItemSyncService {
this.queue = new BurstableQueue({ concurrency: 1 });
}

sync(destinationHubId: string, hub: Hub, contentItem: ContentItem, action: (job: Job) => void): void {
sync(
destinationHubId: string,
hub: Hub,
contentItem: ContentItem,
action: (job: Job) => void,
options: { ignoreSchemaValidation?: boolean; forceSync?: boolean }
): void {
this.queue.add(async () => {
const createSyncJob = await hub.related.jobs.createDeepSyncJob(
new CreateDeepSyncJobRequest({
label: `dc-cli content item: ${contentItem.label}`,
ignoreSchemaValidation: true,
ignoreSchemaValidation: options.ignoreSchemaValidation ?? true,
forceSync: options.forceSync || false,
destinationHubId,
input: { rootContentItemIds: [contentItem.id] }
})
Expand Down
20 changes: 18 additions & 2 deletions src/commands/content-item/sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ describe('content-item sync', () => {
requiresArg: true,
demandOption: true
});

expect(spyOption).toHaveBeenCalledWith('ignoreSchemaValidation', {
type: 'boolean',
boolean: true,
describe: 'Ignore schema validation when syncing content items.'
});

expect(spyOption).toHaveBeenCalledWith('forceSync', {
type: 'boolean',
boolean: true,
describe: 'Sync destination content item when modified (overwrite destination modifications).'
});
});
});

Expand Down Expand Up @@ -149,6 +161,8 @@ describe('content-item sync', () => {
...globalArgs,
id: CONTENT_ITEM_ID,
destinationHubId: DEST_HUB_ID,
ignoreSchemaValidation: true,
forceSync: true,
logFile: mockLog
});

Expand All @@ -158,7 +172,8 @@ describe('content-item sync', () => {
DEST_HUB_ID,
expect.any(Hub),
expect.any(ContentItem),
expect.any(Function)
expect.any(Function),
{ forceSync: true, ignoreSchemaValidation: true }
);
});
it('should sync content items by query', async () => {
Expand Down Expand Up @@ -200,7 +215,8 @@ describe('content-item sync', () => {
DEST_HUB_ID,
expect.any(Hub),
expect.any(ContentItem),
expect.any(Function)
expect.any(Function),
{ forceSync: undefined, ignoreSchemaValidation: undefined }
);
});
});
Expand Down
40 changes: 30 additions & 10 deletions src/commands/content-item/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ export const builder = (yargs: Argv): void => {
describe: 'The ID of a destination hub to sync with.',
requiresArg: true,
demandOption: true
})
.option('ignoreSchemaValidation', {
type: 'boolean',
boolean: true,
describe: 'Ignore schema validation when syncing content items.'
})

.option('forceSync', {
type: 'boolean',
boolean: true,
describe: 'Sync destination content item when modified (overwrite destination modifications).'
});
};

Expand All @@ -77,10 +88,13 @@ export default interface SyncOptions {
force?: boolean;
silent?: boolean;
destinationHubId: string;
ignoreSchemaValidation?: boolean;
forceSync?: boolean;
}

export const handler = async (argv: Arguments<SyncOptions & ConfigurationParameters>): Promise<void> => {
const { id, logFile, force, silent, hubId, repoId, folderId, destinationHubId } = argv;
const { id, logFile, force, silent, hubId, repoId, folderId, destinationHubId, ignoreSchemaValidation, forceSync } =
argv;
const log = logFile.open();
const client = dynamicContentClientFactory(argv);
const facet = withOldFilters(argv.facet, argv);
Expand Down Expand Up @@ -143,15 +157,21 @@ export const handler = async (argv: Arguments<SyncOptions & ConfigurationParamet

dedupedContentItems.forEach(contentItem => {
log.addComment(`Requesting content item sync: ${contentItem.label}`);
syncService.sync(destinationHubId, hub, contentItem, (syncJob: Job) => {
progress.increment();
const logComment =
syncJob.status === 'FAILED'
? `Failed content item sync job ${syncJob.id}: ${JSON.stringify(syncJob.errors)}`
: `Content item synced: ${contentItem.label} (jobId: ${syncJob.id})`;

log.addComment(logComment);
});
syncService.sync(
destinationHubId,
hub,
contentItem,
(syncJob: Job) => {
progress.increment();
const logComment =
syncJob.status === 'FAILED'
? `Failed content item sync job ${syncJob.id}: ${JSON.stringify(syncJob.errors)}`
: `Content item synced: ${contentItem.label} (jobId: ${syncJob.id})`;

log.addComment(logComment);
},
{ ignoreSchemaValidation, forceSync }
);
});

await syncService.onIdle();
Expand Down
Loading