-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new purge commands, scheduled purge task to run daily
- Loading branch information
Showing
5 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Fleetbase\Console\Commands; | ||
|
||
use Fleetbase\Traits\PurgeCommand; | ||
use Illuminate\Console\Command; | ||
use Spatie\Activitylog\Models\Activity; | ||
|
||
class PurgeActivityLogs extends Command | ||
{ | ||
use PurgeCommand; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'purge:activity-logs | ||
{--days=30 : The number of days to preserve logs (default: 30)}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Purges Activity logs older than the specified number of days, with an option to back up records before deletion.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): void | ||
{ | ||
// Determine the number of days to preserve | ||
$days = (int) $this->option('days'); | ||
if ($days <= 0) { | ||
$this->error('The number of days must be a positive integer.'); | ||
|
||
return; | ||
} | ||
|
||
$this->info("Purging Activity logs older than {$days} days..."); | ||
|
||
// Calculate the cutoff date | ||
$cutoffDate = now()->subDays($days); | ||
|
||
// Backup and purge logs | ||
$this->backupAndDelete(Activity::class, 'activity', $cutoffDate, 'backups/activity-logs'); | ||
|
||
$this->info('Purge completed successfully.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Fleetbase\Console\Commands; | ||
|
||
use Fleetbase\Traits\PurgeCommand; | ||
use Illuminate\Console\Command; | ||
use Spatie\ScheduleMonitor\Models\MonitoredScheduledTaskLogItem; | ||
|
||
class PurgeScheduledTaskLogs extends Command | ||
{ | ||
use PurgeCommand; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'purge:scheduled-task-logs | ||
{--days=30 : The number of days to preserve logs (default: 30)}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Purges Activity logs older than the specified number of days, with an option to back up records before deletion.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): void | ||
{ | ||
// Determine the number of days to preserve | ||
$days = (int) $this->option('days'); | ||
if ($days <= 0) { | ||
$this->error('The number of days must be a positive integer.'); | ||
|
||
return; | ||
} | ||
|
||
$this->info("Purging Scheduled Task logs older than {$days} days..."); | ||
|
||
// Calculate the cutoff date | ||
$cutoffDate = now()->subDays($days); | ||
|
||
// Backup and purge logs | ||
$this->backupAndDelete(MonitoredScheduledTaskLogItem::class, 'monitored_scheduled_task_log_items', $cutoffDate, 'backups/scheduled-task-logs'); | ||
|
||
$this->info('Purge completed successfully.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters