diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index e1b67aef6..802472c26 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,7 @@ +2005-03-30 Martin Hawlisch + * plugins/TestcaseGenerator.py: Added some more testcases of invalid relations + * plugins/Check.py: Added some comments an handling for some more invalid references + 2005-03-29 Don Allingham * src/ReadXML.py: handle date object on names * src/gramps.glade: add menu items for merging diff --git a/gramps2/src/plugins/Check.py b/gramps2/src/plugins/Check.py index 07377e673..7e9477f42 100644 --- a/gramps2/src/plugins/Check.py +++ b/gramps2/src/plugins/Check.py @@ -93,6 +93,7 @@ class CheckIntegrity: def check_for_broken_family_links(self): self.broken_links = [] + # Check persons referenced by the family objects for family_handle in self.db.get_family_handles(): family = self.db.get_family_from_handle(family_handle) father_handle = family.get_father_handle() @@ -100,6 +101,7 @@ class CheckIntegrity: if father_handle: father = self.db.get_person_from_handle(father_handle) if not father: + # The person referenced by the father handle does not exist in the database family.set_father_handle(None) self.db.commit_family(family,self.trans) self.broken_parent_links.append((father_handle,family_handle)) @@ -107,16 +109,19 @@ class CheckIntegrity: if mother_handle: mother = self.db.get_person_from_handle(mother_handle) if not mother: + # The person referenced by the mother handle does not exist in the database family.set_father_handle(None) self.db.commit_family(family,self.trans) self.broken_parent_links.append((mother_handle,family_handle)) mother_handle = None if father_handle and father and family_handle not in father.get_family_handle_list(): + # The referenced father has no reference back to the family self.broken_parent_links.append((father_handle,family_handle)) father.add_family_handle(family_handle) self.db.commit_person(father,self.trans) if mother_handle and mother and family_handle not in mother.get_family_handle_list(): + # The referenced mother has no reference back to the family self.broken_parent_links.append((mother_handle,family_handle)) mother.add_family_handle(family_handle) self.db.commit_person(mother,self.trans) @@ -129,14 +134,45 @@ class CheckIntegrity: if family_type[0] == family_handle: break else: + # The referenced child has no reference back to the family family.remove_child_handle(child_handle) self.db.commit_family(family,self.trans) self.broken_links.append((child_handle,family_handle)) else: + # The person referenced by the child handle does not exist in the database family.remove_child_handle(child_handle) self.db.commit_family(family,self.trans) self.broken_links.append((child_handle,family_handle)) - + + # Check persons membership in referenced families + for person_handle in self.db.get_person_handles(): + person = self.db.get_person_from_handle(person_handle) + for family_type in person.get_parent_family_handle_list(): + family = self.db.get_family_from_handle(family_type[0]) + for child_handle in family.get_child_handle_list(): + if child_handle == person_handle: + break + else: + # Person is not a child in the referenced parent family + person.remove_parent_family_handle(family_type[0]) + self.db.commit_person(person,self.trans) + self.broken_links.append((person_handle,family_handle)) + for family_handle in person.get_family_handle_list(): + family = self.db.get_family_from_handle(family_handle) + if not family: + # The referenced family does not exist in database + person.remove_family_handle(family_handle) + self.db.commit_person(person,self.trans) + self.broken_links.append((person_handle,family_handle)) + continue + if family.get_father_handle() == person_handle: + continue + if family.get_mother_handle() == person_handle: + continue + # The person is not a member of the referenced family + person.remove_family_handle(family_handle) + self.db.commit_person(person,self.trans) + self.broken_links.append((person_handle,family_handle)) def cleanup_missing_photos(self,cl=0): missmedia_action = 0 @@ -260,11 +296,13 @@ class CheckIntegrity: continue elif not father_handle: if mother and mother.get_gender() == RelLib.Person.MALE: + # No father set and mother is male family.set_father_handle(mother_handle) family.set_mother_handle(None) self.db.commit_family(family,self.trans) elif not mother_handle: if father and father.get_gender() == RelLib.Person.FEMALE: + # No mother set and father is female family.set_mother_handle(father_handle) family.set_father_handle(None) self.db.commit_family(family,self.trans) @@ -323,17 +361,20 @@ class CheckIntegrity: cn = person.get_primary_name().get_name() else: cn = _("Non existing child") - f = self.db.get_person_from_handle(family.get_father_handle()) - m = self.db.get_person_from_handle(family.get_mother_handle()) - if f and m: - pn = _("%s and %s") % (f.get_primary_name().get_name(),\ + if family: + f = self.db.get_person_from_handle(family.get_father_handle()) + m = self.db.get_person_from_handle(family.get_mother_handle()) + if f and m: + pn = _("%s and %s") % (f.get_primary_name().get_name(),\ m.get_primary_name().get_name()) - elif f: - pn = f.get_primary_name().get_name() - elif m: - pn = m.get_primary_name().get_name() + elif f: + pn = f.get_primary_name().get_name() + elif m: + pn = m.get_primary_name().get_name() + else: + pn = _("unknown") else: - pn = _("unknown") + pn = _("Non existing family") self.text.write('\t') self.text.write(_("%s was removed from the family of %s\n") % (cn,pn)) diff --git a/gramps2/src/plugins/TestcaseGenerator.py b/gramps2/src/plugins/TestcaseGenerator.py index 32bd60507..c8c36d8d8 100644 --- a/gramps2/src/plugins/TestcaseGenerator.py +++ b/gramps2/src/plugins/TestcaseGenerator.py @@ -173,6 +173,60 @@ class TestcaseGenerator: #self.db.commit_person(person2,self.trans) + # Creates a family where the child does not link back to the family + person1_h = self.generate_person(RelLib.Person.MALE,"Broken8",None) + person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken8",None) + child_h = self.generate_person(None,"Broken8",None) + fam = RelLib.Family() + fam.set_father_handle(person1_h) + fam.set_mother_handle(person2_h) + fam.set_relationship(RelLib.Family.MARRIED) + fam.add_child_handle(child_h) + fam_h = self.db.add_family(fam,self.trans) + person1 = self.db.get_person_from_handle(person1_h) + person1.add_family_handle(fam_h) + self.db.commit_person(person1,self.trans) + person2 = self.db.get_person_from_handle(person2_h) + person2.add_family_handle(fam_h) + self.db.commit_person(person2,self.trans) + #child = self.db.get_person_from_handle(child_h) + #person2.add_parent_family_handle(fam_h) + #self.db.commit_person(child,self.trans) + + # Creates a family where the child is not linked, but the child links to the family + person1_h = self.generate_person(RelLib.Person.MALE,"Broken9",None) + person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken9",None) + child_h = self.generate_person(None,"Broken9",None) + fam = RelLib.Family() + fam.set_father_handle(person1_h) + fam.set_mother_handle(person2_h) + fam.set_relationship(RelLib.Family.MARRIED) + #fam.add_child_handle(child_h) + fam_h = self.db.add_family(fam,self.trans) + person1 = self.db.get_person_from_handle(person1_h) + person1.add_family_handle(fam_h) + self.db.commit_person(person1,self.trans) + person2 = self.db.get_person_from_handle(person2_h) + person2.add_family_handle(fam_h) + self.db.commit_person(person2,self.trans) + child = self.db.get_person_from_handle(child_h) + person2.add_parent_family_handle(fam_h,RelLib.Person.CHILD_REL_BIRTH,RelLib.Person.CHILD_REL_BIRTH) + self.db.commit_person(child,self.trans) + + # Creates a person with an event having a witness reference to a nonexisting person + person_h = self.generate_person(None,"Broken10",None) + witness = RelLib.Witness() + witness.set_type(RelLib.Event.ID) + witness.set_value("InvalidHandle3") + witness.set_comment("Pointing to non existing person"); + event = RelLib.Event() + event.add_witness(witness) + event.set_name("Christening") + event_h = self.db.add_event(event,self.trans) + person = self.db.get_person_from_handle(person_h) + person.add_event_handle(event_h) + self.db.commit_person(person,self.trans) + def generate_person(self,gender=None,lastname=None,note=None): print "generate_person"