From 01a08226800267906802a4dac73b5812f7b8e33b Mon Sep 17 00:00:00 2001 From: Michiel Nauta Date: Sat, 26 Mar 2011 18:52:17 +0000 Subject: [PATCH] Commit phoenix asap to fix a bug and simplify code in merge code svn: r16938 --- src/Merge/mergeevent.py | 24 +++++++++++------------- src/Merge/mergefamily.py | 16 ++++++++++++---- src/Merge/mergemedia.py | 2 +- src/Merge/mergenote.py | 2 +- src/Merge/mergeperson.py | 12 +++++------- src/Merge/mergeplace.py | 2 +- src/Merge/mergerepository.py | 2 +- src/Merge/mergesource.py | 2 +- 8 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/Merge/mergeevent.py b/src/Merge/mergeevent.py index 519f69029..04e76be26 100644 --- a/src/Merge/mergeevent.py +++ b/src/Merge/mergeevent.py @@ -212,26 +212,24 @@ class MergeEventQuery(object): self.phoenix.merge(self.titanic) with DbTxn(_("Merge Event Objects"), self.database) as trans: + self.database.commit_event(self.phoenix, trans) for person in self.database.iter_people(): if person.has_handle_reference("Event", old_handle): bri = person.birth_ref_index dri = person.death_ref_index - person.replace_handle_reference("Event", old_handle, new_handle) - if person.birth_ref_index != bri and person.birth_ref_index==-1: + person.replace_handle_reference("Event", old_handle, + new_handle) + if person.birth_ref_index != bri and \ + person.birth_ref_index == -1: for index, ref in enumerate(person.get_event_ref_list()): - if ref.ref == new_handle: - event = self.phoenix - else: - event = self.database.get_event_from_handle(ref.ref) + event = self.database.get_event_from_handle(ref.ref) if event.type.is_birth() and ref.role.is_primary(): person.birth_ref_index = index break - if person.death_ref_index != dri and person.death_ref_index==-1: + if person.death_ref_index != dri and \ + person.death_ref_index == -1: for index, ref in enumerate(person.get_event_ref_list()): - if ref.ref == new_handle: - event = self.phoenix - else: - event = self.database.get_event_from_handle(ref.ref) + event = self.database.get_event_from_handle(ref.ref) if event.type.is_death() and ref.role.is_primary(): person.death_ref_index = index break @@ -239,8 +237,8 @@ class MergeEventQuery(object): for family in self.database.iter_families(): if family.has_handle_reference("Event", old_handle): - family.replace_handle_reference("Event", old_handle, new_handle) + family.replace_handle_reference("Event", old_handle, + new_handle) self.database.commit_family(family, trans) self.database.remove_event(old_handle, trans) - self.database.commit_event(self.phoenix, trans) diff --git a/src/Merge/mergefamily.py b/src/Merge/mergefamily.py index 672923d86..49ef0d7d0 100644 --- a/src/Merge/mergefamily.py +++ b/src/Merge/mergefamily.py @@ -230,11 +230,20 @@ class MergeFamilyQuery(object): """ Create database query to merge two families. """ - def __init__(self, database, phoenix, titanic, phoenix_fh, phoenix_mh): + def __init__(self, database, phoenix, titanic, phoenix_fh=None, + phoenix_mh=None): self.database = database self.phoenix = phoenix self.titanic = titanic - self.phoenix_fh = phoenix_fh + if phoenix_fh is None: + self.phoenix_fh = self.phoenix.get_father_handle() + else: + self.phoenix_fh = phoenix_fh + if phoenix_mh is None: + self.phoenix_mh = self.phoenix.get_mother_handle() + else: + self.phoenix_mh = phoenix_mh + if self.phoenix.get_father_handle() == self.phoenix_fh: self.titanic_fh = self.titanic.get_father_handle() self.father_swapped = False @@ -242,7 +251,6 @@ class MergeFamilyQuery(object): assert self.phoenix_fh == self.titanic.get_father_handle() self.titanic_fh = self.phoenix.get_father_handle() self.father_swapped = True - self.phoenix_mh = phoenix_mh if self.phoenix.get_mother_handle() == self.phoenix_mh: self.titanic_mh = self.titanic.get_mother_handle() self.mother_swapped = False @@ -326,6 +334,7 @@ class MergeFamilyQuery(object): self.phoenix = self.database.get_family_from_handle(new_handle) self.titanic = self.database.get_family_from_handle(old_handle) self.phoenix.merge(self.titanic) + self.database.commit_family(self.phoenix, trans) for childref in self.titanic.get_child_ref_list(): child = self.database.get_person_from_handle( childref.get_reference_handle()) @@ -348,4 +357,3 @@ class MergeFamilyQuery(object): person.replace_handle_reference('Family', old_handle,new_handle) self.database.commit_person(person, trans) self.database.remove_family(old_handle, trans) - self.database.commit_family(self.phoenix, trans) diff --git a/src/Merge/mergemedia.py b/src/Merge/mergemedia.py index 4dfb836ab..2a4780020 100644 --- a/src/Merge/mergemedia.py +++ b/src/Merge/mergemedia.py @@ -186,6 +186,7 @@ class MergeMediaQuery(object): self.phoenix.merge(self.titanic) with DbTxn(_("Merge Media Objects"), self.database) as trans: + self.database.commit_media_object(self.phoenix, trans) for person in self.database.iter_people(): if person.has_media_reference(old_handle): person.replace_media_references(old_handle, new_handle) @@ -212,4 +213,3 @@ class MergeMediaQuery(object): self.database.commit_place(place, trans) self.database.remove_object(old_handle, trans) - self.database.commit_media_object(self.phoenix, trans) diff --git a/src/Merge/mergenote.py b/src/Merge/mergenote.py index ed36e8958..46a91d237 100644 --- a/src/Merge/mergenote.py +++ b/src/Merge/mergenote.py @@ -198,6 +198,7 @@ class MergeNoteQuery(object): old_handle = self.titanic.get_handle() self.phoenix.merge(self.titanic) with DbTxn(_("Merge Notes"), self.database) as trans: + self.database.commit_note(self.phoenix, trans) for person in self.database.iter_people(): if person.has_note_reference(old_handle): @@ -235,4 +236,3 @@ class MergeNoteQuery(object): self.database.commit_repository(repo, trans) self.database.remove_note(old_handle, trans) - self.database.commit_note(self.phoenix, trans) diff --git a/src/Merge/mergeperson.py b/src/Merge/mergeperson.py index d08832b93..8357b045a 100644 --- a/src/Merge/mergeperson.py +++ b/src/Merge/mergeperson.py @@ -346,7 +346,7 @@ class MergePersonQuery(object): if self.check_for_child(self.phoenix, self.titanic): raise MergeError(_("A parent and child cannot be merged. To merge " "these people, you must first break the relationship between " - "them")) + "them.")) def check_for_spouse(self, person1, person2): """Return if person1 and person2 are spouses of eachother.""" @@ -382,6 +382,7 @@ class MergePersonQuery(object): self.database.commit_person(child, trans) if self.phoenix: self.phoenix.remove_family_handle(family_handle) + self.database.commit_person(self.phoenix, trans) family_father_handle = family.get_father_handle() spouse_handle = family.get_mother_handle() if \ new_handle == family_father_handle else family_father_handle @@ -397,8 +398,7 @@ class MergePersonQuery(object): person = self.database.get_person_from_handle(person_handle) person.replace_handle_reference('Family', family_handle, main_family_handle) - if person_handle != new_handle and person_handle != old_handle: - self.database.commit_person(person, trans) + self.database.commit_person(person, trans) self.database.remove_family(family_handle, trans) self.database.commit_family(main_family, trans) @@ -420,16 +420,15 @@ class MergePersonQuery(object): old_handle = self.titanic.get_handle() self.phoenix.merge(self.titanic) + self.database.commit_person(self.phoenix, trans) for (dummy, person_handle) in self.database.find_backlink_handles( old_handle, ['Person']): person = self.database.get_person_from_handle(person_handle) assert person.has_handle_reference('Person', old_handle) person.replace_handle_reference('Person', old_handle, new_handle) - if person_handle != new_handle and person_handle != old_handle: + if person_handle != old_handle: self.database.commit_person(person, trans) - # phoenix changed and can't be determined from database nor transaction - self.phoenix.replace_handle_reference('Person', old_handle, new_handle) for family_handle in self.phoenix.get_parent_family_handle_list(): family = self.database.get_family_from_handle(family_handle) @@ -469,4 +468,3 @@ class MergePersonQuery(object): parent_list.append(parents) self.database.remove_person(old_handle, trans) - self.database.commit_person(self.phoenix, trans) diff --git a/src/Merge/mergeplace.py b/src/Merge/mergeplace.py index 9b55eedad..d464659dc 100644 --- a/src/Merge/mergeplace.py +++ b/src/Merge/mergeplace.py @@ -212,6 +212,7 @@ class MergePlaceQuery(object): self.phoenix.merge(self.titanic) with DbTxn(_("Merge Places"), self.database) as trans: + self.database.commit_place(self.phoenix, trans) for person in self.database.iter_people(): if person.has_handle_reference('Place', old_handle): person.replace_handle_reference('Place', old_handle, @@ -231,4 +232,3 @@ class MergePlaceQuery(object): self.database.commit_event(event, trans) self.database.remove_place(old_handle, trans) - self.database.commit_place(self.phoenix, trans) diff --git a/src/Merge/mergerepository.py b/src/Merge/mergerepository.py index 166b55c3a..1429b330e 100644 --- a/src/Merge/mergerepository.py +++ b/src/Merge/mergerepository.py @@ -173,9 +173,9 @@ class MergeRepoQuery(object): self.phoenix.merge(self.titanic) with DbTxn(_("Merge Repositories"), self.database) as trans: + self.database.commit_repository(self.phoenix, trans) for source in self.database.iter_sources(): if source.has_repo_reference(old_handle): source.replace_repo_references(old_handle, new_handle) self.database.commit_source(source, trans) self.database.remove_repository(old_handle, trans) - self.database.commit_repository(self.phoenix, trans) diff --git a/src/Merge/mergesource.py b/src/Merge/mergesource.py index c613a2736..d62a045e7 100644 --- a/src/Merge/mergesource.py +++ b/src/Merge/mergesource.py @@ -199,6 +199,7 @@ class MergeSourceQuery(object): self.phoenix.merge(self.titanic) with DbTxn(_("Merge Source"), self.database) as trans: + self.database.commit_source(self.phoenix, trans) for person in self.database.iter_people(): if person.has_source_reference(old_handle): person.replace_source_references(old_handle, new_handle) @@ -235,4 +236,3 @@ class MergeSourceQuery(object): self.database.commit_repository(repo, trans) self.database.remove_source(old_handle, trans) - self.database.commit_source(self.phoenix, trans)