Skip to content

Commit

Permalink
confirm pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Jul 8, 2023
1 parent 7dfb38e commit ad7be23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Activity Log

## 1.5.2 - 2023-07-08
### Improved
- Add a confirmation message to the prune command with number of days and date

## 1.5.1 - 2023-07-05
### Added
- Add Payload Search (optional field, enable in Settings page)
Expand Down
14 changes: 10 additions & 4 deletions src/controllers/console/LogsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ public function options($actionID): array

public function actionPrune()
{
$cutoff = Carbon::today()->subDays($this->days ?? 30);
$days = $this->days;

$this->stdout('Pruning records before ' . $cutoff->format('d-m-Y') . '...' . PHP_EOL, Console::FG_GREEN);
$cutoff = Carbon::today()->subDays($days);

ActivityLog::deleteAll(['<', 'createdAt', $cutoff->format('Y-m-d')]);
if ($this->confirm("Are you sure you want to permanently delete all records before the last {$days} days (" .$cutoff->format('d-m-Y') . ")?")) {
$this->stdout('Pruning records before ' . $cutoff->format('d-m-Y') . '...' . PHP_EOL, Console::FG_GREEN);

$this->stdout('Done!' . PHP_EOL, Console::FG_GREEN);
ActivityLog::deleteAll(['<', 'createdAt', $cutoff->format('Y-m-d')]);

$this->stdout('Done!' . PHP_EOL, Console::FG_GREEN);
} else {
$this->stdout('Aborted' . PHP_EOL, Console::FG_YELLOW);
}

return 1;
}
Expand Down

0 comments on commit ad7be23

Please sign in to comment.