@todo implement in bridge_api°interface

Check if data uploaded via the current connector is conform
@param  array          $datas
@param  record_adapter $record
@return array
167443
public function check_upload_constraints(Array $datas, record_adapter $record)
    {
        $errors = $this->check_record_constraints($record);
        $check = function ($field) use (&$errors, $datas, $record) {
                $key = $record->getId();
                $required = ! ! $field["required"];
                $name = $field["name"];
                $length = (int) $field["length"];
                $length_min = (int) $field["length_min"];

                if ( ! isset($datas[$name]) || trim($datas[$name]) === '') {
                    if ($required)
                        $errors[$name . '_' . $key] = $this->translator->trans("Ce champ est obligatoire");
                } else {
                    if ($length != 0 && mb_strlen($datas[$name]) > $length)
                        $errors[$name . '_' . $key] = $this->translator->trans("Ce champ est trop long %length% caracteres max", ['%length%' => $length]);
                    if ($length_min != 0 && mb_strlen($datas[$name]) < $length_min)
                        $errors[$name . '_' . $key] = $this->translator->trans("Ce champ est trop court %length% caracteres min", ['%length%' => $length_min]);
                }
            };

        array_map($check, $this->get_fields());

        return $errors;
    }
327411
protected function hasDnsRecordChanged($domain, $record)
    {
        if (! $dns_history = History::where('meta', $domain)->orderBy('created_at', 'desc')->first()) {
            $this->saveDnsRecord($domain, $record);
            return false;
        }

        $differences = $this->compareDnsRecords($dns_history->record, $record);

        return (count($differences['original']) && count($differences['new']));
    }
498902
protected function exportRecord(AbstractRecord $record, DataDimensions $dataDimensions)
    {
        $precalculate      = $this->precalculateExportRecord($record, $dataDimensions);
        $allowedProperties = array_intersect_key($record->getProperties(), $precalculate['allowedProperties']);
        $record            = clone $record;
        $record->setProperties($allowedProperties);

        return $record;
    }
895377
public function loadFrom(DataObjectInterface $record)
    {
        // Obtain Field Name:
        
        $fieldName = $this->getName();
        
        // Bail Early (if needed):
        
        if (empty($fieldName) || empty($record)) {
            return;
        }
        
        // Determine Value Mode:
        
        if (!$this->isMultiple()) {
            
            // Load Singular Value:
            
            parent::setValue($record->$fieldName);
            
        } else {
            
            // Load Multiple Value:
            
            $relation = $this->getNamedRelation($record);
            
            if ($relation instanceof Relation) {
                $this->loadFromRelation($relation);
            } elseif ($record->hasField($fieldName)) {
                parent::setValue($this->stringDecode($record->$fieldName));
            }
            
        }
    }
1164646
public static function transform($record, $includes = [])
    {
        $model_name = class_basename(get_class($record));
        $transformer = sprintf('\App\Transformers\%sTransformer', $model_name);

        $fractal = new self();

        if ($includes) {
            $fractal->manager->parseIncludes($includes);
        }

        try {
            return $fractal->item($record, new $transformer, $model_name);
        } catch (\Exception $e) {
            //Transformer class doesn't exist
            return [];
        }
    }
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;
    }
378409
public function saveRecords(array $records, DataDimensions $dataDimensions = null)
    {
        if (count($records) > 0)
        {
            $record          = reset($records);
            $contentTypeName = $record->getContentTypeName();

            if (!$dataDimensions)
            {
                $dataDimensions = $this->getCurrentDataDimensions();
            }

            $recordIds  = [ ];
            $allRecords = $this->getAllRecords($contentTypeName, $dataDimensions);

            foreach ($records as $record)
            {
                $record = $this->finalizeRecord($record, $dataDimensions);

                if ($record->getID() == '')
                {
                    $nextId = 1;
                    if (count($allRecords) > 0)
                    {

                        $nextId = max(array_keys($allRecords)) + 1;
                    }
                    $record->setID($nextId);
                    $record->setRevision(0);
                }

                $mergedRecord = $this->mergeExistingRecord($record, $dataDimensions);

                $mergedRecord->setRevision($mergedRecord->getRevision() + 1);
                $record->setRevision($mergedRecord->getRevision());
                $mergedRecord->setLastChangeUserInfo($this->userInfo);
                $record->setLastChangeUserInfo($this->userInfo);

                $allRecords[$mergedRecord->getID()] = $mergedRecord;
                $recordIds[]                        = $mergedRecord->getID();
            }

            $data = json_encode([ 'records' => $allRecords ], JSON_PRETTY_PRINT);

            if ($this->writeData($this->getConfiguration()->getUriRecords($contentTypeName), $data))
            {
                $this->stashAllRecords($allRecords, $dataDimensions);

                return $recordIds;

            }
            throw new AnyContentClientException('Error when saving records of content type ' . $this->getCurrentContentTypeName());
        }

        return [ ];
    }
1132233
protected function parseRecord($record, $fields_info, $filter_info = null, $for_update = false, $old_record = null)
    {
        switch ($this->getAction()) {
            case Verbs::PATCH:
                if (static::doesRecordContainModifier($record)) {
                    return $this->interpretRecordValues($record);
                }
                break;
        }

        // convert to native format
        $result = parent::parseRecord($record, $fields_info, $filter_info, $for_update, $old_record);

        return static::toMongoObjects($result);
    }
50332
private function fixBlockFieldsForPreview($record)
    {
        foreach ($record->contenttype['fields'] as $fieldSlug => $fieldSettings) {
            if ($fieldSettings['type'] === 'block') {
                $fieldValue = $this->getBlockFieldValue($record, $fieldSlug);
                if ($fieldValue) {
                    $newArray = [];
                    foreach ($fieldValue as $item) {
                        if (!empty($item)) {
                            foreach ($item as $k => &$v) {
                                $v['block'] = $k;
                            }
                            $newArray[] = $v;
                        }
                    }
                    $this->setFieldValue($record, $fieldSlug, $newArray);
                }
            }
        }

        return $record;
    }
453543
public function multiUpdate($records)
    {
        $ids = [];

        foreach ($records as $record) {
            try {
                $updatedRecord = $this->update($record);
                $ids[] = $updatedRecord[$this->getIdentifier()];
            } catch (\Throwable $e) {
                // TODO: need to log record that was not updated
                continue;
            }
        }

        return $ids;
    }
285401
protected function prepareContentData($record)
    {
        $dataArray = array(
            'token'       => $this->token,
            'channel'     => $this->channel,
            'username'    => $this->username,
            'text'        => '',
            'attachments' => array(),
        );

        if ($this->formatter) {
            $message = $this->formatter->format($record);
        } else {
            $message = $record['message'];
        }

        if ($this->useAttachment) {
            $attachment = array(
                'fallback' => $message,
                'color'    => $this->getAttachmentColor($record['level']),
                'fields'   => array(),
            );

            if ($this->useShortAttachment) {
                $attachment['title'] = $record['level_name'];
                $attachment['text'] = $message;
            } else {
                $attachment['title'] = 'Message';
                $attachment['text'] = $message;
                $attachment['fields'][] = array(
                    'title' => 'Level',
                    'value' => $record['level_name'],
                    'short' => true,
                );
            }

            if ($this->includeContextAndExtra) {
                if (!empty($record['extra'])) {
                    if ($this->useShortAttachment) {
                        $attachment['fields'][] = array(
                            'title' => "Extra",
                            'value' => $this->stringify($record['extra']),
                            'short' => $this->useShortAttachment,
                        );
                    } else {
                        // Add all extra fields as individual fields in attachment
                        foreach ($record['extra'] as $var => $val) {
                            $attachment['fields'][] = array(
                                'title' => $var,
                                'value' => $val,
                                'short' => $this->useShortAttachment,
                            );
                        }
                    }
                }

                if (!empty($record['context'])) {
                    if ($this->useShortAttachment) {
                        $attachment['fields'][] = array(
                            'title' => "Context",
                            'value' => $this->stringify($record['context']),
                            'short' => $this->useShortAttachment,
                        );
                    } else {
                        // Add all context fields as individual fields in attachment
                        foreach ($record['context'] as $var => $val) {
                            $attachment['fields'][] = array(
                                'title' => $var,
                                'value' => $val,
                                'short' => $this->useShortAttachment,
                            );
                        }
                    }
                }
            }

            $dataArray['attachments'] = json_encode(array($attachment));
        } else {
            $dataArray['text'] = $message;
        }

        if ($this->iconEmoji) {
            $dataArray['icon_emoji'] = ":{$this->iconEmoji}:";
        }

        return $dataArray;
    }
996544
public function saveInto(DataObjectInterface $record)
    {
        $items = [];
        $fieldName = $this->name;
        $saveDest = $record->$fieldName();

        if (!$saveDest) {
            $recordClass = get_class($record);
            user_error(
                "TreeMultiselectField::saveInto() Field '$fieldName' not found on"
                . " {$recordClass}.{$record->ID}",
                E_USER_ERROR
            );
        }

        // Detect whether this field has actually been updated
        if ($this->value !== 'unchanged') {
            if (is_array($this->value)) {
                $items = $this->value;
            } elseif ($this->value) {
                $items = preg_split("/ *, */", trim($this->value));
            }
        }

        // Allows you to modify the items on your object before save
        $funcName = "onChange$fieldName";
        if ($record->hasMethod($funcName)) {
            $result = $record->$funcName($items);
            if (!$result) {
                return;
            }
        }
        $saveDest->setByIDList($items);
    }
521697
public function doesRecordNeedUpdate(GedcomRecord $record): bool
    {
        $gedcom = $record->gedcom();

        return
            preg_match('/(\n1.*@.+@.*(?:(?:\n[2-9].*)*))(?:\n1.*(?:\n[2-9].*)*)*\1/', $gedcom) ||
            preg_match('/(\n2.*@.+@.*(?:(?:\n[3-9].*)*))(?:\n2.*(?:\n[3-9].*)*)*\1/', $gedcom) ||
            preg_match('/(\n3.*@.+@.*(?:(?:\n[4-9].*)*))(?:\n3.*(?:\n[4-9].*)*)*\1/', $gedcom);
    }
71296
protected function shouldDisplayAction($record)
    {
        $admin = $this->owner->popupController;
        // If the record is a File, check if the file binary was archived
        $hasFileSaved = $record instanceof File ? $record->exists() : true;
        return (
            $hasFileSaved &&
            $admin instanceof ArchiveAdmin &&
            DataObject::has_extension($record, Versioned::class) &&
            $record->canRestoreToDraft()
        );
    }
187427
protected function formatSyncList(array $records)
    {
        $results = array();

        foreach ($records as $id => $attributes)
        {
            if ( ! is_array($attributes))
            {
                list($id, $attributes) = array($attributes, array());
            }

            $results[$id] = $attributes;
        }

        return $results;
    }
1124776
protected function unsetImportedRelations(array & $record)
    {
        foreach ($record as $key => $value) {
            if (strpos($key, 'role_by_') !== false ||
                strpos($key, 'service_by_') !== false ||
                strpos($key, 'role_service_access_by_') !== false ||
                strpos($key, 'user_to_app_to_role_by_') !== false
            ) {
                if (empty($value) || is_array($value)) {
                    unset($record[$key]);
                }
            }
        }
    }
1297470
private function recordFilter(array $records)
    {
        $messages = [];
        foreach ($records as $record) {
            if (!isset($record['level'])) {
                continue;
            }
            if (!$this->isHandling($record)) {
                continue;
            }

            $record = $this->processRecord($record);
            $record['formatted'] = $this->getFormatter()->format($record);

            $messages[] = $record;
        }
        return $messages;
    }