Skip to content

Commit

Permalink
#497 | reset my groups after restoring the backup db
Browse files Browse the repository at this point in the history
this ensures that mygroups are synced according to the user and data is delted/synced according the groups synced
  • Loading branch information
vindeolal committed Aug 23, 2021
1 parent e7b4235 commit 0ce2212
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/openchs-android/src/service/BackupRestoreRealm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {EntityMetaData, EntitySyncStatus, IdentifierAssignment, UserInfo, Concept} from 'avni-models';
import {EntityMetaData, EntitySyncStatus, IdentifierAssignment, UserInfo, Concept, MyGroups} from 'avni-models';
import FileSystem from "../model/FileSystem";
import General from "../utility/General";
import fs from 'react-native-fs';
Expand Down Expand Up @@ -128,6 +128,7 @@ export default class BackupRestoreRealmService extends BaseService {
cb(97, "restoringDb");
})
.then(() => this._deleteUserInfoAndIdAssignment())
.then(() => this._deleteUserGroups())
.then(() => {
General.logDebug("BackupRestoreRealmService", "Personalisation of database complete");
cb(100, "restoreComplete");
Expand Down Expand Up @@ -168,6 +169,20 @@ export default class BackupRestoreRealmService extends BaseService {
})
});
}

_deleteUserGroups() {
const db = this.db;
const myGroups = db.objects(EntitySyncStatus.schema.name)
.filtered(`entityName = 'MyGroups'`)
.map(u => _.assign({}, u));
this.db.write(() => {
db.delete(db.objects(MyGroups.schema.name));
myGroups.forEach(({uuid, entityName, entityTypeUuid}) => {
const updatedEntity = EntitySyncStatus.create(entityName, EntitySyncStatus.REALLY_OLD_DATE, uuid, entityTypeUuid);
db.create(EntitySyncStatus.schema.name, updatedEntity, true);
})
});
}
}

export const removeBackupFile = async (backupFilePath) => {
Expand Down

0 comments on commit 0ce2212

Please sign in to comment.