Guest User

Untitled

a guest
Jun 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. private fun migratePeople(ctx: PplContext, newAccountId: Long, pushAppId: Long, options: PushMigrationOptions): PushAppMigrationResult {
  2. var migratedPersons = 0L
  3. var migratedDestinations = 0L
  4. log.info("STARTING MIGRATION OF PERSONS FOR APPID $pushAppId")
  5. personService.forEachPersonPaged(ctx, query(pushAppId)) { person ->
  6. val destinations = findDestinationsForAppAndMsisdnEmail(person, pushAppId)
  7. personMergeService.mergePerson(pplCtx(newAccountId), person.copy(id = null, destinations = destinations.map { it.copy(id = null) }, linkedIds = null), false)
  8. destinations
  9. .filter { it.type == DestinationType.PUSH }
  10. .forEach { destinationService.deleteWithOptions(ctx, it._id, DeleteOneDestinationOptions(forceDeletePushDestinations = true)) }
  11.  
  12. // delete person if all destinations were migrated
  13. if (person.shouldDelete(options, destinations)) {
  14. personService.deleteWithOptions(ctx, person._id, DeleteOnePersonOptions(forceDeletePushDestinations = true))
  15. }
  16.  
  17. migratedDestinations += destinations.size
  18. migratedPersons++
  19.  
  20. if ((migratedPersons % 1000) == 0L) {
  21. log.info("MIGRATED $migratedPersons PERSONS W $migratedDestinations DESTINATIONS")
  22. }
  23. }
  24. log.info("MIGRATED $migratedPersons PERSONS W $migratedDestinations DESTINATIONS FOR APPID $pushAppId")
  25. return PushAppMigrationResult(pushAppId, migratedPersons, migratedDestinations)
  26. }
Add Comment
Please, Sign In to add comment