From 62358aec4ef8cfb28f4d6d7cb776237cd0af9921 Mon Sep 17 00:00:00 2001 From: IceToast Date: Thu, 2 Feb 2023 23:19:08 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Add=20open=20payments=20cle?= =?UTF-8?q?anup=20to=20schedule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/ChargeCreditsCommand.php | 4 +- app/Console/Commands/CleanupPayments.php | 42 +++++++++++++++++++ app/Console/Kernel.php | 5 ++- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 app/Console/Commands/CleanupPayments.php diff --git a/app/Console/Commands/ChargeCreditsCommand.php b/app/Console/Commands/ChargeCreditsCommand.php index e51bfdf9..145943c7 100644 --- a/app/Console/Commands/ChargeCreditsCommand.php +++ b/app/Console/Commands/ChargeCreditsCommand.php @@ -67,7 +67,7 @@ class ChargeCreditsCommand extends Command $server->suspend(); //add user to notify list - if (! in_array($user, $this->usersToNotify)) { + if (!in_array($user, $this->usersToNotify)) { array_push($this->usersToNotify, $user); } } catch (\Exception $exception) { @@ -85,7 +85,7 @@ class ChargeCreditsCommand extends Command */ public function notifyUsers() { - if (! empty($this->usersToNotify)) { + if (!empty($this->usersToNotify)) { /** @var User $user */ foreach ($this->usersToNotify as $user) { $this->line("Notified user: {$user->name}"); diff --git a/app/Console/Commands/CleanupPayments.php b/app/Console/Commands/CleanupPayments.php new file mode 100644 index 00000000..eca142a8 --- /dev/null +++ b/app/Console/Commands/CleanupPayments.php @@ -0,0 +1,42 @@ +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; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 5f081211..ac055581 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -18,10 +18,11 @@ class Kernel extends ConsoleKernel { $schedule->command('credits:charge')->hourly(); $schedule->command('cp:versioncheck:get')->daily(); + $schedule->command('payments:clear')->daily(); //log cronjob activity $schedule->call(function () { - Storage::disk('logs')->put('cron.log', 'Last activity from cronjobs - '.now()); + Storage::disk('logs')->put('cron.log', 'Last activity from cronjobs - ' . now()); })->everyMinute(); } @@ -32,7 +33,7 @@ class Kernel extends ConsoleKernel */ protected function commands() { - $this->load(__DIR__.'/Commands'); + $this->load(__DIR__ . '/Commands'); require base_path('routes/console.php'); }