예제 #1
0
     if ($record && $record->canShow() && $record->canEdit()) {
         foreach ($record->getFacts() as $fact) {
             if ($fact->getFactId() == $fact_id && $fact->canShow() && $fact->canEdit()) {
                 $record->deleteFact($fact_id, true);
                 break 2;
             }
         }
     }
     // Can’t find the record/fact, or don’t have permission to delete it.
     http_response_code(406);
     break;
 case 'delete-record':
     $record = GedcomRecord::getInstance(Filter::post('xref', WT_REGEX_XREF), $WT_TREE);
     if ($record && Auth::isEditor($record->getTree()) && $record->canShow() && $record->canEdit()) {
         // Delete links to this record
         foreach (FunctionsDb::fetchAllLinks($record->getXref(), $record->getTree()->getTreeId()) as $xref) {
             $linker = GedcomRecord::getInstance($xref, $WT_TREE);
             $old_gedcom = $linker->getGedcom();
             $new_gedcom = FunctionsEdit::removeLinks($old_gedcom, $record->getXref());
             // FunctionsDb::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 = GedcomRecord::getInstance($xref, $WT_TREE);
                     FlashMessages::addMessage(I18N::translate('The family “%s” has been deleted because it only has one member.', $family->getFullName()));
                     $family->deleteRecord();
                     // Delete any remaining link to this family
                     if ($match) {
                         $relict = GedcomRecord::getInstance($match[2][0], $WT_TREE);
예제 #2
0
    }
}
foreach ($facts1 as $id1 => $fact1) {
    foreach ($facts2 as $id2 => $fact2) {
        if ($fact1->getFactId() === $fact2->getFactId()) {
            $facts[] = $fact1;
            unset($facts1[$id1]);
            unset($facts2[$id2]);
        }
    }
}
if ($rec1 && $rec2 && $rec1->getXref() !== $rec2->getXref() && $rec1::RECORD_TYPE === $rec2::RECORD_TYPE && Filter::post('action') === 'merge' && Filter::checkCsrf()) {
    // Use the XREF of the record.
    $gid1 = $rec1->getXref();
    $gid2 = $rec2->getXref();
    $ids = FunctionsDb::fetchAllLinks($gid2, $WT_TREE->getTreeId());
    // If we are not auto-accepting, then we can show a link to the pending deletion
    if (Auth::user()->getPreference('auto_accept')) {
        $record2_name = $rec2->getFullName();
    } else {
        $record2_name = '<a class="alert-link" href="' . $rec2->getHtmlUrl() . '">' . $rec2->getFullName() . '</a>';
    }
    foreach ($ids as $id) {
        $record = GedcomRecord::getInstance($id, $WT_TREE);
        if (!$record->isPendingDeletion()) {
            FlashMessages::addMessage(I18N::translate('The link from “%1$s” to “%2$s” has been updated.', '<a class="alert-link" href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a>', $record2_name), 'info');
            $gedcom = str_replace("@{$gid2}@", "@{$gid1}@", $record->getGedcom());
            $gedcom = preg_replace('/(\\n1.*@.+@.*(?:(?:\\n[2-9].*)*))((?:\\n1.*(?:\\n[2-9].*)*)*\\1)/', '$2', $gedcom);
            $record->updateRecord($gedcom, true);
        }
    }