Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F16510692
D5004.id14328.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D5004.id14328.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/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
Mon, Oct 28, 8:32 PM (22 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10050909
Default Alt Text
D5004.id14328.diff (2 KB)
Attached To
Mode
D5004: db:expunge command
Attached
Detach File
Event Timeline
Log In to Comment