Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

Commit 2e91203

Browse files
fix(profile): add ability to reset cache when the command is executed against an org multiple times
The PR adds an additional flag --resetcache to merge/reconcile which provides ability to reset cache as required among subsequent runs fixes #1413
1 parent f28b47f commit 2e91203

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

packages/sfpowerscripts-cli/messages/profile_merge.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"folderFlagDescription": "comma separated list of folders to scan for profiles. If ommited, the folders in the packageDirectories configuration will be used.",
44
"profileListFlagDescription": "comma separated list of profiles. If ommited, all the profiles found in the folder(s) will be merged",
55
"metadataFlagDescription": "comma separated list of metadata for which the permissions will be retrieved.",
6-
"deleteFlagDescription": "set this flag to delete profile files that does not exist in the org."
6+
"deleteFlagDescription": "set this flag to delete profile files that does not exist in the org.",
7+
"resetCacheFlagDescription": "set this flag to reset the cache and retrieve the latest profile permissions from the org."
78
}

packages/sfpowerscripts-cli/messages/profile_reconcile.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"nameFlagDescription": "list of profiles to be reconciled. If ommited, all the profiles components will be reconciled.",
55
"destFolderFlagDescription": " the destination folder for reconciled profiles, if omitted existing profiles will be reconciled and will be rewritten in the current location",
66
"sourceonlyFlagDescription": "set this flag to reconcile profiles only against component available in the project only. Configure ignored perissions in sfdx-project.json file in the array plugins->sfpowerkit->ignoredPermissions.",
7-
"targetorgFlagDescription": " org against which profiles will be reconciled. this parameter can be ommited if sourceonly flag is set."
7+
"targetorgFlagDescription": " org against which profiles will be reconciled. this parameter can be ommited if sourceonly flag is set.",
8+
"resetCacheFlagDescription": "set this flag to reset the cache and retrieve the latest profile permissions from the org."
89
}

packages/sfpowerscripts-cli/src/commands/profile/merge.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export default class Merge extends SfpowerscriptsCommand {
4444
description: messages.getMessage('deleteFlagDescription'),
4545
required: false,
4646
}),
47+
resetcache: Flags.boolean({
48+
description: messages.getMessage('resetCacheFlagDescription'),
49+
required: false,
50+
}),
4751
targetorg: requiredUserNameFlag,
4852
'apiversion': orgApiVersionFlagSfdxStyle,
4953
loglevel,
@@ -60,15 +64,7 @@ export default class Merge extends SfpowerscriptsCommand {
6064
let argProfileList = this.flags.profilelist;
6165
let argMetadatas = this.flags.metadata;
6266

63-
// argMetadatas = (val: string) => {
64-
// let parts = val.split(':');
65-
// return {
66-
// MetadataType: parts[0].trim(),
67-
// ApiName: parts.length >= 2 ? parts[1].trim() : '*',
68-
// };
69-
// };
70-
71-
Sfpowerkit.initCache();
67+
Sfpowerkit.initCache(this.flags.resetcache);
7268

7369
let metadatas = undefined;
7470
let invalidArguments = [];

packages/sfpowerscripts-cli/src/commands/profile/reconcile.ts

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export default class Reconcile extends SfpowerscriptsCommand {
4949
description: messages.getMessage('sourceonlyFlagDescription'),
5050
required: false,
5151
}),
52+
resetcache: Flags.boolean({
53+
description: messages.getMessage('resetCacheFlagDescription'),
54+
required: false,
55+
}),
5256
targetorg: requiredUserNameFlag,
5357
'apiversion': orgApiVersionFlagSfdxStyle,
5458
loglevel,
@@ -67,6 +71,7 @@ export default class Reconcile extends SfpowerscriptsCommand {
6771
public async execute(): Promise<Array<{state: any, fullName: any, type: any, path: any}>> {
6872
let argFolder = this.flags.folder;
6973
let argProfileList = this.flags.profilelist;
74+
Sfpowerkit.initCache(this.flags.resetcache);
7075

7176
if (!this.flags.sourceonly) {
7277
if (_.isNil(this.flags.targetorg)) {

packages/sfpowerscripts-cli/src/commands/profile/retrieve.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class Retrieve extends SfpowerscriptsCommand {
6565
folders.push(...argFolder);
6666
}
6767

68-
Sfpowerkit.initCache();
68+
Sfpowerkit.initCache(true);
6969

7070
SFPLogger.log(COLOR_WARNING(messages.getMessage('retriveDelayWarning')),LoggerLevel.INFO);
7171
SFPLogger.log(COLOR_KEY_MESSAGE(`Retrieving profiles from ${this.flags.targetorg}`),LoggerLevel.INFO );

packages/sfprofiles/src/utils/sfpowerkit.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ export class Sfpowerkit {
3030
fs.unlinkSync(cachePath);
3131
}
3232

33-
public static initCache() {
33+
public static initCache(resetCache?:boolean) {
3434
try {
35+
if(resetCache)
36+
Sfpowerkit.resetCache();
3537
//Set the cache path on init,
3638
//TODO: Move this to a temporary directory with randomization
3739
Sfpowerkit.cache = new SQLITEKeyValue(FileUtils.getLocalCachePath('sfpowerkit-cache.db'));

0 commit comments

Comments
 (0)