diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f3e5ec5..74331fe50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image `hardisgroupcom/sfdx-hardis@beta` +## [5.4.0] 2024-11-02 + - New command hardis:org:multi-org-query allowing to execute a SOQL Bulk Query in multiple orgs and aggregate the results in a single CSV / XLS report - New command hardis:org:community:update to Activate / Deactivate communities from command line diff --git a/src/commands/hardis/org/community/update.ts b/src/commands/hardis/org/community/update.ts index 77a871746..0fd9a1708 100644 --- a/src/commands/hardis/org/community/update.ts +++ b/src/commands/hardis/org/community/update.ts @@ -1,5 +1,5 @@ import { SfCommand, Flags, requiredOrgFlagWithDeprecations } from '@salesforce/sf-plugins-core'; -import { Messages } from '@salesforce/core'; +import { Messages, SfError } from '@salesforce/core'; import { AnyJson } from '@salesforce/ts-types'; import c from 'chalk'; import { isCI, uxLog } from '../../../../common/utils/index.js'; @@ -26,13 +26,7 @@ export default class HardisOrgCommunityUpdate extends SfCommand { }), status: Flags.string({ description: 'New status for the community, available values are: Live, DownForMaintenance', - char:'s', - required: true, - }), - active: Flags.string({ - description: 'Activate or deactivate community, available values are: true, false', - char:'a', - default: true, + char: 's', required: true, }), debug: Flags.boolean({ @@ -52,65 +46,66 @@ export default class HardisOrgCommunityUpdate extends SfCommand { const conn = flags['target-org'].getConnection(); if (networkNames.length === 0) { - uxLog(this, c.red(`Error: No network name(s) provided.`)); - } else if (networkNames.length > 0) { - const networksConstraintIn = networkNames.map((networkName) => `'${networkName}'`).join(','); - const networksQuery = `SELECT Id, Name, Status FROM Network WHERE Name IN (${networksConstraintIn})`; - const networksQueryRes = await soqlQuery(networksQuery, conn); - if (debugMode) { - uxLog(this, c.grey(`Query result:\n${JSON.stringify(networksQueryRes, null, 2)}`)); - } - // Check empty result - if (networksQueryRes.length === 0) { - const outputString = `No matching network records found with given names`; + throw new SfError(`Error: No network name(s) provided.`); + } + + const networksConstraintIn = networkNames.map((networkName) => `'${networkName}'`).join(','); + const networksQuery = `SELECT Id, Name, Status FROM Network WHERE Name IN (${networksConstraintIn})`; + const networksQueryRes = await soqlQuery(networksQuery, conn); + if (debugMode) { + uxLog(this, c.grey(`Query result:\n${JSON.stringify(networksQueryRes, null, 2)}`)); + } + // Check empty result + if (networksQueryRes.length === 0) { + const outputString = `No matching network records found with given names`; + uxLog(this, c.yellow(outputString)); + return { outputString }; + } + const idToNameMap = new Map(networksQueryRes.records.map(network => [network.Id, network.Name])); + + // Request configuration from user + if (!isCI) { + const confirmUpdate = await prompts({ + type: 'confirm', + name: 'value', + initial: true, + message: c.cyanBright( + `Are you sure you want to update these ${c.bold(idToNameMap.size)} networks's status to '${status}' in org ${c.green( + flags['target-org'].getUsername() + )} (y/n)?` + ), + }); + if (confirmUpdate.value !== true) { + const outputString = 'Script cancelled by user'; uxLog(this, c.yellow(outputString)); return { outputString }; } - const idToNameMap = new Map(networksQueryRes.records.map(network => [network.Id, network.Name])); - - // Request configuration from user - if (!isCI) { - const confirmUpdate = await prompts({ - type: 'confirm', - name: 'value', - initial: true, - message: c.cyanBright( - `Are you sure you want to update these ${c.bold(idToNameMap.size)} networks's status to '${status}' in org ${c.green( - flags['target-org'].getUsername() - )} (y/n)?` - ), - }); - if (confirmUpdate.value !== true) { - const outputString = 'Script cancelled by user'; - uxLog(this, c.yellow(outputString)); - return { outputString }; - } - } + } - // Process Network update - const networkUpdates = networksQueryRes.records.map((network) => { - return { Id: network.Id, Status: status }; - }); - const updateResults = await conn.sobject("Network").update(networkUpdates, { allOrNone: false }); - let updateSuccessNb = 0; - let updateErrorsNb = 0; + // Process Network update + const networkUpdates = networksQueryRes.records.map((network) => { + return { Id: network.Id, Status: status }; + }); + const updateResults = await conn.sobject("Network").update(networkUpdates, { allOrNone: false }); + let updateSuccessNb = 0; + let updateErrorsNb = 0; - for (const ret of updateResults) { - if (ret.success) { - updateSuccessNb++; - uxLog(this, c.green(`'${c.bold(idToNameMap.get(ret.id))}' Network was updated.`)); - } else { - updateErrorsNb++; - uxLog(this, c.red(`Error ${updateErrorsNb}: Network '${idToNameMap.get(ret.id)}' failed to update: [${ret.errors[0].message}]`)); - } + for (const ret of updateResults) { + if (ret.success) { + updateSuccessNb++; + uxLog(this, c.green(`'${c.bold(idToNameMap.get(ret.id))}' Network was updated.`)); + } else { + updateErrorsNb++; + uxLog(this, c.red(`Error ${updateErrorsNb}: Network '${idToNameMap.get(ret.id)}' failed to update: [${ret.errors[0].message}]`)); } - // Return an object to be displayed with --json - return { - orgId: flags['target-org'].getOrgId(), - communityUpdatesSuccess: updateSuccessNb, - communityUpdatesErrors: updateErrorsNb, - outputString: `${updateSuccessNb} network(s) were updated`, - }; } + // Return an object to be displayed with --json + return { + orgId: flags['target-org'].getOrgId(), + communityUpdatesSuccess: updateSuccessNb, + communityUpdatesErrors: updateErrorsNb, + outputString: `${updateSuccessNb} network(s) were updated`, + }; + } }