app/GedcomRecord.php
public function updateFact(string $fact_id, string $gedcom, bool $update_chan): void
    {
        // MSDOS line endings will break things in horrible ways
        $gedcom = preg_replace('/[\r\n]+/', "\n", $gedcom);
        $gedcom = trim($gedcom);

        if ($this->pending === '') {
            throw new Exception('Cannot edit a deleted record');
        }
        if ($gedcom !== '' && !preg_match('/^1 ' . Gedcom::REGEX_TAG . '/', $gedcom)) {
            throw new Exception('Invalid GEDCOM data passed to GedcomRecord::updateFact(' . $gedcom . ')');
        }

        if ($this->pending) {
            $old_gedcom = $this->pending;
        } else {
            $old_gedcom = $this->gedcom;
        }

        // First line of record may contain data - e.g. NOTE records.
        [$new_gedcom] = explode("\n", $old_gedcom, 2);

        // Replacing (or deleting) an existing fact
        foreach ($this->facts([], false, Auth::PRIV_HIDE) as $fact) {
            if (!$fact->isPendingDeletion()) {
                if ($fact->id() === $fact_id) {
                    if ($gedcom !== '') {
                        $new_gedcom .= "\n" . $gedcom;
                    }
                    $fact_id = 'NOT A VALID FACT ID'; // Only replace/delete one copy of a duplicate fact
                } elseif ($fact->getTag() !== 'CHAN' || !$update_chan) {
                    $new_gedcom .= "\n" . $fact->gedcom();
                }
            }
        }
        if ($update_chan) {
            $new_gedcom .= "\n1 CHAN\n2 DATE " . strtoupper(date('d M Y')) . "\n3 TIME " . date('H:i:s') . "\n2 _WT_USER " . Auth::user()->userName();
        }

        // Adding a new fact
        if ($fact_id === '') {
            $new_gedcom .= "\n" . $gedcom;
        }

        if ($new_gedcom !== $old_gedcom) {
            // Save the changes
            DB::table('change')->insert([
                'gedcom_id'  => $this->tree->id(),
                'xref'       => $this->xref,
                'old_gedcom' => $old_gedcom,
                'new_gedcom' => $new_gedcom,
                'user_id'    => Auth::id(),
            ]);

            $this->pending = $new_gedcom;

            if (Auth::user()->getPreference('auto_accept')) {
                FunctionsImport::acceptAllChanges($this->xref, $this->tree);
                $this->gedcom  = $new_gedcom;
                $this->pending = null;
            }
        }
        $this->parseFacts();
    }
public function updateFact(string $fact_id, string $gedcom, bool $update_chan): void
    {
        // MSDOS line endings will break things in horrible ways
        $gedcom = preg_replace('/[\r\n]+/', "\n", $gedcom);
        $gedcom = trim($gedcom);

        if ($this->pending === '') {
            throw new Exception('Cannot edit a deleted record');
        }
        if ($gedcom !== '' && !preg_match('/^1 ' . Gedcom::REGEX_TAG . '/', $gedcom)) {
            throw new Exception('Invalid GEDCOM data passed to GedcomRecord::updateFact(' . $gedcom . ')');
        }

        if ($this->pending) {
            $old_gedcom = $this->pending;
        } else {
            $old_gedcom = $this->gedcom;
        }

        // First line of record may contain data - e.g. NOTE records.
        [$new_gedcom] = explode("\n", $old_gedcom, 2);

        // Replacing (or deleting) an existing fact
        foreach ($this->facts([], false, Auth::PRIV_HIDE) as $fact) {
            if (!$fact->isPendingDeletion()) {
                if ($fact->id() === $fact_id) {
                    if ($gedcom !== '') {
                        $new_gedcom .= "\n" . $gedcom;
                    }
                    $fact_id = 'NOT A VALID FACT ID'; // Only replace/delete one copy of a duplicate fact
                } elseif ($fact->getTag() !== 'CHAN' || !$update_chan) {
                    $new_gedcom .= "\n" . $fact->gedcom();
                }
            }
        }
        if ($update_chan) {
            $new_gedcom .= "\n1 CHAN\n2 DATE " . strtoupper(date('d M Y')) . "\n3 TIME " . date('H:i:s') . "\n2 _WT_USER " . Auth::user()->userName();
        }

        // Adding a new fact
        if ($fact_id === '') {
            $new_gedcom .= "\n" . $gedcom;
        }

        if ($new_gedcom !== $old_gedcom) {
            // Save the changes
            DB::table('change')->insert([
                'gedcom_id'  => $this->tree->id(),
                'xref'       => $this->xref,
                'old_gedcom' => $old_gedcom,
                'new_gedcom' => $new_gedcom,
                'user_id'    => Auth::id(),
            ]);

            $this->pending = $new_gedcom;

            if (Auth::user()->getPreference('auto_accept')) {
                FunctionsImport::acceptAllChanges($this->xref, $this->tree);
                $this->gedcom  = $new_gedcom;
                $this->pending = null;
            }
        }
        $this->parseFacts();
    }
public function updateFact ( string $ fact_id , string $ gedcom , bool $ update_chan ) : void { // MSDOS line endings will break things in horrible ways $ gedcom = preg_replace ( '/[\r\n]+/' , "\n" , $ gedcom ) ; $ gedcom = trim ( $ gedcom ) ; if ( $ this -> pending === '' ) { throw new Exception ( 'Cannot edit a deleted record' ) ; } if ( $ gedcom !== '' && ! preg_match ( '/^1 ' . Gedcom :: REGEX_TAG . '/' , $ gedcom ) ) { throw new Exception ( 'Invalid GEDCOM data passed to GedcomRecord::updateFact(' . $ gedcom . ')' ) ; } if ( $ this -> pending ) { $ old_gedcom = $ this -> pending ; } else { $ old_gedcom = $ this -> gedcom ; } // First line of record may contain data - e.g. NOTE records. [ $ new_gedcom ] = explode ( "\n" , $ old_gedcom , 2 ) ; // Replacing (or deleting) an existing fact foreach ( $ this -> facts ( [ ] , false , Auth :: PRIV_HIDE ) as $ fact ) { if ( ! $ fact -> isPendingDeletion ( ) ) { if ( $ fact -> id ( ) === $ fact_id ) { if ( $ gedcom !== '' ) { $ new_gedcom .= "\n" . $ gedcom ; } $ fact_id = 'NOT A VALID FACT ID' ; // Only replace/delete one copy of a duplicate fact } elseif ( $ fact -> getTag ( ) !== 'CHAN' || ! $ update_chan ) { $ new_gedcom .= "\n" . $ fact -> gedcom ( ) ; } } } if ( $ update_chan ) { $ new_gedcom .= "\n1 CHAN\n2 DATE " . strtoupper ( date ( 'd M Y' ) ) . "\n3 TIME " . date ( 'H:i:s' ) . "\n2 _WT_USER " . Auth :: user ( ) -> userName ( ) ; } // Adding a new fact if ( $ fact_id === '' ) { $ new_gedcom .= "\n" . $ gedcom ; } if ( $ new_gedcom !== $ old_gedcom ) { // Save the changes DB :: table ( 'change' ) -> insert ( [ 'gedcom_id' => $ this -> tree -> id ( ) , 'xref' => $ this -> xref , 'old_gedcom' => $ old_gedcom , 'new_gedcom' => $ new_gedcom , 'user_id' => Auth :: id ( ) , ] ) ; $ this -> pending = $ new_gedcom ; if ( Auth :: user ( ) -> getPreference ( 'auto_accept' ) ) { FunctionsImport :: acceptAllChanges ( $ this -> xref , $ this -> tree ) ; $ this -> gedcom = $ new_gedcom ; $ this -> pending = null ; } } $ this -> parseFacts ( ) ; }
Replace a fact with a new gedcom data.

@param string $fact_id
@param string $gedcom
@param bool   $update_chan

@return void
@throws Exception
Replace a fact with a new gedcom data .