Skip to content

Commit

Permalink
#624 - subject migration was not getting marked as migrated for the f…
Browse files Browse the repository at this point in the history
…irst time.
  • Loading branch information
petmongrels committed Oct 20, 2023
1 parent c376984 commit 0db49d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions packages/openchs-android/src/service/SubjectMigrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ class SubjectMigrationService extends BaseService {
}

migrateSubjects(notifyProgress) {
if (this.getCount(Individual.schema.name) === 0)
return;

const length = this.findAll().filtered('hasMigrated = false').length;
const individualCount = this.getCount(Individual.schema.name);
const nothingToMigrate = individualCount === 0;
for (let i = 0; i < length; i++) {
const subjectMigration = this.findAll().filtered('hasMigrated = false limit(1)')[0];
const handle = setTimeout(() => {
if (nothingToMigrate) {
this.markMigrated(subjectMigration);
} else {
this.migrateSubjectIfRequired(subjectMigration);
}
const handle = setTimeout(() => {
notifyProgress("SubjectMigration", length, i);
clearTimeout(handle);
}, 1);
}, 50);
}
}

Expand Down Expand Up @@ -195,14 +198,14 @@ class SubjectMigrationService extends BaseService {
const addressLevelService = this.getService(AddressLevelService);
const userInfoService = this.getService(UserInfoService);
const subjectType = this.getService(SubjectTypeService).findByUUID(subjectMigration.subjectTypeUUID);
const syncConcept1Values = userInfoService.getSyncConcept1Values(subjectType);
const syncConcept2Values = userInfoService.getSyncConcept2Values(subjectType);
const userSyncConcept1Values = userInfoService.getSyncConcept1Values(subjectType);
const userSyncConcept2Values = userInfoService.getSyncConcept2Values(subjectType);
const oldAddressExists = addressLevelService.existsByUuid(subjectMigration.oldAddressLevelUUID);
const newAddressExists = addressLevelService.existsByUuid(subjectMigration.newAddressLevelUUID);
const oldSyncConcept1ValueExists = _.includes(syncConcept1Values, subjectMigration.oldSyncConcept1Value);
const newSyncConcept1ValueExists =_.includes(syncConcept1Values, subjectMigration.newSyncConcept1Value);
const oldSyncConcept2ValueExists = _.includes(syncConcept2Values, subjectMigration.oldSyncConcept2Value);
const newSyncConcept2ValueExists = _.includes(syncConcept2Values, subjectMigration.newSyncConcept2Value);
const oldSyncConcept1ValueExists = _.includes(userSyncConcept1Values, subjectMigration.oldSyncConcept1Value);
const newSyncConcept1ValueExists =_.includes(userSyncConcept1Values, subjectMigration.newSyncConcept1Value);
const oldSyncConcept2ValueExists = _.includes(userSyncConcept2Values, subjectMigration.oldSyncConcept2Value);
const newSyncConcept2ValueExists = _.includes(userSyncConcept2Values, subjectMigration.newSyncConcept2Value);

if ((oldAddressExists && !newAddressExists) ||
(oldSyncConcept1ValueExists && !newSyncConcept1ValueExists) ||
Expand All @@ -211,6 +214,10 @@ class SubjectMigrationService extends BaseService {
this.removeEntitiesFor(subjectMigration);
}

this.markMigrated(subjectMigration);
}

markMigrated(subjectMigration) {
const db = this.db;
db.write(() => {
subjectMigration.hasMigrated = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/openchs-android/src/service/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class SyncService extends BaseService {
this.getService(UserSubjectAssignmentService).deleteUnassignedSubjectsAndDependents(entities);
}

General.logDebugTemp("SyncService", `${entityMetaData.entityName} ${entityMetaData.syncStatus.entityTypeUuid}`);
General.logDebug("SyncService", `Syncing - ${entityMetaData.entityName} with subType: ${entityMetaData.syncStatus.entityTypeUuid}`);
const currentEntitySyncStatus = this.entitySyncStatusService.get(entityMetaData.entityName, entityMetaData.syncStatus.entityTypeUuid);
const entitySyncStatus = new EntitySyncStatus();
entitySyncStatus.entityName = entityMetaData.entityName;
Expand Down

0 comments on commit 0db49d2

Please sign in to comment.