diff --git a/app/Jobs/DeleteCrmCustomerJob.php b/app/Jobs/DeleteCrmCustomerJob.php index b342131..d65296f 100644 --- a/app/Jobs/DeleteCrmCustomerJob.php +++ b/app/Jobs/DeleteCrmCustomerJob.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; class DeleteCrmCustomerJob implements ShouldQueue @@ -44,36 +45,38 @@ class DeleteCrmCustomerJob implements ShouldQueue $hashchode = $this->customer['hashcode']; $email = $this->customer['email']; - // For baskets and old walls. - $contact = Contact::where('contact_ref', $hashchode)->first(); - if ($contact) { - $contact->murs()->delete(); - $contact->paniers()->delete(); - $contact->logs()->delete(); - $contact->delete(); + DB::transaction(function () use ($hashchode, $email) { + // For baskets and old walls. + $contact = Contact::where('contact_ref', $hashchode)->first(); + if ($contact) { + $contact->murs()->delete(); + $contact->paniers()->delete(); + $contact->logs()->delete(); + $contact->delete(); - Log::channel('crm')->info( - sprintf( - "Hashcode : %s - Email : %s - Contact deleted.", - $hashchode, - $email - ) - ); - } + Log::channel('crm')->info( + sprintf( + "Hashcode : %s - Email : %s - Contact deleted.", + $hashchode, + $email + ) + ); + } - // For walls. - $customer = Customers::where('hashcode', $hashchode)->first(); - if ($customer) { - $customer->printedWalls()->delete(); - $customer->delete(); + // For walls. + $customer = Customers::where('hashcode', $hashchode)->first(); + if ($customer) { + $customer->printedWalls()->delete(); + $customer->delete(); - Log::channel('crm')->info( - sprintf( - "Hashcode : %s - Email : %s - Customer deleted.", - $hashchode, - $email - ) - ); - } + Log::channel('crm')->info( + sprintf( + "Hashcode : %s - Email : %s - Customer deleted.", + $hashchode, + $email + ) + ); + } + }); } }