fix: Put all database actions in a transaction for the DeleteCrmCustomer job
This commit is contained in:
parent
715c83f9fc
commit
e0075ab68c
1 changed files with 31 additions and 28 deletions
|
|
@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue