Skip to content

Commit

Permalink
ensure that users migrating from old JSON birthdays are assigned UIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Julesssss committed Feb 27, 2018
1 parent 3f1cc16 commit cd6110b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit cd6110b

Please sign in to comment.