2023-02-02 22:19:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use App\Models\Payment;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
2023-02-06 10:57:14 +00:00
|
|
|
class CleanupOpenPayments extends Command
|
2023-02-02 22:19:08 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-02-02 22:21:52 +00:00
|
|
|
protected $signature = 'payments:open:clear';
|
2023-02-02 22:19:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Clears all payments from the database that have state "open"';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
// delete all payments that have state "open" and are older than 1 hour
|
|
|
|
try {
|
|
|
|
Payment::where('status', 'open')->where('updated_at', '<', now()->subHour())->delete();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->error('Could not delete payments: ' . $e->getMessage());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->info('Successfully deleted all open payments');
|
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|