Giter Site home page Giter Site logo

yii2-csv-importer's People

Contributors

ruskid avatar stupidusername avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-csv-importer's Issues

private functions

Hi,

Is it possible to stop using private functions? I'd like to extend a few of these functions for some custom code but am unable to as everything is private.

Thanks,

bw

How to validate against model rules?

I am using MultipleImportStrategy

public function actionUploadCsv() {
$model = new MonitoringCsvForm();
$importer = new CSVImporter();

	if (Yii::$app->request->isPost) {
		$model->file = UploadedFile::getInstance ( $model, 'file' );
		
		if ($model->file && $model->validate ()) {
			
			$importer->setData ( new CSVReader ( [ 
					'filename' => $model->file->tempName,
					'fgetcsvOptions' => [ 
							'delimiter' => ',' 
					] 
			] ) );
			
			$importer->import ( new MultipleImportStrategy ( [ 
					'tableName' => UsersMonitoring::tableName (),
					'configs' => [ 
							[ 
									'attribute' => 'user_id',
									'value' => function ($line) {
										return $line [0];
									} 
							],
							[ 
									'attribute' => 'country',
									'value' => function ($line) {
										return $line [1];
									} 
							],
							[ 
									'attribute' => 'reg_code',
									'value' => function ($line) {
										return $line [2];
									} 
							],
							[ 
									'attribute' => 'start_date',
									'value' => function ($line) {
										return $line [3];
									} 
							],
							[ 
									'attribute' => 'end_date',
									'value' => function ($line) {
										return $line [4];
									} 
							],
							[ 
									'attribute' => 'condition_by_group',
									'value' => function ($line) {
										return $line [5];
									} 
							],
							[ 
									'attribute' => 'comment',
									'value' => function ($line) {
										return $line [6];
									} 
							] 
					] 
			] ) );
			
			// return $this->render('upload-csv', ['model' => $model]);
			Yii::$app->session->setFlash ( 'successMessage', Yii::t ( 'main', 'Records have been added' ) );
			return $this->redirect ( 'index' );
		}
	}
	
	return $this->render ( 'upload-csv', [ 
			'model' => $model 
	] );
}
How can I validate CSV data against my model and show error if rules don't pass?

Does not work for big CSV files.

The component loads the whole files into memory.
Then parses the whole result as arrays in memory again.
At the moment there is no easy way to work-around this.

I had to move on an existing project to league/csv to workaround this limitations on an inherited project handling 500k+ row CSV files.

Possible to use with tab delimited file?

I'm sorry to create an issue for this. Does this extension work with tab delimited files? I'm trying to set the delimiter to'\t', but I get the error fgetcsv(): delimiter must be a single character.

Create a release!!!

Would you please create a release?

Installing your package when ours requires yours, is a PITA.

When you have min stability set to stable, as one should in their main production repo, you can not install a package that requires yours because it is dev-master.

- main project
  |->my package
     \-> your package

So to install my package, I have to manually install yours in the main repo first, to force it to accept it. That completely goes against the point of composer. My package should be able to install it's required dependencies (ie: yours) streamlined with one command.

So please, click "Releases", create a release, and tag it v1.0.0.

Thanks

No rows affected.

I'm trying out this plugin with the following example:

//Import multiple (Fast but not reliable). Will return number of inserted rows
$numberRowsAffected = $importer->import(new MultipleImportStrategy([
    'tableName' => VendorSwType::tableName(),
    'configs' => [
        [
            'attribute' => 'name',
            'value' => function($line) {
                return $line[1];
            },
            'unique' => true, //Will filter and import unique values only. can by applied for 1+ attributes
        ]
    ],
]));

But var_dump of $numberRowsAffected is 0.

This line is suspicious. It is unsetting all the lines.

Large CSV file

Hi,
i'm using this extension and works great!
Now i need to import a 18MBytes file (>100.000 records) and i get the typical 'Out Of Memory' error:
PHP Fatal Error โ€“ yii\base\ErrorException
Allowed memory size of 268435456 bytes exhausted
In my test webserver i coud increase the php memory limit to 2GB and the file is imported but i can't do this in my production server.
I'm using this code:

`

    //Import multiple (Fast but not reliable). Will return number of inserted rows
    $numberRowsAffected = $importer->import(new MultipleImportStrategy([
        'tableName' => $table,
        'configs' => [
            [
                'attribute' => 'first_attribute',
                'value' => function($line) {

.....`

Any help?
Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.