Skip to content

Commit 1480d03

Browse files
committed
Added to content_type_uid and uid field to references that are in the old format in audit and audit fix
1 parent 321a9a0 commit 1480d03

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

packages/contentstack-audit/src/messages/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const auditMsg = {
4040
SCAN_ASSET_SUCCESS_MSG: `Successfully completed the scanning of Asset with UID '{uid}'.`,
4141
SCAN_ASSET_WARN_MSG: `The locale '{locale}' or environment '{environment}' are not present for asset with uid '{uid}'`,
4242
ENTRY_PUBLISH_DETAILS: `Removing the publish detials for entry '{uid}' of ct '{ctuid}' in locale '{locale}' as locale '{publocale}' or environment '{environment}' does not exist`,
43-
CT_REFERENCE_FIELD: `The mentioned Reference Field is not Array field name 'reference_to' having display name 'display_name'`,
43+
CT_REFERENCE_FIELD: `The mentioned Reference field is not Array field reference is '{reference_to}' having display name '{display_name}''`,
4444
ASSET_NOT_EXIST: `The publish_details either does not exist or is not an array for asset uid '{uid}'`,
4545
ENTRY_PUBLISH_DETAILS_NOT_EXIST: `The publish_details either does not exist or is not an array for entry uid '{uid}'`,
4646
};

packages/contentstack-audit/src/modules/entries.ts

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default class Entries {
175175

176176
const localKey = this.locales.map((locale: any) => locale.code);
177177

178-
if(this.entries[entryUid]?.publish_details && !Array.isArray(this.entries[entryUid].publish_details)) {
178+
if (this.entries[entryUid]?.publish_details && !Array.isArray(this.entries[entryUid].publish_details)) {
179179
this.log($t(auditMsg.ENTRY_PUBLISH_DETAILS_NOT_EXIST, { uid: entryUid }), { color: 'red' });
180180
}
181181

@@ -194,11 +194,23 @@ export default class Entries {
194194
{ color: 'red' },
195195
);
196196
if (!Object.keys(this.missingEnvLocale).includes(entryUid)) {
197-
this.missingEnvLocale[entryUid] = [{ entry_uid: entryUid, publish_locale: pd.locale, publish_environment: pd.environment, ctUid: ctSchema.uid, ctLocale: code }];
197+
this.missingEnvLocale[entryUid] = [
198+
{
199+
entry_uid: entryUid,
200+
publish_locale: pd.locale,
201+
publish_environment: pd.environment,
202+
ctUid: ctSchema.uid,
203+
ctLocale: code,
204+
},
205+
];
198206
} else {
199-
this.missingEnvLocale[entryUid].push(
200-
{ entry_uid: entryUid, publish_locale: pd.locale, publish_environment: pd.environment, ctUid: ctSchema.uid, ctLocale: code },
201-
);
207+
this.missingEnvLocale[entryUid].push({
208+
entry_uid: entryUid,
209+
publish_locale: pd.locale,
210+
publish_environment: pd.environment,
211+
ctUid: ctSchema.uid,
212+
ctLocale: code,
213+
});
202214
}
203215
return false;
204216
}
@@ -332,7 +344,6 @@ export default class Entries {
332344
field: ContentTypeStruct | GlobalFieldDataType | ModularBlockType | GroupFieldDataType,
333345
entry: EntryFieldType,
334346
) {
335-
336347
if (this.fix) {
337348
entry = this.runFixOnSchema(tree, field.schema as ContentTypeSchemaType[], entry);
338349
}
@@ -631,18 +642,29 @@ export default class Entries {
631642
if (this.fix) return [];
632643

633644
const missingRefs: Record<string, any>[] = [];
634-
const { uid: data_type, display_name } = fieldStructure;
645+
const { uid: data_type, display_name, reference_to } = fieldStructure;
635646

636647
for (const index in field ?? []) {
637-
const reference = field[index];
648+
const reference: any = field[index];
638649
const { uid } = reference;
650+
if (!uid && reference.startsWith('blt')) {
651+
const refExist = find(this.entryMetaData, { uid: reference });
652+
if (!refExist) {
653+
if(Array.isArray(reference_to) && reference_to.length===1) {
654+
missingRefs.push({uid:reference, _content_type_uid: reference_to[0]});
655+
} else {
656+
missingRefs.push(reference);
657+
}
658+
}
659+
}
639660
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
640661
// if (this.config.skipRefs.includes(reference)) continue;
662+
else {
663+
const refExist = find(this.entryMetaData, { uid });
641664

642-
const refExist = find(this.entryMetaData, { uid });
643-
644-
if (!refExist) {
645-
missingRefs.push(reference);
665+
if (!refExist) {
666+
missingRefs.push(reference);
667+
}
646668
}
647669
}
648670

@@ -847,7 +869,7 @@ export default class Entries {
847869
* @returns
848870
*/
849871
fixSelectField(tree: Record<string, unknown>[], field: SelectFeildStruct, entry: any) {
850-
if(!this.config.fixSelectField) {
872+
if (!this.config.fixSelectField) {
851873
return entry;
852874
}
853875
const { enum: selectOptions, multiple, min_instance, display_type, display_name, uid } = field;
@@ -1197,16 +1219,29 @@ export default class Entries {
11971219
entry = JSON.parse(stringReference);
11981220
}
11991221
entry = entry
1200-
?.map((reference) => {
1222+
?.map((reference: any) => {
12011223
const { uid } = reference;
1202-
const refExist = find(this.entryMetaData, { uid });
1203-
1204-
if (!refExist) {
1205-
missingRefs.push(reference);
1206-
return null;
1224+
const { reference_to } = field;
1225+
if (!uid && reference.startsWith('blt')) {
1226+
const refExist = find(this.entryMetaData, { uid: reference });
1227+
if (!refExist) {
1228+
if(Array.isArray(reference_to) && reference_to.length===1) {
1229+
missingRefs.push({uid:reference, _content_type_uid: reference_to[0]});
1230+
} else {
1231+
missingRefs.push(reference);
1232+
}
1233+
} else {
1234+
return { uid: reference, _content_type_uid: refExist.ctUid };
1235+
}
1236+
} else {
1237+
const refExist = find(this.entryMetaData, { uid });
1238+
if (!refExist) {
1239+
missingRefs.push(reference);
1240+
return null;
1241+
} else {
1242+
return reference;
1243+
}
12071244
}
1208-
1209-
return reference;
12101245
})
12111246
.filter((val) => val) as EntryReferenceFieldDataType[];
12121247

@@ -1364,7 +1399,7 @@ export default class Entries {
13641399
`error`,
13651400
);
13661401
}
1367-
this.entryMetaData.push({ uid: entryUid, title });
1402+
this.entryMetaData.push({ uid: entryUid, title, ctUid:uid });
13681403
}
13691404
}
13701405
}

0 commit comments

Comments
 (0)