Create import record.

@param \CsvMigrations\Model\Table\ImportsTable $table Table instance
@param \CsvMigrations\Model\Entity\Import $entity Import entity
@param string $filename Uploaded file name
@return bool
334523
public function create(ImportsTable $table, ImportEntity $entity, string $filename) : bool
    {
        $modelName = $this->request->getParam('controller');
        if ($this->request->getParam('plugin')) {
            $modelName = $this->request->getParam('plugin') . '.' . $modelName;
        }

        $data = [
            'filename' => $filename,
            'status' => $table::STATUS_PENDING,
            'model_name' => $modelName,
            'attempts' => 0
        ];

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

        return (bool)$table->save($entity);
    }
12849
public function import_record($table, $dataobject) {
        $dataobject = (object)$dataobject;

        $columns = $this->get_columns($table);
        $cleaned = array();
        foreach ($dataobject as $field=>$value) {
            if (!isset($columns[$field])) {
                continue;
            }
            $cleaned[$field] = $value;
        }

        return $this->insert_record_raw($table, $cleaned, false, true, true);
    }
145788
public function addImportFilenameToImporterFile($importerFile, $filenameToImport)
    {
        if ($this->importerFileHasFilename($importerFile, $filenameToImport)) {
            return false;
        }

        $data = array();
        if (file_exists($importerFile)) {
            $data = Yaml::parse(file_get_contents($importerFile));
            if (!is_array($data) || !isset($data['imports'])) {
                $data = array('imports' => array());
            }
        }

        $data['imports'][] = array('resource' => $filenameToImport);

        $prefix = '';
        if (strpos($filenameToImport, '/') > 0) {
            $prefix = substr($filenameToImport, 0, strrpos($filenameToImport, '/'));
        }
        $data = $this->sortImports($data, $prefix);
        file_put_contents($importerFile, Yaml::dump($data));

        return true;
    }
125392
public function generateMigrationFile($method, $tables)
    {
        if ($method == 'create') {
            $function = 'getFields';
            $prefix = 'create';
        } elseif ($method = 'foreign_keys') {
            $function = 'getForeignKeyConstraints';
            $prefix = 'add_foreign_keys_to';
            $method = 'table';
        } else {
            return;
        }

        $this->method = $method;
        foreach ($tables as $table) {
            $migrationName = $prefix . '_' . $table . '_table';
            
            $fields = $this->schemaParser->{$function}($table);

            if (empty($fields)) {
                continue;
            }

            $filename = $this->datePrefix . '_' . $migrationName.'.php';

            $templateData = $this->getTemplateData($fields, [
                'CLASS'  => ucwords(camel_case($migrationName)),
                'TABLE'  => $table,
                'METHOD' => $method,
            ]);

            $this->generateFile($filename, $templateData);
        }
    }
653401
public function import_from_file($filename)
    {
        $reader = new FileReader($filename);
        if (!$reader->is_resource()) {
            return false;
        }

        $this->filename = (string) $filename;

        return $this->import_from_reader($reader);
    }
1275816
protected function _existingImport(ImportsTable $table, Import $import, int $count) : bool
    {
        $result = false;

        $data = ['attempted_date' => Time::now()];

        // max attempts rearched
        if ($import->get('attempts') >= (int)Configure::read('Importer.max_attempts')) {
            // set import as failed
            $data['status'] = $table::STATUS_FAIL;
            $import = $table->patchEntity($import, $data);

            return (bool)$table->save($import);
        }

        // increase attempts count
        $data['attempts'] = $import->get('attempts') + 1;
        $import = $table->patchEntity($import, $data);
        $table->save($import);

        $this->_run($import, $count);

        // mark import as completed
        $data['status'] = $table::STATUS_COMPLETED;
        $import = $table->patchEntity($import, $data);

        return (bool)$table->save($import);
    }
433266
public function createTable(Table $table)
    {
        if (!$table->hasOption('charset') && !$table->hasOption('collate')) {
            $connParams = $this->_conn->getParams();
            if (isset($connParams['defaultTableOptions']['charset']) && isset($connParams['defaultTableOptions']['collate'])) {
                $table
                    ->addOption('charset', $connParams['defaultTableOptions']['charset'])
                    ->addOption('collate', $connParams['defaultTableOptions']['collate'])
                ;
            }
        }

        return parent::createTable($table);
    }
1374283
private function import(SessionInterface $session, $path, $fileName)
    {
        if ($session->nodeExists($path)) {
            $session->getNode($path)->remove();
            $session->save();
        }

        $session->importXML(
            PathHelper::getParentPath($path),
            $fileName,
            ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW
        );

        $session->save();
    }
1052518
public function replaceFile(File $fileEntity, UploadedFile $file)
	{
		$entityManager = $this->getDoctrineEntityManager();
		$oldFileIsImage = $fileEntity instanceof Image;
		$newFileIsImage = $this->isMimeTypeImage($file->getMimeType());

		if ($oldFileIsImage !== $newFileIsImage) {
			throw new Exception\UploadFilterException(self::VALIDATION_IMAGE_TO_FILE_REPLACE_MESSAGE_KEY, 'New file should be image too');
		}

		$originalFile = clone($fileEntity);
		$entityManager->detach($originalFile);

		// setting new data
		// The name is not changed by Bug #6756
//		$fileEntity->setFileName($file['name']);
		$fileEntity->setSize($file->getSize());
		$fileEntity->setMimeType($file->getMimeType());

		// This must be call before removing the old file
		$this->validateFileUpload($fileEntity, $file->getPathname());

		$this->removeFileInFileSystem($originalFile);

		$this->storeFileData($fileEntity, $file->getPathname());

		// additional jobs for images
		if ($fileEntity instanceof Image) {
			
			$imageProcessor  = $this->getImageResizer();
			// store original size
			$imageInfo = $imageProcessor->getImageInfo($fileEntity);
			$fileEntity->setWidth($imageInfo->getWidth());
			$fileEntity->setHeight($imageInfo->getHeight());
			// reprocess sizes
			$this->recreateImageSizes($fileEntity);
		}

		$fileEntity->setModificationTime();

		$entityManager->flush();
	}
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);
    }
376383
public function create($name, $extension = null, $table = null, $create = false)
    {
        $migrationPath = $this->getMigrationPath($extension);

        $path = $this->getPath($name, $migrationPath);

        $stub = $this->getStub($table, $create);

        $this->files->put($path, $this->populateStub($stub, $table));

        return $path;
    }
64001
public function beforeSave(Event $event, Entity $entity) {
        // configuration set?
        $this->check();

        // go through each field
        foreach($this->_config['fields'] as $field => $path) {
            // get uploaded file info
            $file = $entity->get($field);

            // no file or not array? problem...
            if(!($file && is_array($entity[$field])))
                continue;

            // file not ok? skip
            if($file['error'] !== UPLOAD_ERR_OK) {
                $entity->set($field, '');
                continue;
            }

            // get the final name
            $final = $this->formatFile($entity, $file, $path);

            // create the folder
            $folder = new Folder($this->_config['root']);
            $folder->create($this->_config['root'] . dirname($final));

            // copy file, delete old file and set new file in entity
            $file = new File($file['tmp_name']);
            if($file->copy($this->_config['root'] . $final)) {
                $this->deleteFile($entity->extractOriginalChanged([$field])[$field] ?? null);
                $entity->set($field, '/' . str_replace(DS, '/', $final));
            } else $entity->set($field, '');
        }
    }
1058470
private void importSingleFile(String file, String toplevelCorpusName,
    long corpusRef)
  {

    BinaryImportHelper preStat = new BinaryImportHelper(file, getRealDataDir(),
      toplevelCorpusName,
      corpusRef, mimeTypeMapping);
    getJdbcTemplate().execute(BinaryImportHelper.SQL, preStat);

  }
971737
public static function create($data = [], Entity $entity = null)
    {
        $record = new static($data, $entity);

        $record->save();

        return $record;
    }
479943
public static function create($table, $callback)
	{
		$table = new Table($table);

		// To indicate that the table is new and needs to be created, we'll run
		// the "create" command on the table instance. This tells schema it is
		// not simply a column modification operation.
		$table->create();

		call_user_func($callback, $table);

		return static::execute($table);
	}
895132
public function import( $key, $source ) {
		$filename = $this->prepare_write( $key );

		if ( $filename ) {
			return copy( $source, $filename ) && touch( $filename );
		}

		return false;
	}
824129
public function import($fileData, $workspace = null)
    {
        $ical = new ICal($fileData);
        $events = $ical->events();
        $entities = [];

        foreach ($events as $event) {
            $e = new Event();
            $e->setTitle($event->summary);
            $e->setStart($ical->iCalDateToUnixTimestamp($event->dtstart));
            $e->setEnd($ical->iCalDateToUnixTimestamp($event->dtend));
            $e->setDescription($event->description);
            if ($workspace) {
                $e->setWorkspace($workspace);
            }
            $e->setUser($this->tokenStorage->getToken()->getUser());
            $e->setPriority('#01A9DB');
            $this->om->persist($e);
            //the flush is required to generate an id
            $this->om->flush();
            $entities[] = $e;
        }

        return $entities;
    }