Imports data according to the design of the specified import specification.

@param ImportSpecification $specification Import specification.

@return PorterRecords|CountablePorterRecords

@throws ImportException Provider failed to return an iterator.
543752
public function import(ImportSpecification $specification)
    {
        $specification = clone $specification;

        $records = $this->fetch(
            $specification->getResource(),
            $specification->getProviderName(),
            ConnectionContextFactory::create($specification)
        );

        if (!$records instanceof ProviderRecords) {
            $records = $this->createProviderRecords($records, $specification->getResource());
        }

        $records = $this->transformRecords($records, $specification->getTransformers(), $specification->getContext());

        return $this->createPorterRecords($records, $specification);
    }
328440
protected function processImport(AbstractImport $import, SerializerInterface $serializer)
    {
        $errors = [];

        $import->setData($serializer->unserialize($import->getFile()->openFile('r')));

        foreach ($import as $idx => $data) {
            $import->checkMandatoryColumns($data);

            $error = $import->importData($data);
            if ($error !== null) {
                $errors[] = $error;
            }
        }

        return $errors;
    }
792488
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;
    }
412432
public function count(Import $import)
	{
		// create iterator
		$iterator = new Reader($import->getDatapath(), $this->delimiter);

		// iterate over each row
		foreach ($iterator as $row => $data)
		{
			// if we got back null for a row dont count
			if ($data !== null)
			{
				$data = array_map('trim', (array)$data);

				if (array_filter($data))
				{
					$this->data_count++;
				}
			}
		}

		// return count
		return $this->data_count;
	}
1258596
public function importProductListProductConcrete(?DataImporterConfigurationTransfer $dataImporterConfigurationTransfer = null): DataImporterReportTransfer
    {
        return $this->getFactory()
            ->createProductListProductConcreteDataImport()
            ->import($dataImporterConfigurationTransfer);
    }
580971
public function importTenancyFrom(TenantContract $tenant)
    {
        $this->setTenantOwnerId($tenant->getTenantOwnerId());
        $this->setTenantCreatorId($tenant->getTenantCreatorId());

        return $this;
    }
329490
public function import(Guardian $guardian, ImportRecordsDataTable $importRecordsDataTable)
    {
        return $importRecordsDataTable->with([
            'resource' => $guardian,
            'tabs' => 'adminarea.guardians.tabs',
            'url' => route('adminarea.guardians.stash'),
            'id' => "adminarea-attributes-{$guardian->getRouteKey()}-import-table",
        ])->render('cortex/foundation::adminarea.pages.datatable-dropzone');
    }
460601
public function import(Service $service, ImportRecordsDataTable $importRecordsDataTable)
    {
        return $importRecordsDataTable->with([
            'resource' => $service,
            'tabs' => 'adminarea.services.tabs',
            'url' => route('adminarea.services.stash'),
            'id' => "adminarea-services-{$service->getRouteKey()}-import-table",
        ])->render('cortex/foundation::adminarea.pages.datatable-dropzone');
    }
807444
protected function _importResult(Import $import, array $headers, int $rowNumber, array $data) : void
    {
        $importTable = TableRegistry::get('CsvMigrations.ImportResults');
        Assert::isInstanceOf($importTable, ImportResultsTable::class);

        $query = $importTable->find('all')
            ->enableHydration(true)
            ->where(['import_id' => $import->get('id'), 'row_number' => $rowNumber]);

        try {
            $importResult = $query->firstOrFail();
        } catch (RecordNotFoundException $e) {
            return;
        }

        Assert::isInstanceOf($importResult, ImportResult::class);

        // skip successful imports
        if ($importTable::STATUS_SUCCESS === $importResult->get('status')) {
            return;
        }

        $table = TableRegistry::get($importResult->get('model_name'));

        $data = $this->_prepareData($import, $headers, $data);
        $csvFields = FieldUtility::getCsv($table);
        $data = $this->_processData($table, $csvFields, $data);

        // skip empty processed data
        if (empty($data)) {
            $this->_importFail($importResult, ['Row has no data']);

            return;
        }

        try {
            $entity = $table->newEntity();
            $entity = $table->patchEntity($entity, $data);

            $table->save($entity) ?
                $this->_importSuccess($importResult, $entity) :
                $this->_importFail($importResult, $entity->getErrors());
        } catch (CakeException $e) {
            $this->_importFail($importResult, [$e->getMessage()]);
        } catch (PDOException $e) {
            $this->_importFail($importResult, [$e->getMessage()]);
        }
    }
222555
protected function createImport($name, $filename, $record)
    {
        // This is needed to feed WorkflowService#getNamedTemplate()
        $import = ImportedWorkflowTemplate::create();
        $import->Name = $name;
        $import->Filename = $filename;
        $import->Content = serialize($record);
        $import->write();

        return $import;
    }
1067225
protected function createImportResults(Import $import, int $count) : void
    {
        $this->out('Preparing records ..');

        $progress = $this->helper('Progress');
        Assert::isInstanceOf($progress, ProgressHelper::class);
        $progress->init();

        $table = TableRegistry::get('CsvMigrations.ImportResults');
        Assert::isInstanceOf($table, ImportResultsTable::class);

        $query = $table->find('all')->where(['import_id' => $import->get('id')]);
        $queryCount = $query->count();

        if ($queryCount >= $count) {
            return;
        }

        $data = [
            'import_id' => $import->get('id'),
            'status' => $table::STATUS_PENDING,
            'status_message' => $table::STATUS_PENDING_MESSAGE,
            'model_name' => $import->get('model_name')
        ];

        $i = $queryCount + 1;
        $progressCount = $count - $queryCount;
        // set $i = 1 to skip header row
        for ($i; $i <= $count; $i++) {
            $data['row_number'] = $i;

            $entity = $table->newEntity();
            $entity = $table->patchEntity($entity, $data);

            $table->save($entity);

            $progress->increment(100 / $progressCount);
            $progress->draw();
        }

        $this->out(null);
    }
634255
public function import(?DataImporterConfigurationTransfer $dataImporterConfigurationTransfer = null): DataImporterReportTransfer
    {
        return $this->getFactory()->createPriceProductMerchantRelationshipDataImport()->import($dataImporterConfigurationTransfer);
    }
1316775
public function getQueueByTypeAndMode($importType, $importMode, $limit)
    {
        if (is_array($importType)) {
            $condition = [];
            foreach ($importType as $type) {
                if ($type == 'Catalog') {
                    $condition[] = ['like' => $type . '%'];
                } else {
                    $condition[] = ['eq' => $type];
                }
            }
            $this->addFieldToFilter('import_type', $condition);
        } else {
            $this->addFieldToFilter(
                'import_type',
                ['eq' => $importType]
            );
        }

        $this->addFieldToFilter('import_mode', ['eq' => $importMode])
            ->addFieldToFilter(
                'import_status',
                ['eq' => \Dotdigitalgroup\Email\Model\Importer::NOT_IMPORTED]
            )
            ->setPageSize($limit)
            ->setCurPage(1);

        return $this;
    }
686857
public function importProductMeasurementSalesUnit(?DataImporterConfigurationTransfer $dataImporterConfigurationTransfer = null): DataImporterReportTransfer
    {
        return $this->getFactory()
            ->getProductMeasurementSalesUnitDataImporter()
            ->import($dataImporterConfigurationTransfer);
    }
1030013
protected function getImportType()
    {
        $type = $this->importType;

        if (strlen($type) != 1 || !array_key_exists($type, $this->objects)) {
            throw new Exception('Error unknown command: ' . $type);
        } else {
            return $this->objects[$type];
        }
    }
918688
public function setSpecification($specification = null)
    {
        $this->checkSpecificationIsArray($specification);

        foreach ($specification as $item) {
            $this->items[] = $this->checkIfAnnotationAndReturnObject($item);
        }
    }
872372
public function count(Import $import)
	{
		// create iterator
		$iterator = new Reader($import->getDatapath(), $this->key);

		// return count
		return $iterator->total();
	}