Fixes/cli importer issue (#9199)

* Added logic to handle the CLI importer.

* Fix bug introduced with the commit previous to the regression.

* Adds a validation for  variable when is null, add comments to clarify where the  class variable came from.

* Add support for when  variable is an instance of User class.
This commit is contained in:
Ivan Nieto Vivanco 2021-04-05 21:28:31 -05:00 committed by GitHub
parent 5ea759f615
commit 90a24539b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -120,8 +120,10 @@ 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 setted by
//-- the class that needs to use it (command importer or GUI importer inside the project).
if(isset($target)) { if(isset($target)) {
$asset->fresh()->checkOut($target); $asset->fresh()->checkOut($target, $this->user_id);
} }
return; return;
} }

View file

@ -313,8 +313,14 @@ class Asset extends Depreciable
} }
if ($this->save()) { if ($this->save()) {
if (is_integer($admin)){
event(new CheckoutableCheckedOut($this, $target, Auth::user(), $note)); $checkedOutBy = User::findOrFail($admin);
} elseif (get_class($admin) === 'App\Models\User') {
$checkedOutBy = $admin;
} else {
$checkedOutBy = Auth::user();
}
event(new CheckoutableCheckedOut($this, $target, $checkedOutBy, $note));
$this->increment('checkout_counter', 1); $this->increment('checkout_counter', 1);
return true; return true;