File size: 1,645 Bytes
89a1081 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | <?php
namespace App\Jobs;
use App\Models\Import;
use App\Service\Admin\Contact\ContactService;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ImportJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public string $imported;
/**
* Create a new job instance.
*
* @param string $imported importId
*/
public function __construct(string $imported)
{
$this->imported = $imported;
$this->onQueue('default');
}
/**
* Execute the job.
*
* @param ImportContactService $importContactService
* @return void
* @throws Exception
*/
public function handle(ContactService $contactService): void
{
try {
$import = Import::where('id', $this->imported)
->where('status', 0)
->first();
if (!$import) return;
$import->status = 1;
$import->save();
if($import->mime == 'csv' || $import->mime = 'xlsv') {
$contactService->importContactFormFile($import->name, $import->path, $import->contact_structure, $import->group_id, $import->user_id);
} else {
return;
}
} catch(\Exception $e) {
\Log::error("ImportJob failed: " . $e->getMessage());
}
}
}
|