diff --git a/src/Http/Controllers/Subscribers/SubscribersImportController.php b/src/Http/Controllers/Subscribers/SubscribersImportController.php index 5de89284..8c1f9455 100644 --- a/src/Http/Controllers/Subscribers/SubscribersImportController.php +++ b/src/Http/Controllers/Subscribers/SubscribersImportController.php @@ -8,8 +8,10 @@ use Exception; use Illuminate\Contracts\View\View as ViewContract; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Str; use Rap2hpoutre\FastExcel\FastExcel; use Sendportal\Base\Http\Controllers\Controller; use Sendportal\Base\Http\Requests\SubscribersImportRequest; @@ -44,14 +46,14 @@ public function show(SegmentTenantRepository $segmentRepo): ViewContract public function store(SubscribersImportRequest $request): RedirectResponse { if ($request->file('file')->isValid()) { - $filename = str_random(16) . '.csv'; + $filename = Str::random(16) . '.csv'; $path = $request->file('file')->storeAs('imports', $filename); $subscribers = (new FastExcel)->import(storage_path('app/' . $path), function (array $line) use ($request) { // TODO: validate each row beforehand try { - $data = array_only($line, ['id', 'email', 'first_name', 'last_name']); + $data = Arr::only($line, ['id', 'email', 'first_name', 'last_name']); $data['segments'] = $request->get('segments') ?? []; diff --git a/src/Services/Subscribers/ImportSubscriberService.php b/src/Services/Subscribers/ImportSubscriberService.php index cdc06774..be75b1ca 100644 --- a/src/Services/Subscribers/ImportSubscriberService.php +++ b/src/Services/Subscribers/ImportSubscriberService.php @@ -2,6 +2,7 @@ namespace Sendportal\Base\Services\Subscribers; +use Illuminate\Support\Arr; use Sendportal\Base\Models\Subscriber; use Sendportal\Base\Repositories\SubscriberTenantRepository; use Exception; @@ -28,19 +29,19 @@ public function import(int $workspaceId, array $data): Subscriber { $subscriber = null; - if (!empty(\Arr::get($data, 'id'))) { + if (!empty(Arr::get($data, 'id'))) { $subscriber = $this->subscribers->findBy($workspaceId, 'id', $data['id'], ['segments']); } if (!$subscriber) { - $subscriber = $this->subscribers->findBy($workspaceId, 'email', \Arr::get($data, 'email'), ['segments']); + $subscriber = $this->subscribers->findBy($workspaceId, 'email', Arr::get($data, 'email'), ['segments']); } if (!$subscriber) { - $subscriber = $this->subscribers->store($workspaceId, array_except($data, ['id', 'segments'])); + $subscriber = $this->subscribers->store($workspaceId, Arr::except($data, ['id', 'segments'])); } - $data['segments'] = array_merge($subscriber->segments->pluck('id')->toArray(), \Arr::get($data, 'segments')); + $data['segments'] = array_merge($subscriber->segments->pluck('id')->toArray(), Arr::get($data, 'segments')); $this->subscribers->update($workspaceId, $subscriber->id, $data);