A free open source IT asset/license management system
a few more imports, component sample
spencerrlongg3574ef5bb9a4
diff --git a/app/Importer/AccessoryImporter.php b/app/Importer/AccessoryImporter.phpindex 9901fb70d7..eb17c5acad 100644--- a/app/Importer/AccessoryImporter.php+++ b/app/Importer/AccessoryImporter.php@@ -46,10 +46,9 @@ class AccessoryImporter extends ItemImporter$this->item['min_amt'] = $this->findCsvMatch($row, "min_amt");$accessory->fill($this->sanitizeItemForStoring($accessory));- //FIXME: this disables model validation. Need to find a way to avoid double-logs without breaking everything.- // $accessory->unsetEventDispatcher();+ // This sets an attribute on the Loggable trait for the action log+ $accessory->setImported(true);if ($accessory->save()) {- $accessory->logCreate('Imported using CSV Importer');$this->log('Accessory '.$this->item['name'].' was created');return;diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.phpindex 312c9b44b2..e001a383ad 100644--- a/app/Importer/AssetImporter.php+++ b/app/Importer/AssetImporter.php@@ -135,7 +135,7 @@ class AssetImporter extends ItemImporter$asset->{$custom_field} = $val;}}- //this sets an attribute on the Loggable trait for the action log+ // This sets an attribute on the Loggable trait for the action log$asset->setImported(true);if ($asset->save()) {diff --git a/app/Importer/ComponentImporter.php b/app/Importer/ComponentImporter.phpindex 71ded1b0e5..f72d4cbfd7 100644--- a/app/Importer/ComponentImporter.php+++ b/app/Importer/ComponentImporter.php@@ -48,10 +48,10 @@ class ComponentImporter extends ItemImporter$this->log('No matching component, creating one');$component = new Component;$component->fill($this->sanitizeItemForStoring($component));- //FIXME: this disables model validation. Need to find a way to avoid double-logs without breaking everything.- $component->unsetEventDispatcher();++ // This sets an attribute on the Loggable trait for the action log+ $component->setImported(true);if ($component->save()) {- $component->logCreate('Imported using CSV Importer');$this->log('Component '.$this->item['name'].' was created');// If we have an asset tag, checkout to that asset.diff --git a/app/Observers/AccessoryObserver.php b/app/Observers/AccessoryObserver.phpindex f97d166b17..99a594c5bc 100644--- a/app/Observers/AccessoryObserver.php+++ b/app/Observers/AccessoryObserver.php@@ -38,6 +38,9 @@ class AccessoryObserver$logAction->item_id = $accessory->id;$logAction->created_at = date('Y-m-d H:i:s');$logAction->user_id = Auth::id();+ if($accessory->imported) {+ $logAction->note = trans('general.importer.import_note');+ }$logAction->logaction('create');}diff --git a/app/Observers/ComponentObserver.php b/app/Observers/ComponentObserver.phpindex 57792022bb..e89006ad85 100644--- a/app/Observers/ComponentObserver.php+++ b/app/Observers/ComponentObserver.php@@ -38,6 +38,9 @@ class ComponentObserver$logAction->item_id = $component->id;$logAction->created_at = date('Y-m-d H:i:s');$logAction->user_id = Auth::id();+ if($component->imported) {+ $logAction->note = trans('general.importer.import_note');+ }$logAction->logaction('create');}diff --git a/sample_csvs/components-sample.csv b/sample_csvs/components-sample.csvnew file mode 100644index 0000000000..0861abc8dd--- /dev/null+++ b/sample_csvs/components-sample.csv@@ -0,0 +1,2 @@+Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Serial number,Category,Quantity+RTX 4080,2024-01-01,5000.00,Austin,Grokability,2790,123456789,GPU,10\ No newline at end of file