Add missing parts for delete customer (jobs) but deny removing customers (on Model)
This commit is contained in:
parent
95bb4e3b09
commit
5ba294b496
3 changed files with 27 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ class Kernel extends ConsoleKernel
|
|||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->job(DeleteOldCustomers::class)->dailyAt('22:50');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
23
app/Jobs/DeleteOlds/DeleteOldCustomers.php
Normal file
23
app/Jobs/DeleteOlds/DeleteOldCustomers.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\DeleteOlds;
|
||||
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Delete customers that are older than 36 months
|
||||
*/
|
||||
class DeleteOldCustomers
|
||||
{
|
||||
/**
|
||||
* Called when the job will be executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Log::debug(__CLASS__ . ' Removing old customers');
|
||||
Customer::query()->withTrashed()->where('last_connection', '<=', now()->subMonths(36))->forceDelete();
|
||||
}
|
||||
}
|
||||
|
|
@ -70,6 +70,9 @@ class Customer extends Authenticatable implements MustVerifyEmail
|
|||
static::updating(function (self $model) {
|
||||
static::assertEmailIsUnique($model->id, $model->email);
|
||||
});
|
||||
static::deleting(function () {
|
||||
throw new \RuntimeException('This cannot be done à cause de MesBR');
|
||||
});
|
||||
static::deleted(function (self $model) {
|
||||
if ($model->forceDeleting) {
|
||||
if ($model->existsInCrm()) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue