Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun migratePeople(ctx: PplContext, newAccountId: Long, pushAppId: Long, options: PushMigrationOptions): PushAppMigrationResult {
- var migratedPersons = 0L
- var migratedDestinations = 0L
- log.info("STARTING MIGRATION OF PERSONS FOR APPID $pushAppId")
- personService.forEachPersonPaged(ctx, query(pushAppId)) { person ->
- val destinations = findDestinationsForAppAndMsisdnEmail(person, pushAppId)
- personMergeService.mergePerson(pplCtx(newAccountId), person.copy(id = null, destinations = destinations.map { it.copy(id = null) }, linkedIds = null), false)
- destinations
- .filter { it.type == DestinationType.PUSH }
- .forEach { destinationService.deleteWithOptions(ctx, it._id, DeleteOneDestinationOptions(forceDeletePushDestinations = true)) }
- // delete person if all destinations were migrated
- if (person.shouldDelete(options, destinations)) {
- personService.deleteWithOptions(ctx, person._id, DeleteOnePersonOptions(forceDeletePushDestinations = true))
- }
- migratedDestinations += destinations.size
- migratedPersons++
- if ((migratedPersons % 1000) == 0L) {
- log.info("MIGRATED $migratedPersons PERSONS W $migratedDestinations DESTINATIONS")
- }
- }
- log.info("MIGRATED $migratedPersons PERSONS W $migratedDestinations DESTINATIONS FOR APPID $pushAppId")
- return PushAppMigrationResult(pushAppId, migratedPersons, migratedDestinations)
- }
Add Comment
Please, Sign In to add comment