From 2deba17d9105fa584da743020d36f126cf1394f2 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Thu, 25 Jan 2024 20:04:02 -0600 Subject: [PATCH] that's all of 'em --- app/Importer/ConsumableImporter.php | 6 +++--- app/Importer/LicenseImporter.php | 6 +++--- app/Observers/ConsumableObserver.php | 3 +++ app/Observers/LicenseObserver.php | 3 +++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Importer/ConsumableImporter.php b/app/Importer/ConsumableImporter.php index 5a65514deb..9e7019b086 100644 --- a/app/Importer/ConsumableImporter.php +++ b/app/Importer/ConsumableImporter.php @@ -45,10 +45,10 @@ class ConsumableImporter extends ItemImporter $this->item['item_no'] = trim($this->findCsvMatch($row, 'item_number')); $this->item['min_amt'] = trim($this->findCsvMatch($row, "min_amt")); $consumable->fill($this->sanitizeItemForStoring($consumable)); - //FIXME: this disables model validation. Need to find a way to avoid double-logs without breaking everything. - $consumable->unsetEventDispatcher(); + + // This sets an attribute on the Loggable trait for the action log + $consumable->setImported(true); if ($consumable->save()) { - $consumable->logCreate('Imported using CSV Importer'); $this->log('Consumable '.$this->item['name'].' was created'); return; diff --git a/app/Importer/LicenseImporter.php b/app/Importer/LicenseImporter.php index 393d00367d..b7c55cdba6 100644 --- a/app/Importer/LicenseImporter.php +++ b/app/Importer/LicenseImporter.php @@ -85,10 +85,10 @@ class LicenseImporter extends ItemImporter } else { $license->fill($this->sanitizeItemForStoring($license)); } - //FIXME: this disables model validation. Need to find a way to avoid double-logs without breaking everything. - // $license->unsetEventDispatcher(); + + // This sets an attribute on the Loggable trait for the action log + $license->setImported(true); if ($license->save()) { - $license->logCreate('Imported using csv importer'); $this->log('License '.$this->item['name'].' with serial number '.$this->item['serial'].' was created'); // Lets try to checkout seats if the fields exist and we have seats. diff --git a/app/Observers/ConsumableObserver.php b/app/Observers/ConsumableObserver.php index b945196e20..265e64d73e 100644 --- a/app/Observers/ConsumableObserver.php +++ b/app/Observers/ConsumableObserver.php @@ -38,6 +38,9 @@ class ConsumableObserver $logAction->item_id = $consumable->id; $logAction->created_at = date('Y-m-d H:i:s'); $logAction->user_id = Auth::id(); + if($consumable->imported) { + $logAction->note = trans('general.importer.import_note'); + } $logAction->logaction('create'); } diff --git a/app/Observers/LicenseObserver.php b/app/Observers/LicenseObserver.php index 1478aba113..2d0f60a625 100644 --- a/app/Observers/LicenseObserver.php +++ b/app/Observers/LicenseObserver.php @@ -38,6 +38,9 @@ class LicenseObserver $logAction->item_id = $license->id; $logAction->created_at = date('Y-m-d H:i:s'); $logAction->user_id = Auth::id(); + if($license->imported) { + $logAction->note = trans('general.importer.import_note'); + } $logAction->logaction('create'); }