From f758557ca31fb66276bcd4aa8c58b05aec3af5fc Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Wed, 30 Aug 2006 05:10:50 +0000 Subject: [PATCH] * src/GrampsDb/_GrampsDbBase.py (remove_person,_do_remove_object): Properly delete objects; (get_del_func): Add method to find deleting function for an object. * src/plugins/Check.py (cleanup_empty_families): Report gramps id. svn: r7292 --- ChangeLog | 4 ++++ src/GrampsDb/_GrampsDbBase.py | 40 ++++++++++++++++++++++++++--------- src/plugins/Check.py | 7 +++--- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index bafa951d8..c09d7d613 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ 2006-08-29 Alex Roitman + * src/GrampsDb/_GrampsDbBase.py (remove_person,_do_remove_object): + Properly delete objects; + (get_del_func): Add method to find deleting function for an object. + * src/plugins/Check.py (cleanup_empty_families): Report gramps id. * src/RelLib/_SourceRef.py (SourceRef.__init__): Pass source. * src/RelLib/_ChildRef.py (ChildRef.__init__): Pass source. * src/RelLib/_EventRef.py (EventRef.__init__): Pass source. diff --git a/src/GrampsDb/_GrampsDbBase.py b/src/GrampsDb/_GrampsDbBase.py index 99eebbc53..704cfa38d 100644 --- a/src/GrampsDb/_GrampsDbBase.py +++ b/src/GrampsDb/_GrampsDbBase.py @@ -1700,21 +1700,41 @@ class GrampsDbBase(GrampsDBCallback): method must be overridden in the derived class. """ + if self.readonly or not handle: + return self._delete_primary_from_reference_map(handle, transaction) - if not self.readonly: - person = self.get_person_from_handle(handle) - self.genderStats.uncount_person (person) - if not transaction.batch: - transaction.add(PERSON_KEY, handle, person.serialize(), None) + person = self.get_person_from_handle(handle) + self.genderStats.uncount_person (person) + if transaction.batch: + self._del_person(handle) + else: + transaction.add(PERSON_KEY, handle, person.serialize(), None) transaction.person_del.append(str(handle)) + def get_del_func(self,key): + key2del = { + PERSON_KEY: self._del_person, + FAMILY_KEY: self._del_family, + SOURCE_KEY: self._del_source, + EVENT_KEY: self._del_event, + MEDIA_KEY: self._del_media, + PLACE_KEY: self._del_place, + REPOSITORY_KEY: self._del_repository, + } + return key2del[key] + def _do_remove_object(self, handle, trans, dmap, key, del_list): + if self.readonly or not handle: + return + + handle = str(handle) self._delete_primary_from_reference_map(handle, trans) - if not self.readonly: - handle = str(handle) - if not trans.batch: - old_data = dmap.get(handle) - trans.add(key, handle, old_data, None) + if trans.batch: + del_func = self.get_del_func(key) + del_func(handle) + else: + old_data = dmap.get(handle) + trans.add(key, handle, old_data, None) del_list.append(handle) def remove_source(self, handle, transaction): diff --git a/src/plugins/Check.py b/src/plugins/Check.py index f50f63e88..d5706adea 100644 --- a/src/plugins/Check.py +++ b/src/plugins/Check.py @@ -510,11 +510,12 @@ class CheckIntegrity: self.progress.step() family = self.db.get_family_from_handle(family_handle) + family_id = family.get_gramps_id() father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() if not father_handle and not mother_handle: - self.empty_family.append(family_handle) + self.empty_family.append(family_id) self.delete_empty_family(family_handle) continue elif not father_handle and len(family.get_child_ref_list()) == 0: @@ -522,14 +523,14 @@ class CheckIntegrity: person.remove_family_handle(family_handle) self.db.commit_person(person,self.trans) self.db.remove_family(family_handle,self.trans) - self.empty_family.append(family_handle) + self.empty_family.append(family_id) continue elif not mother_handle and len(family.get_child_ref_list()) == 0: person = self.db.get_person_from_handle(father_handle) person.remove_family_handle(family_handle) self.db.commit_person(person,self.trans) self.db.remove_family(family_handle,self.trans) - self.empty_family.append(family_handle) + self.empty_family.append(family_id) continue def delete_empty_family(self,family_handle):