From ad7be2306e1fa314475c961d2b9f1d70da5f72a5 Mon Sep 17 00:00:00 2001 From: Mat Fish Date: Sat, 8 Jul 2023 12:35:18 +0300 Subject: [PATCH] confirm pruning --- CHANGELOG.md | 4 ++++ src/controllers/console/LogsController.php | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 519acf7..2c1900a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/controllers/console/LogsController.php b/src/controllers/console/LogsController.php index 75c1c24..90b2763 100644 --- a/src/controllers/console/LogsController.php +++ b/src/controllers/console/LogsController.php @@ -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; }