mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
bee1dfc4a6
* The default locale of en does not include dollar sign in default currency. Assume if there is no currency symbol set that the dollar sign is a good thing to look for in parsefloat. * Fix for 4485. Serial not serial_number Also fix bug where updating with a csv that does not include custom field columns should not overwrite current values. * Rename serial_number to serial in default imports to avoid needing to map weirdly. * Add Test for 4359. Not reproducable at current though
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Importer;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\Consumable;
|
|
|
|
class ConsumableImporter extends ItemImporter
|
|
{
|
|
public function __construct($filename)
|
|
{
|
|
parent::__construct($filename);
|
|
}
|
|
|
|
protected function handle($row)
|
|
{
|
|
parent::handle($row); // TODO: Change the autogenerated stub
|
|
$this->createConsumableIfNotExists();
|
|
}
|
|
|
|
/**
|
|
* Create a consumable if a duplicate does not exist
|
|
*
|
|
* @author Daniel Melzter
|
|
* @since 3.0
|
|
*/
|
|
public function createConsumableIfNotExists()
|
|
{
|
|
$consumable = Consumable::where('name', $this->item['name'])->first();
|
|
if ($consumable) {
|
|
if (!$this->updating) {
|
|
$this->log('A matching Consumable ' . $this->item["name"] . ' already exists. ');
|
|
return;
|
|
}
|
|
$this->log('Updating Consumable');
|
|
$consumable->update($this->sanitizeItemForUpdating($consumable));
|
|
$consumable->save();
|
|
return;
|
|
}
|
|
$this->log("No matching consumable, creating one");
|
|
$consumable = new Consumable();
|
|
$consumable->fill($this->sanitizeItemForStoring($consumable));
|
|
|
|
if ($consumable->save()) {
|
|
$consumable->logCreate('Imported using CSV Importer');
|
|
$this->log("Consumable " . $this->item["name"] . ' was created');
|
|
return;
|
|
}
|
|
$this->logError($consumable, 'Consumable');
|
|
return;
|
|
}
|
|
}
|