From b96e2fb52c61fe2d961d16b939e849c1a399361a Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Thu, 23 Oct 2025 15:40:54 +0100 Subject: [PATCH 1/3] Added migration to fix incorrect action_type in action_log --- ..._144927_migrate_incorrect_action_types.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 database/migrations/2025_10_22_144927_migrate_incorrect_action_types.php diff --git a/database/migrations/2025_10_22_144927_migrate_incorrect_action_types.php b/database/migrations/2025_10_22_144927_migrate_incorrect_action_types.php new file mode 100644 index 0000000000..7eff84667a --- /dev/null +++ b/database/migrations/2025_10_22_144927_migrate_incorrect_action_types.php @@ -0,0 +1,38 @@ +where('action_type', 'request_canceled')->update(['action_type' => 'request canceled']); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // no down migration for this one + } +}; From f7bc538fdf39f8fec0d9869974acb3c425ca6008 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Mon, 3 Nov 2025 15:39:31 +0000 Subject: [PATCH 2/3] Intorduce ActionType enum and ensure all logactions are using it --- app/Enums/ActionType.php | 33 +++++++++++++++++++ app/Http/Controllers/ViewAssetsController.php | 3 +- app/Models/Actionlog.php | 8 +++-- app/Presenters/ActionlogPresenter.php | 2 +- 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 app/Enums/ActionType.php diff --git a/app/Enums/ActionType.php b/app/Enums/ActionType.php new file mode 100644 index 0000000000..6798a6b78e --- /dev/null +++ b/app/Enums/ActionType.php @@ -0,0 +1,33 @@ +isRequestedBy($user)) || $cancel_by_admin) { $item->cancelRequest($requestingUser); $data['item_quantity'] = ($item_request) ? $item_request->qty : 1; - $logaction->logaction('request_canceled'); + $logaction->logaction(ActionType::RequestCanceled); if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) { $settings->notify(new RequestAssetCancelation($data)); diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index 786246778c..4a12835a9d 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -9,6 +9,7 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Str; +use App\Enums\ActionType; /** * Model for the Actionlog (the table that keeps a historical log of @@ -335,9 +336,12 @@ class Actionlog extends SnipeModel * @since [v3.0] * @return bool */ - public function logaction($actiontype) + public function logaction(string|ActionType $actiontype) { - $this->action_type = $actiontype; + if (is_string($actiontype)) { + $actiontype = ActionType::from($actiontype); + } + $this->action_type = $actiontype->value; $this->remote_ip = request()->ip(); $this->user_agent = request()->header('User-Agent'); $this->action_source = $this->determineActionSource(); diff --git a/app/Presenters/ActionlogPresenter.php b/app/Presenters/ActionlogPresenter.php index 0f82d1f667..a2dc75113d 100644 --- a/app/Presenters/ActionlogPresenter.php +++ b/app/Presenters/ActionlogPresenter.php @@ -102,7 +102,7 @@ class ActionlogPresenter extends Presenter return 'fa-solid fa-rotate-right'; } - if ($this->action_type == 'note_added') { + if ($this->action_type == 'note added') { return 'fas fa-sticky-note'; } From 27d74494591ddc04d51c5cd5fc3aa06e06958930 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Tue, 4 Nov 2025 14:04:37 +0000 Subject: [PATCH 3/3] Fix comment to properly reflext the current state of the database --- ..._10_22_144927_migrate_incorrect_action_types.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/database/migrations/2025_10_22_144927_migrate_incorrect_action_types.php b/database/migrations/2025_10_22_144927_migrate_incorrect_action_types.php index 7eff84667a..b27ed56ef3 100644 --- a/database/migrations/2025_10_22_144927_migrate_incorrect_action_types.php +++ b/database/migrations/2025_10_22_144927_migrate_incorrect_action_types.php @@ -13,16 +13,9 @@ return new class extends Migration { /** - * So the concern here is that the following statement _could_ take a long time - the action_logs table is not indexed - * against the action_type column (and shouldn't be) so this could take a few beats. But, still, we're not talking about - * a particularly wide table or anything; we've certainly heard about a couple of times where people had a few million - * action_logs but, again, not too many more than that. - * - * But @snipe has mentioned multiple times that in some older migrations, trying to run an UPDATE in batch, there were - * memory issues. - * - * I've investigated and it looks like we've rarely or never done a 'batch update' the way we do below. I'm pretty sure - * it will be fine (famous last words...) + * We actually *do* have an index on action_type, so this query shouldn't take too terribly long. I don't know + * that we have a ton of people canceling requests (and only certain types of request-cancellation use this + * erroneous action_type), so I feel pretty comfortable with this fixup. Fingers crossed! * */ DB::table('action_logs')->where('action_type', 'request_canceled')->update(['action_type' => 'request canceled']);