Last active
August 9, 2017 05:25
-
-
Save jarbitlira/cdaf4fc3ecae7c2887c3a3767fb084d9 to your computer and use it in GitHub Desktop.
ImportJob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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