From b0f1bb46d7968b0d7b91c929f0ee878ae0705bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Carodej?= Date: Wed, 6 Apr 2022 09:36:10 +0200 Subject: [PATCH] clear howdy file requests in demo account --- src/App/Console/Kernel.php | 4 +-- .../Demo/Actions/ClearHowdyDemoDataAction.php | 30 +++++++++++++++++++ .../DeleteAllDemoSharedLinksAction.php | 20 ------------- tests/Support/Demo/DemoTest.php | 4 +-- 4 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 src/Support/Demo/Actions/ClearHowdyDemoDataAction.php delete mode 100644 src/Support/Demo/Actions/DeleteAllDemoSharedLinksAction.php diff --git a/src/App/Console/Kernel.php b/src/App/Console/Kernel.php index 157c7dd4..167af946 100644 --- a/src/App/Console/Kernel.php +++ b/src/App/Console/Kernel.php @@ -5,7 +5,7 @@ use Illuminate\Console\Scheduling\Schedule; use App\Console\Commands\SetupDevEnvironment; use App\Console\Commands\SetupProdEnvironment; use Support\Scheduler\Actions\ReportUsageAction; -use Support\Demo\Actions\DeleteAllDemoSharedLinksAction; +use Support\Demo\Actions\ClearHowdyDemoDataAction; use Support\Scheduler\Actions\DeleteFailedFilesAction; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Support\Scheduler\Actions\DeleteUnverifiedUsersAction; @@ -43,7 +43,7 @@ class Kernel extends ConsoleKernel if (is_demo()) { $schedule->call( - fn () => resolve(DeleteAllDemoSharedLinksAction::class)() + fn () => resolve(ClearHowdyDemoDataAction::class)() )->daily()->at('00:00'); } diff --git a/src/Support/Demo/Actions/ClearHowdyDemoDataAction.php b/src/Support/Demo/Actions/ClearHowdyDemoDataAction.php new file mode 100644 index 00000000..03c9502a --- /dev/null +++ b/src/Support/Demo/Actions/ClearHowdyDemoDataAction.php @@ -0,0 +1,30 @@ +first(); + + // Delete howdy shared links + DB::table('shares') + ->where('user_id', $user->id) + ->delete(); + + // Delete File request + UploadRequest::where('user_id', $user->id) + ->cursor() + ->each(function ($request) { + if ($request->created_at->diffInHours(now()) >= 6) { + $request->delete(); + } + }); + } +} diff --git a/src/Support/Demo/Actions/DeleteAllDemoSharedLinksAction.php b/src/Support/Demo/Actions/DeleteAllDemoSharedLinksAction.php deleted file mode 100644 index a736a984..00000000 --- a/src/Support/Demo/Actions/DeleteAllDemoSharedLinksAction.php +++ /dev/null @@ -1,20 +0,0 @@ -first(); - - // Delete howdy shared links - DB::table('shares') - ->where('user_id', $user->id) - ->delete(); - } -} diff --git a/tests/Support/Demo/DemoTest.php b/tests/Support/Demo/DemoTest.php index ffc80e37..ad40f6ac 100644 --- a/tests/Support/Demo/DemoTest.php +++ b/tests/Support/Demo/DemoTest.php @@ -4,7 +4,7 @@ namespace Tests\Support\Demo; use Tests\TestCase; use App\Users\Models\User; use Domain\Sharing\Models\Share; -use Support\Demo\Actions\DeleteAllDemoSharedLinksAction; +use Support\Demo\Actions\ClearHowdyDemoDataAction; class DemoTest extends TestCase { @@ -29,7 +29,7 @@ class DemoTest extends TestCase Share::factory() ->create(['user_id' => $howdy->id]); - resolve(DeleteAllDemoSharedLinksAction::class)(); + resolve(ClearHowdyDemoDataAction::class)(); $this->assertDatabaseHas('shares', [ 'user_id' => $user->id,