Fix double create log on import. (#4706)

* Fix double create log on import.

* Fix code error causing component importer to implode.

* More component importer oldities
This commit is contained in:
Daniel Meltzer 2018-01-03 20:22:02 -05:00 committed by snipe
parent b721bfcc84
commit b2469bb34f
6 changed files with 9 additions and 7 deletions

View file

@ -41,6 +41,7 @@ class AccessoryImporter extends ItemImporter
$this->log("No Matching Accessory, Creating a new one");
$accessory = new Accessory();
$accessory->fill($this->sanitizeItemForStoring($accessory));
$accessory->unsetEventDispatcher();
if ($accessory->save()) {
$accessory->logCreate('Imported using CSV Importer');
$this->log('Accessory ' . $this->item["name"] . ' was created');

View file

@ -106,6 +106,7 @@ class AssetImporter extends ItemImporter
$asset->{$custom_field} = $val;
}
}
$asset->unsetEventDispatcher();
if ($asset->save()) {
$asset->logCreate('Imported using csv importer');
$this->log('Asset ' . $this->item["name"] . ' with serial number ' . $this->item['serial'] . ' was created');

View file

@ -27,29 +27,26 @@ class ComponentImporter extends ItemImporter
public function createComponentIfNotExists()
{
$component = null;
$editingComponent = false;
$this->log("Creating Component");
$component = Component::where('name', $this->item['name'])
->where('serial', $this->item['serial'])
->first();
if ($component) {
$editingComponent = true;
$this->log('A matching Component ' . $this->item["name"] . ' with serial ' .$this->item['serial'].' already exists. ');
if (!$this->updating) {
$this->log("Skipping Component");
return;
}
$this->log("Updating Component");
$component = $this->components[$componentId];
$component->update($this->sanitizeItemFor($component));
$component->update($this->sanitizeItemForUpdating($component));
$component->save();
return;
}
$this->log("No matching component, creating one");
$component = new Component;
$component->fill($$this->sanitizeItemForStoring($component));
$component->fill($this->sanitizeItemForStoring($component));
$component->unsetEventDispatcher();
if ($component->save()) {
$component->logCreate('Imported using CSV Importer');
$this->log("Component " . $this->item["name"] . ' was created');

View file

@ -41,6 +41,7 @@ class ConsumableImporter extends ItemImporter
$consumable = new Consumable();
$consumable->fill($this->sanitizeItemForStoring($consumable));
$consumable->unsetEventDispatcher();
if ($consumable->save()) {
$consumable->logCreate('Imported using CSV Importer');
$this->log("Consumable " . $this->item["name"] . ' was created');

View file

@ -63,6 +63,8 @@ class LicenseImporter extends ItemImporter
} else {
$license->fill($this->sanitizeItemForStoring($license));
}
$license->unsetEventDispatcher();
if ($license->save()) {
$license->logCreate('Imported using csv importer');
$this->log('License ' . $this->item["name"] . ' with serial number ' . $this->item['serial'] . ' was created');

View file

@ -182,7 +182,7 @@ trait Loggable
$log->location_id = null;
$log->note = $note;
$log->user_id = $user_id;
$log->logaction('created');
$log->logaction('create');
$log->save();
return $log;
}