Updated importer

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-09-19 16:20:42 +01:00
parent 9adb2c24f3
commit 4363e8b34c
5 changed files with 9 additions and 9 deletions

View file

@ -177,7 +177,7 @@ class AssetImporter extends ItemImporter
$this->log('Asset '.$this->item['name'].' with serial number '.$this->item['serial'].' was created'); $this->log('Asset '.$this->item['name'].' with serial number '.$this->item['serial'].' was created');
// If we have a target to checkout to, lets do so. // If we have a target to checkout to, lets do so.
//-- user_id is a property of the abstract class Importer, which this class inherits from and it's set by //-- created_by is a property of the abstract class Importer, which this class inherits from and it's set by
//-- the class that needs to use it (command importer or GUI importer inside the project). //-- the class that needs to use it (command importer or GUI importer inside the project).
if (isset($target) && ($target !== false)) { if (isset($target) && ($target !== false)) {
if (!is_null($asset->assigned_to)){ if (!is_null($asset->assigned_to)){

View file

@ -58,7 +58,7 @@ class ComponentImporter extends ItemImporter
if (isset($this->item['asset_tag']) && ($asset = Asset::where('asset_tag', $this->item['asset_tag'])->first())) { if (isset($this->item['asset_tag']) && ($asset = Asset::where('asset_tag', $this->item['asset_tag'])->first())) {
$component->assets()->attach($component->id, [ $component->assets()->attach($component->id, [
'component_id' => $component->id, 'component_id' => $component->id,
'user_id' => $this->created_by, 'created_by' => $this->created_by,
'created_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s'),
'assigned_qty' => 1, // Only assign the first one to the asset 'assigned_qty' => 1, // Only assign the first one to the asset
'asset_id' => $asset->id, 'asset_id' => $asset->id,

View file

@ -22,7 +22,7 @@ abstract class Importer
* @var * @var
*/ */
protected $user_id; protected $created_by;
/** /**
* Are we updating items in the import * Are we updating items in the import
* @var bool * @var bool
@ -395,7 +395,7 @@ abstract class Importer
} }
/** /**
* Matches a user by user_id if user_name provided is a number * Matches a user by created_by if user_name provided is a number
* @param string $user_name users full name from csv * @param string $user_name users full name from csv
* @return User User Matching ID * @return User User Matching ID
*/ */
@ -412,13 +412,13 @@ abstract class Importer
/** /**
* Sets the Id of User performing import. * Sets the Id of User performing import.
* *
* @param mixed $user_id the user id * @param mixed $created_by the user id
* *
* @return self * @return self
*/ */
public function setUserId($user_id) public function setUserId($created_by)
{ {
$this->created_by = $user_id; $this->created_by = $created_by;
return $this; return $this;
} }

View file

@ -94,7 +94,7 @@ class ItemImporter extends Importer
$this->item['qty'] = $this->findCsvMatch($row, 'quantity'); $this->item['qty'] = $this->findCsvMatch($row, 'quantity');
$this->item['requestable'] = $this->findCsvMatch($row, 'requestable'); $this->item['requestable'] = $this->findCsvMatch($row, 'requestable');
$this->item['user_id'] = $this->created_by; $this->item['created_by'] = $this->created_by;
$this->item['serial'] = $this->findCsvMatch($row, 'serial'); $this->item['serial'] = $this->findCsvMatch($row, 'serial');
// NO need to call this method if we're running the user import. // NO need to call this method if we're running the user import.
// TODO: Merge these methods. // TODO: Merge these methods.

View file

@ -65,7 +65,7 @@ class LocationImporter extends ItemImporter
$this->item['ldap_ou'] = trim($this->findCsvMatch($row, 'ldap_ou')); $this->item['ldap_ou'] = trim($this->findCsvMatch($row, 'ldap_ou'));
$this->item['manager'] = trim($this->findCsvMatch($row, 'manager')); $this->item['manager'] = trim($this->findCsvMatch($row, 'manager'));
$this->item['manager_username'] = trim($this->findCsvMatch($row, 'manager_username')); $this->item['manager_username'] = trim($this->findCsvMatch($row, 'manager_username'));
$this->item['user_id'] = auth()->id(); $this->item['created_by'] = auth()->id();
if ($this->findCsvMatch($row, 'parent_location')) { if ($this->findCsvMatch($row, 'parent_location')) {
$this->item['parent_id'] = $this->createOrFetchLocation(trim($this->findCsvMatch($row, 'parent_location'))); $this->item['parent_id'] = $this->createOrFetchLocation(trim($this->findCsvMatch($row, 'parent_location')));