Apply any updates to this record

@param GedcomRecord $record

@return string
166206
public function updateRecord(GedcomRecord $record): string
    {
        $old_gedcom = $record->gedcom();

        // Allow "\n" to indicate a line-feed in replacement text.
        // Back-references such as $1, $2 are handled automatically.
        $new_gedcom = preg_replace('/' . $this->regex . '/mu' . $this->case, str_replace('\n', "\n", $this->replace), $old_gedcom);

        return $new_gedcom;
    }
1289934
public static function checkRecordAccess(GedcomRecord $record = null, $edit = false): void
    {
        if ($record === null) {
            throw new RecordNotFoundException();
        }

        if (!$record->canShow()) {
            throw new RecordAccessDeniedException();
        }

        if ($edit && !$record->canEdit()) {
            throw new RecordAccessDeniedException();
        }
    }
63430
public static function destroy($record)
    {
        if(is_string($record)) {
            return $record;
        }

        $id = $record->id;

        try {
            $tableName = self::getTableName();
            $conn = self::getConnection();
            $sql = "DELETE FROM ".$tableName ." WHERE id = ".$id;
            $affectedRows = $conn->exec($sql);

            return $affectedRows;
        }
        catch(PDOException $pe) {
            return $pe->getMessage();
        }
        catch(Exception $e) {
            return $e->getMessage();
        }
    }
1106564
public function getRecordUrl($record)
    {
        if (isset($this->recordOnClick)) {
            return 'javascript:;';
        }

        if (!isset($this->recordUrl)) {
            return null;
        }

        $url = RouterHelper::replaceParameters($record, $this->recordUrl);
        return Backend::url($url);
    }
1096341
public function getActionPreview(GedcomRecord $record): string
    {
        $old_lines   = explode("\n", $record->gedcom());
        $new_lines   = explode("\n", $this->updateRecord($record));
        $algorithm   = new MyersDiff();
        $differences = $algorithm->calculate($old_lines, $new_lines);
        $diff_lines  = [];

        foreach ($differences as $difference) {
            switch ($difference[1]) {
                case MyersDiff::DELETE:
                    $diff_lines[] = self::decorateDeletedText($difference[0]);
                    break;
                case MyersDiff::INSERT:
                    $diff_lines[] = self::decorateInsertedText($difference[0]);
                    break;
                default:
                    $diff_lines[] = $difference[0];
            }
        }

        return '<pre class="gedcom-data">' . self::createEditLinks(implode("\n", $diff_lines), $record) . '</pre>';
    }
1102271
protected function getRecordGridfieldRow($record)
    {
        $this->gridField->setList(new ArrayList(array($record)));
        $rowContent = '';

        foreach ($this->gridField->getColumns() as $column) {
            $colContent = $this->gridField->getColumnContent($record, $column);
            // Null means this columns should be skipped altogether.
            if ($colContent === null) {
                continue;
            }

            $colAttributes = $this->gridField->getColumnAttributes($record, $column);
            $rowContent .= HTML::createTag(
                'td',
                $colAttributes,
                $colContent
            );
        }

        $rowAttributes = array(
            'class' => 'ss-gridfield-item ' . implode(' ', $this->successClasses),
            'data-id' => $record->ID,
            'data-class' => $record->ClassName,
        );
        $row = HTML::createTag(
            'tr',
            $rowAttributes,
            $rowContent
        );
        return $row;
    }
857547
protected function getRecordState($record)
    {
        if ($this->isVersioned()) {
            // Check stage this record belongs to
            $stage = $record->getSourceQueryParam('Versioned.stage') ?: Versioned::get_stage();

            // Non-live stages are automatically non-public
            if ($stage !== Versioned::LIVE) {
                return AssetManipulationList::STATE_PROTECTED;
            }
        }

        // Check if canView permits anonymous viewers
        return Member::actAs(null, function () use ($record) {
            return $record->canView()
                ? AssetManipulationList::STATE_PUBLIC
                : AssetManipulationList::STATE_PROTECTED;
        });
    }
1189285
protected static function doesRecordContainModifier($record)
    {
        if (is_array($record)) {
            foreach ($record as $key => $value) {
                if (!empty($key) && ('$' == $key[0])) {
                    return true;
                }
            }
        }

        return false;
    }
268948
public function addRecord($record)
    {
        if ((isset($this->DBFHeader)) && (is_array($this->DBFHeader))) {
            $record->updateDBFInfo($this->DBFHeader);
        }

        $this->fileLength += ($record->getContentLength() + 4);
        $this->records[] = $record;
        $this->records[count($this->records) - 1]->recordNumber = count($this->records);

        $this->updateBBox('x', $record->SHPData);
        $this->updateBBox('y', $record->SHPData);

        if (in_array($this->shapeType, [11, 13, 15, 18, 21, 23, 25, 28])) {
            $this->updateBBox('m', $record->SHPData);
        }

        if (in_array($this->shapeType, [11, 13, 15, 18])) {
            $this->updateBBox('z', $record->SHPData);
        }

        return count($this->records) - 1;
    }
1013090
public static function fromRecord($record)
    {
        if (!$record) {
            return null;
        }
        $className = get_called_class();
        $entity = new $className;
        foreach ($record as $key => $value) {
            $entity->$key = $value;
        }
        return $entity;
    }
225052
private function applyTraits($record, $world)
    {
        foreach ($world->flashTraits() as $use) {
            $traits = Fabricate::traits();
            if (array_key_exists($use, $traits)) {
                $record = array_merge($record, $traits[$use]->run($record, $world));
            }
        }
        return $record;
    }
54538
public function tabelizeRecord(DatabaseRecord $record, $onlyDirty = false)
    {
        $dataArray = $record->__toArray(null, 2, false);
        $extensionArray = [];

        if ($onlyDirty) {
            foreach ($dataArray as $key => $val) {
                /**
                 * Leave only dirty and primary keys.
                 *
                 * @T00D00 - What if primary id has changed?
                 */
                if ($record->isDirty($key) || $key == 'id') {
                    continue;
                }

                unset($dataArray[$key]);
            }
        }

        /**
         * Holds all available fields in database table cache.
         */
        $keys = [
            $this->table => $this->repository->getCache()->getTableFields($this->table),
        ];

        foreach (get_class_methods($this) as $method) {
            /**
             * Get extension's fields.
             */
            if ($method != 'getFields' && substr($method, 0, 3) == 'get' && substr($method, -6) == 'Fields') {
                $suffix = $this->{'get' . substr($method, 3, -6) . 'TableSuffix'}();
                if (substr($this->table,
                           strlen($this->table) - strlen($suffix)) != $suffix && $this->repository->getCache()
                                                                                                  ->hasTable($this->table . $suffix)) {
                    $keys[$this->table . $suffix] = $this->{$method}();
                }
            }

            /**
             * Get extension's foreign key values.
             */
            if ($method != 'getForeignKeys' && substr($method, 0, 3) == 'get' && substr($method,
                                                                                        -11) == 'ForeignKeys') {
                $suffix = $this->{'get' . substr($method, 3, -11) . 'TableSuffix'}();
                if (substr($this->table,
                           strlen($this->table) - strlen($suffix)) != $suffix && $this->repository->getCache()
                                                                                                  ->hasTable($this->table . $suffix)) {
                    // base table
                    $extensionArray[$this->table . $suffix] = $this->{$method}($record);
                } elseif (strrpos($this->table,
                                  $suffix) == strlen($this->table) - strlen($suffix) && $this->repository->getCache()
                                                                                                         ->hasTable($this->table . $suffix)) {
                    // extendee table
                    $extensionArray[$this->table] = $this->{$method}($record);
                }
            }
        }

        // fill array with tables and fields
        $values = [];
        foreach ($keys as $table => $fields) {
            $values[$table] = [];
            foreach ($fields as $field) {
                /**
                 * Add value if field exists in data array and repository has that field.
                 */
                if ($this->repository->getCache()->tableHasField($table, $field)) {
                    if (isset($extensionArray[$table]) && array_key_exists($field, $extensionArray[$table])) {
                        $values[$table][$field] = $extensionArray[$table][$field];
                    } elseif (array_key_exists($field, $dataArray)) {
                        $values[$table][$field] = $dataArray[$field];
                    }
                }
            }
        }

        return $values;
    }
331144
public function queriedUpdate($record, Query $query)
    {
        $identifier = $this->getIdentifier();

        if (isset($record[$identifier])) {
            throw new DataStoreException('Primary key is not allowed in record for queried update');
        }

        $forUpdateRecords = $this->query($query);
        $updatedIds = [];

        foreach ($forUpdateRecords as $forUpdateRecord) {
            try {
                $updatedRecord = $this->update(array_merge($record, [$identifier => $forUpdateRecord[$identifier]]));
                $updatedIds[] = $updatedRecord[$identifier];
            } catch (\Throwable $e) {
                // TODO: log failed queried updated record
                continue;
            }
        }

        return $updatedIds;
    }
786483
private function processRouteMatchLogRecord(array $record)
    {
        if ($this->isAsseticLog($record)) {
            $record['message'] = '{method}: {request_uri}';

            return $record;
        }

        $context = $record['context'];

        unset($context['method']);
        unset($context['request_uri']);

        $record['context'] = array_merge(
            array($record['context']['method'] => $record['context']['request_uri']),
            $context
        );

        return $record;
    }
783489
private function surnamesToAdd(GedcomRecord $record): array
    {
        $gedcom = $record->gedcom();
        $tree   = $record->tree();

        $wife_surnames    = $this->surnames($record);
        $husb_surnames    = [];
        $missing_surnames = [];

        preg_match_all('/^1 FAMS @(.+)@/m', $gedcom, $fmatch);

        foreach ($fmatch[1] as $famid) {
            $family = Family::getInstance($famid, $tree);
            $famrec = $family->gedcom();

            if (preg_match('/^1 MARR/m', $famrec) && preg_match('/^1 HUSB @(.+)@/m', $famrec, $hmatch)) {
                $spouse = Individual::getInstance($hmatch[1], $tree);

                if ($spouse instanceof Individual) {
                    $husb_surnames = array_unique(array_merge($husb_surnames, $this->surnames($spouse)));
                }
            }
        }

        foreach ($husb_surnames as $husb_surname) {
            if (!in_array($husb_surname, $wife_surnames, true)) {
                $missing_surnames[] = $husb_surname;
            }
        }

        return $missing_surnames;
    }
1188759
public function findExistingObject($record)
    {
        // checking for existing records (only if not already found)
        foreach ($this->duplicateChecks as $fieldName => $duplicateCheck) {
            //plain duplicate checks on fields and relations
            if (is_string($duplicateCheck)) {
                $fieldName = $duplicateCheck;
                //If the dupilcate check is a dot notation, then convert to ID relation
                if (strpos($duplicateCheck, '.') !== false) {
                    list($relationName, $columnName) = explode('.', $duplicateCheck);
                    $fieldName = $relationName."ID";
                }
                //TODO: also convert plain relation names to include ID

                //skip current duplicate check if field value is empty
                if (!isset($record[$fieldName]) || empty($record[$fieldName])) {
                    continue;
                }
                $existingRecord = $this->getDataList()
                                    ->filter($fieldName, $record[$fieldName])
                                    ->first();
                if ($existingRecord) {
                    return $existingRecord;
                }
            }
            //callback duplicate checks
            elseif (
                is_array($duplicateCheck) &&
                isset($duplicateCheck['callback']) &&
                is_callable($duplicateCheck['callback'])
            ) {
                $callback = $duplicateCheck['callback'];
                if ($existingRecord = $callback($fieldName, $record)) {
                    return $existingRecord;
                }
            } else {
                user_error('BulkLoader::processRecord(): Wrong format for $duplicateChecks',
                    E_USER_WARNING
                );
            }
        }

        return false;
    }
809086
public function editlink($record)
    {
        $perm = 'contenttype:' . $record->contenttype['slug'] . ':edit:' . $record->id;

        if ($this->users->isAllowed($perm)) {
            return $this->urlGenerator->generate('editcontent', ['contenttypeslug' => $record->contenttype['slug'], 'id' => $record->id]);
        }

        return false;
    }