public function import(array $definitions, array $records, array $defaultAttributes = [], $persist = true): array
    {
        $imported = [];
        $recordsByHandle = $this->getRecordsByHandle($records);
        foreach ($definitions as $handle => $definition) {
            $modelClass = $definition['class'];
            $converter = Craft::$app->controller->module->getConverter($modelClass);
            if ($converter) {
                $record = $this->findOrNewRecord($recordsByHandle, $definition, $handle);

                if ($converter->getRecordDefinition($record) === $definition) {
                    Schematic::info('- Skipping '.get_class($record).' '.$handle);
                } else {
                    $converter->setRecordAttributes($record, $definition, $defaultAttributes);
                    if ($persist) {
                        Schematic::info('- Saving '.get_class($record).' '.$handle);
                        if (!$converter->saveRecord($record, $definition)) {
                            Schematic::importError($record, $handle);
                        }
                    }
                }

                $imported[] = $record;
            }
            unset($recordsByHandle[$handle]);
        }

        if (Schematic::$force && $persist) {
            // Delete records not in definitions
            foreach ($recordsByHandle as $handle => $record) {
                $modelClass = get_class($record);
                Schematic::info('- Deleting '.get_class($record).' '.$handle);
                $converter = Craft::$app->controller->module->getConverter($modelClass);
                $converter->deleteRecord($record);
            }
        }

        return $imported;
    }
public function import(array $definitions, array $records, array $defaultAttributes = [], $persist = true): array
    {
        $imported = [];
        $recordsByHandle = $this->getRecordsByHandle($records);
        foreach ($definitions as $handle => $definition) {
            $modelClass = $definition['class'];
            $converter = Craft::$app->controller->module->getConverter($modelClass);
            if ($converter) {
                $record = $this->findOrNewRecord($recordsByHandle, $definition, $handle);

                if ($converter->getRecordDefinition($record) === $definition) {
                    Schematic::info('- Skipping '.get_class($record).' '.$handle);
                } else {
                    $converter->setRecordAttributes($record, $definition, $defaultAttributes);
                    if ($persist) {
                        Schematic::info('- Saving '.get_class($record).' '.$handle);
                        if (!$converter->saveRecord($record, $definition)) {
                            Schematic::importError($record, $handle);
                        }
                    }
                }

                $imported[] = $record;
            }
            unset($recordsByHandle[$handle]);
        }

        if (Schematic::$force && $persist) {
            // Delete records not in definitions
            foreach ($recordsByHandle as $handle => $record) {
                $modelClass = get_class($record);
                Schematic::info('- Deleting '.get_class($record).' '.$handle);
                $converter = Craft::$app->controller->module->getConverter($modelClass);
                $converter->deleteRecord($record);
            }
        }

        return $imported;
    }
public function import ( array $ definitions , array $ records , array $ defaultAttributes = [ ] , $ persist = true ) : array { $ imported = [ ] ; $ recordsByHandle = $ this -> getRecordsByHandle ( $ records ) ; foreach ( $ definitions as $ handle => $ definition ) { $ modelClass = $ definition [ 'class' ] ; $ converter = Craft :: $ app -> controller -> module -> getConverter ( $ modelClass ) ; if ( $ converter ) { $ record = $ this -> findOrNewRecord ( $ recordsByHandle , $ definition , $ handle ) ; if ( $ converter -> getRecordDefinition ( $ record ) === $ definition ) { Schematic :: info ( '- Skipping ' . get_class ( $ record ) . ' ' . $ handle ) ; } else { $ converter -> setRecordAttributes ( $ record , $ definition , $ defaultAttributes ) ; if ( $ persist ) { Schematic :: info ( '- Saving ' . get_class ( $ record ) . ' ' . $ handle ) ; if ( ! $ converter -> saveRecord ( $ record , $ definition ) ) { Schematic :: importError ( $ record , $ handle ) ; } } } $ imported [ ] = $ record ; } unset ( $ recordsByHandle [ $ handle ] ) ; } if ( Schematic :: $ force && $ persist ) { // Delete records not in definitions foreach ( $ recordsByHandle as $ handle => $ record ) { $ modelClass = get_class ( $ record ) ; Schematic :: info ( '- Deleting ' . get_class ( $ record ) . ' ' . $ handle ) ; $ converter = Craft :: $ app -> controller -> module -> getConverter ( $ modelClass ) ; $ converter -> deleteRecord ( $ record ) ; } } return $ imported ; }
Import records.

@param array $definitions
@param Model $records           The existing records
@param array $defaultAttributes Default attributes to use for each record
@param bool  $persist           Whether to persist the parsed records

@return array
Import records .