diff options
| author | Greg Roach <fisharebest@gmail.com> | 2014-04-30 22:58:53 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2014-04-30 22:58:53 +0100 |
| commit | d33daee369340be9755d8344cf860c9df2f5bc1a (patch) | |
| tree | 6246a02c748bbcc93f6143b9d9a6069f74f7777c | |
| parent | 0229cbced4f1106c26433fe9826324ddbfe87019 (diff) | |
| download | webtrees-d33daee369340be9755d8344cf860c9df2f5bc1a.tar.gz webtrees-d33daee369340be9755d8344cf860c9df2f5bc1a.tar.bz2 webtrees-d33daee369340be9755d8344cf860c9df2f5bc1a.zip | |
Certain sequences of pending deletions could cause the same record to be deleted twice, which caused a (harmless) error message
| -rw-r--r-- | action.php | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/action.php b/action.php index ecddffc530..66f01e1232 100644 --- a/action.php +++ b/action.php @@ -145,26 +145,30 @@ case 'delete-source': // Delete links to this record foreach (fetch_all_links($record->getXref(), $record->getGedcomId()) as $xref) { $linker = WT_GedcomRecord::getInstance($xref); - $gedcom =$linker->getGedcom(); - $gedcom = remove_links($gedcom, $record->getXref()); - // If we have removed a link from a family to an individual, and it has only one member - if (preg_match('/^0 @'.WT_REGEX_XREF.'@ FAM/', $gedcom) && preg_match_all('/\n1 (HUSB|WIFE|CHIL) @(' . WT_REGEX_XREF . ')@/', $gedcom, $match)==1) { - // Delete the family - $family = WT_GedcomRecord::getInstance($xref); - WT_FlashMessages::addMessage(/* I18N: %s is the name of a family group, e.g. “Husband name + Wife name” */ WT_I18N::translate('The family “%s” has been deleted, as it only has one member.', $family->getFullName())); - $family->deleteRecord(); - // Delete any remaining link to this family - if ($match) { - $relict = WT_GedcomRecord::getInstance($match[2][0]); - $gedcom = $relict->getGedcom(); - $gedcom = remove_links($gedcom, $linker->getXref()); - $relict->updateRecord($gedcom, false); - WT_FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ WT_I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $relict->getFullName(), $family->getFullName())); + $old_gedcom =$linker->getGedcom(); + $new_gedcom = remove_links($old_gedcom, $record->getXref()); + // fetch_all_links() does not take account of pending changes. The links (or even the + // record itself) may have already been deleted. + if ($old_gedcom !== $new_gedcom) { + // If we have removed a link from a family to an individual, and it has only one member + if (preg_match('/^0 @'.WT_REGEX_XREF.'@ FAM/', $new_gedcom) && preg_match_all('/\n1 (HUSB|WIFE|CHIL) @(' . WT_REGEX_XREF . ')@/', $new_gedcom, $match)==1) { + // Delete the family + $family = WT_GedcomRecord::getInstance($xref); + WT_FlashMessages::addMessage(/* I18N: %s is the name of a family group, e.g. “Husband name + Wife name” */ WT_I18N::translate('The family “%s” has been deleted, as it only has one member.', $family->getFullName())); + $family->deleteRecord(); + // Delete any remaining link to this family + if ($match) { + $relict = WT_GedcomRecord::getInstance($match[2][0]); + $new_gedcom = $relict->getGedcom(); + $new_gedcom = remove_links($new_gedcom, $linker->getXref()); + $relict->updateRecord($new_gedcom, false); + WT_FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ WT_I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $relict->getFullName(), $family->getFullName())); + } + } else { + // Remove links from $linker to $record + WT_FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ WT_I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $linker->getFullName(), $record->getFullName())); + $linker->updateRecord($new_gedcom, false); } - } else { - // Remove links from $linker to $record - WT_FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ WT_I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $linker->getFullName(), $record->getFullName())); - $linker->updateRecord($gedcom, false); } } // Delete the record itself |
