Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117860130
D5004.1775318671.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D5004.1775318671.diff
View Options
diff --git a/src/app/Console/Commands/DB/ExpungeCommand.php b/src/app/Console/Commands/DB/ExpungeCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/DB/ExpungeCommand.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace App\Console\Commands\DB;
+
+use Carbon\Carbon;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
+
+class ExpungeCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'db:expunge';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Expunge old records from the database tables';
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ \App\Policy\Greylist\Connect::where('updated_at', '<', Carbon::now()->subMonthsWithoutOverflow(6))
+ ->delete();
+
+ \App\Policy\Greylist\Whitelist::where('updated_at', '<', Carbon::now()->subMonthsWithoutOverflow(6))
+ ->delete();
+
+ \App\Policy\RateLimit::where('updated_at', '<', Carbon::now()->subMonthsWithoutOverflow(6))
+ ->delete();
+
+ \App\SignupCode::where('created_at', '<', Carbon::now()->subMonthsWithoutOverflow(6))
+ ->forceDelete();
+
+ DB::table('failed_jobs')->where('failed_at', '<', Carbon::now()->subMonthsWithoutOverflow(6))
+ ->delete();
+
+ // TODO: What else? Should we force-delete deleted "dummy/spammer" accounts?
+ }
+}
diff --git a/src/app/Console/Kernel.php b/src/app/Console/Kernel.php
--- a/src/app/Console/Kernel.php
+++ b/src/app/Console/Kernel.php
@@ -40,6 +40,9 @@
// This removes passport expired/revoked tokens and auth codes from the database
$schedule->command('passport:purge')->dailyAt('06:30');
+
+ // Keep the database size under control (every Monday)
+ $schedule->command('db:expunge')->weeklyOn(1, '04:00');
}
/**
diff --git a/src/tests/Feature/Console/DB/ExpungeTest.php b/src/tests/Feature/Console/DB/ExpungeTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/DB/ExpungeTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Tests\Feature\Console\DB;
+
+use Tests\TestCase;
+
+class ExpungeTest extends TestCase
+{
+ /**
+ * Test command runs
+ */
+ public function testHandle(): void
+ {
+ $code = \Artisan::call("db:expunge");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 4, 4:04 PM (16 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18830298
Default Alt Text
D5004.1775318671.diff (2 KB)
Attached To
Mode
D5004: db:expunge command
Attached
Detach File
Event Timeline