diff --git a/app/Console/Commands/DeleteUnconfirmedCustomers.php b/app/Console/Commands/DeleteUnconfirmedCustomers.php index bb633e6..fa3ab31 100644 --- a/app/Console/Commands/DeleteUnconfirmedCustomers.php +++ b/app/Console/Commands/DeleteUnconfirmedCustomers.php @@ -2,12 +2,13 @@ namespace App\Console\Commands; -use App\Models\CustomerInfo; +use App\Models\Customer; use App\Models\CustomerLogin; use App\Models\CustomerOptInHistory; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; /** * @codeCoverageIgnore @@ -37,20 +38,22 @@ class DeleteUnconfirmedCustomers extends Command public function handle() { /** @var \Illuminate\Database\Eloquent\Collection $customersLogins */ - $customersLogins = CustomerLogin::whereStatus(false)->where('created_at', '<', Carbon::now()->subDay(1))->get(); + $customersLogins = CustomerLogin::whereStatus(false) + ->where('created_at', '<', Carbon::now()->subDay(1)) + ->with(['brand', 'customer']) + ->get(); $customersLogins->map(function (CustomerLogin $customerLogin) { + Log::info($customerLogin->customer_id); DB::transaction(function () use ($customerLogin) { /** @var \App\Models\Customer $customer */ $customer = $customerLogin->customer; - // * Si non activé et créer il y a plus d'un jour : Suppression. - $customerLogin->customer->infos()->where('brand_id', $customerLogin->brand_id) - ->get()->map(function (CustomerInfo $customerInfo) { - $customerInfo->deleteOrFail(); - }); + /** @var \App\Models\Brand */ + $brand = $customerLogin->brand; // * Suppression de ses infos de login pour la marque. - $customerLogin->deleteOrFail(); + $customer->info($brand, Customer::FIRST_OR_FAIL)->deleteOrFail(); + $customer->login($brand, Customer::FIRST_OR_FAIL)->deleteOrFail(); // * Si le customer n'a plus d'info il n'a donc plus besoin de compte en crm. if (!$customer->infos()->count()) {