diff --git a/app/src/main/java/website/julianrosser/birthdays/database/DatabaseHelper.java b/app/src/main/java/website/julianrosser/birthdays/database/DatabaseHelper.java index 29bdb28..0a8f7f6 100644 --- a/app/src/main/java/website/julianrosser/birthdays/database/DatabaseHelper.java +++ b/app/src/main/java/website/julianrosser/birthdays/database/DatabaseHelper.java @@ -25,6 +25,7 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.util.ArrayList; +import java.util.UUID; import website.julianrosser.birthdays.AlarmsHelper; import website.julianrosser.birthdays.BirthdayReminder; @@ -161,7 +162,11 @@ public void migrateJsonToFirebase(Context context, FirebaseUser user, MigrateUse DatabaseReference databaseReference; for (Birthday jsonBirthday : jsonbirthdays) { - Log.i("Migration", "for birthday: " + jsonBirthday.getName()); + if (jsonBirthday.getUID() == null || jsonBirthday.getUID().isEmpty()) { + jsonBirthday.setUID(UUID.randomUUID().toString()); + } + + Log.i("Migration", "for birthday: " + jsonBirthday.getName() + " // uid:" + jsonBirthday.getUID()); // Update database ref databaseReference = BirthdayReminder.getInstance().getDatabaseReference().child(user.getUid()).child(Constants.TABLE_BIRTHDAYS) diff --git a/app/src/main/java/website/julianrosser/birthdays/model/Birthday.java b/app/src/main/java/website/julianrosser/birthdays/model/Birthday.java index 0b0e0ef..311d882 100644 --- a/app/src/main/java/website/julianrosser/birthdays/model/Birthday.java +++ b/app/src/main/java/website/julianrosser/birthdays/model/Birthday.java @@ -131,6 +131,11 @@ public void setYearOfDate(int year) { } public String getUID() { + String uid = this.uID; + if (uid == null ||uid.isEmpty()) { + uid = UUID.randomUUID().toString(); + setUID(uid); + } return uID; }