app/Http/Controllers/Admin/FixLevel0MediaController.php
public function fixLevel0MediaAction(ServerRequestInterface $request): ResponseInterface
    {
        $fact_id   = $request->getParsedBody()['fact_id'];
        $indi_xref = $request->getParsedBody()['indi_xref'];
        $obje_xref = $request->getParsedBody()['obje_xref'];
        $tree_id   = (int) $request->getParsedBody()['tree_id'];

        $tree       = Tree::findById($tree_id);
        $individual = Individual::getInstance($indi_xref, $tree);
        $media      = Media::getInstance($obje_xref, $tree);

        if ($individual !== null && $media !== null) {
            foreach ($individual->facts() as $fact1) {
                if ($fact1->id() === $fact_id) {
                    $individual->updateFact($fact_id, $fact1->gedcom() . "\n2 OBJE @" . $obje_xref . '@', false);
                    foreach ($individual->facts(['OBJE']) as $fact2) {
                        if ($fact2->target() === $media) {
                            $individual->deleteFact($fact2->id(), false);
                        }
                    }
                    break;
                }
            }
        }

        return response();
    }
public function fixLevel0MediaAction(ServerRequestInterface $request): ResponseInterface
    {
        $fact_id   = $request->getParsedBody()['fact_id'];
        $indi_xref = $request->getParsedBody()['indi_xref'];
        $obje_xref = $request->getParsedBody()['obje_xref'];
        $tree_id   = (int) $request->getParsedBody()['tree_id'];

        $tree       = Tree::findById($tree_id);
        $individual = Individual::getInstance($indi_xref, $tree);
        $media      = Media::getInstance($obje_xref, $tree);

        if ($individual !== null && $media !== null) {
            foreach ($individual->facts() as $fact1) {
                if ($fact1->id() === $fact_id) {
                    $individual->updateFact($fact_id, $fact1->gedcom() . "\n2 OBJE @" . $obje_xref . '@', false);
                    foreach ($individual->facts(['OBJE']) as $fact2) {
                        if ($fact2->target() === $media) {
                            $individual->deleteFact($fact2->id(), false);
                        }
                    }
                    break;
                }
            }
        }

        return response();
    }
public function fixLevel0MediaAction ( ServerRequestInterface $ request ) : ResponseInterface { $ fact_id = $ request -> getParsedBody ( ) [ 'fact_id' ] ; $ indi_xref = $ request -> getParsedBody ( ) [ 'indi_xref' ] ; $ obje_xref = $ request -> getParsedBody ( ) [ 'obje_xref' ] ; $ tree_id = ( int ) $ request -> getParsedBody ( ) [ 'tree_id' ] ; $ tree = Tree :: findById ( $ tree_id ) ; $ individual = Individual :: getInstance ( $ indi_xref , $ tree ) ; $ media = Media :: getInstance ( $ obje_xref , $ tree ) ; if ( $ individual !== null && $ media !== null ) { foreach ( $ individual -> facts ( ) as $ fact1 ) { if ( $ fact1 -> id ( ) === $ fact_id ) { $ individual -> updateFact ( $ fact_id , $ fact1 -> gedcom ( ) . "\n2 OBJE @" . $ obje_xref . '@' , false ) ; foreach ( $ individual -> facts ( [ 'OBJE' ] ) as $ fact2 ) { if ( $ fact2 -> target ( ) === $ media ) { $ individual -> deleteFact ( $ fact2 -> id ( ) , false ) ; } } break ; } } } return response ( ) ; }
Move a link to a media object from a level 0 record to a level 1 record.

@param ServerRequestInterface $request

@return ResponseInterface
Move a link to a media object from a level 0 record to a level 1 record .