Skip to content

Instantly share code, notes, and snippets.

@jarbitlira
Last active August 9, 2017 05:25
Show Gist options
  • Save jarbitlira/cdaf4fc3ecae7c2887c3a3767fb084d9 to your computer and use it in GitHub Desktop.
Save jarbitlira/cdaf4fc3ecae7c2887c3a3767fb084d9 to your computer and use it in GitHub Desktop.
ImportJob
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class ImportCsv implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $filePath;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($filePath)
{
$this->filePath = $filePath;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
/*
Get PD0 connection and insert data in csv file
*/
\DB::connection()->getPdo()
->exec("
LOAD DATA LOCAL INFILE '{$this->filePath}'
INTO TABLE imports
FIELDS TERMINATED BY ','
IGNORE 1 ROWS
(
`email`, `fname`, `lname`,
`address`, `city`, `state`,
`zip`, `phone`, `ip`,
`datetime`, `source`, `gender`,
`birth`, @deliveryverified, `verify_date`,
`smtpresponse`
)
SET created_at = now(),
updated_at = now(),
deliveryverified = if(@deliveryverified = 'yes', true, deliveryverified);");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment