Skip to content

Commit f2cfc86

Browse files
authored
✨ Data Cleanup Jobs (#3482)
1 parent 0a508ce commit f2cfc86

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Console\Commands\DatabaseCleaner;
4+
5+
use Illuminate\Console\Command;
6+
use Spatie\Activitylog\Models\Activity;
7+
8+
class CleanUpActivity extends Command
9+
{
10+
protected $signature = 'app:clean-up-activity';
11+
12+
protected $description = 'Delete all activity logs older than 30 days';
13+
14+
public function handle(): int {
15+
$this->info('Cleaning up activity logs older than 30 days...');
16+
17+
// Assuming you have a model named ActivityLog
18+
$deletedCount = Activity::where('created_at', '<', now()->subDays(30))->delete();
19+
20+
if ($deletedCount) {
21+
$this->info("Deleted $deletedCount old activity logs.");
22+
} else {
23+
$this->info('No old activity logs found to delete.');
24+
}
25+
26+
return 0;
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Console\Commands\DatabaseCleaner;
4+
5+
use App\Models\EventSuggestion;
6+
use Illuminate\Console\Command;
7+
8+
class CleanUpEventSuggestions extends Command
9+
{
10+
protected $signature = 'app:clean-up-event-suggestions';
11+
12+
protected $description = 'Delete all event suggestions with begin older than 30 days';
13+
14+
public function handle(): int {
15+
$this->info('Cleaning up event suggestions older than 30 days...');
16+
17+
// Assuming you have a model named EventSuggestion
18+
$deletedCount = EventSuggestion::where('begin', '<', now()->subDays(30))->delete();
19+
20+
if ($deletedCount) {
21+
$this->info("Deleted $deletedCount old event suggestions.");
22+
} else {
23+
$this->info('No old event suggestions found to delete.');
24+
}
25+
26+
return 0;
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Console\Commands\DatabaseCleaner;
4+
5+
use Illuminate\Console\Command;
6+
use Laravel\Passport\Passport;
7+
8+
class CleanUpTokens extends Command
9+
{
10+
protected $signature = 'app:clean-up-tokens';
11+
protected $description = 'Delete all tokens expired more than 30 days';
12+
13+
public function handle(): int {
14+
$this->info('Cleaning up tokens older than 30 days...');
15+
16+
// Assuming you have a model named Token
17+
$deletedCount = Passport::tokenModel()::where('expires_at', '<', now()->subDays(30))->delete();
18+
19+
if ($deletedCount) {
20+
$this->info("Deleted $deletedCount old tokens.");
21+
} else {
22+
$this->info('No old tokens found to delete.');
23+
}
24+
25+
return 0;
26+
}
27+
}

app/Console/Commands/DatabaseCleaner/DatabaseCleaner.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public function handle(): int {
1919
$this->call(Trips::class);
2020
$this->call(RefreshPrometheusCache::class);
2121
$this->call(CleanUpDanglingStatuses::class);
22+
$this->call(CleanUpActivity::class);
23+
$this->call(CleanUpEventSuggestions::class);
24+
$this->call(CleanUpTokens::class);
2225

2326
$this->call('queue-monitor:purge', ['--beforeDays' => 7]);
2427
$this->call('activitylog:clean');

0 commit comments

Comments
 (0)