Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into doc
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Nov 19, 2023
2 parents ce5f1d5 + a16b58c commit 54d7647
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/linters/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@
"removedonly",
"removepackagexml",
"reportfile",
"resetpassword",
"resetsave",
"resetselection",
"resultformat",
Expand Down
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image `hardisgroupcom/sfdx-hardis@beta`

## [4.12.3] 2023-11-18

- Monitoring: Update default **package-skip-items.xml**
- **hardis:org:diagnose:audittrail** enhancements:
- Add PerSetUnassign in not suspect monitored actions in Setup Audit Trail
Expand All @@ -17,6 +15,7 @@ Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image
- Add it by default in the monitoring commands
- Doc
- Update contributing infos (use `sf plugins link`)
- **hardis:files:export** : Make the command compliant with Email attachments

## [4.12.2] 2023-11-15

Expand Down
29 changes: 21 additions & 8 deletions src/common/utils/filesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,37 @@ export class FilesExporter {
this.totalSoqlRequests++;
const contentVersions = await bulkQuery(contentVersionSoql, this.conn);

// ContentDocument object can be linked to multiple other objects even with same type (for example: same attachment can be linked to multiple EmailMessage objects).
// Because of this when we fetch ContentVersion for ContentDocument it can return less results than there is ContentDocumentLink objects to link.
// To fix this we create a list of ContentVersion and ContentDocumentLink pairs.
// This way we have multiple pairs and we will download ContentVersion objects for each linked object.
const versionsAndLinks = []
contentVersions.records.forEach(contentVersion => {
contentDocumentLinks.records.forEach(contentDocumentLink => {
if (contentDocumentLink.ContentDocumentId === contentVersion.ContentDocumentId) {
versionsAndLinks.push({
contentVersion: contentVersion,
contentDocumentLink: contentDocumentLink,
});
}
});
});

// Download files
await PromisePool.withConcurrency(5)
.for(contentVersions.records)
.process(async (contentVersion: any) => {
.for(versionsAndLinks)
.process(async (versionAndLink: any) => {
try {
await this.downloadContentVersionFile(contentVersion, records, contentDocumentLinks.records);
await this.downloadContentVersionFile(versionAndLink.contentVersion, records, versionAndLink.contentDocumentLink);
} catch (e) {
this.filesErrors++;
uxLog(this, c.red("Download file error: " + contentVersion.Title + "\n" + e));
uxLog(this, c.red("Download file error: " + versionAndLink.contentVersion.Title + "\n" + e));
}
});
}

private async downloadContentVersionFile(contentVersion, records, contentDocumentLinks) {
private async downloadContentVersionFile(contentVersion, records, contentDocumentLink) {
// Retrieve initial record to build output files folder name
const contentDocumentLink = contentDocumentLinks.filter(
(contentDocumentLink) => contentDocumentLink.ContentDocumentId === contentVersion.ContentDocumentId,
)[0];
const parentRecord = records.filter((record) => record.Id === contentDocumentLink.LinkedEntityId)[0];
// Build record output files folder (if folder name contains slashes or antislashes, replace them by spaces)
const parentFolderName = (parentRecord[this.dtl.outputFolderNameField] || parentRecord.Id).replace(/[/\\?%*:|"<>]/g, "-");
Expand Down

0 comments on commit 54d7647

Please sign in to comment.