Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importer again #4702

Merged
merged 8 commits into from
Dec 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Requests/ItemImportRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function authorize()
public function rules()
{
return [
//
'import-type' => 'required',
];
}

Expand Down
19 changes: 16 additions & 3 deletions app/Importer/AssetImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,28 @@ public function createAssetIfNotExists(array $row)
}

$this->item['asset_tag'] = $asset_tag;

// We need to save the user if it exists so that we can checkout to user later.
// Sanitizing the item will remove it.
if(array_key_exists('user', $this->item)) {
$user = $this->item['user'];
}
$item = $this->sanitizeItemForStoring($asset, $editingAsset);
// By default we're set this to location_id in the item.
// The location id fetched by the csv reader is actually the rtd_location_id.
// This will also set location_id, but then that will be overridden by the
// checkout method if necessary below.
if (isset($this->item["location_id"])) {
$item['rtd_location_id'] = $this->item['location_id'];
unset($item['location_id']);
}


if ($editingAsset) {
$asset->update($item);
} else {
$asset->fill($item);
}
// If we're updating, we don't want to overwrite old fields.

// If we're updating, we don't want to overwrite old fields.
if (array_key_exists('custom_fields', $this->item)) {
foreach ($this->item['custom_fields'] as $custom_field => $val) {
$asset->{$custom_field} = $val;
Expand All @@ -101,6 +109,11 @@ public function createAssetIfNotExists(array $row)
if ($asset->save()) {
$asset->logCreate('Imported using csv importer');
$this->log('Asset ' . $this->item["name"] . ' with serial number ' . $this->item['serial'] . ' was created');

// If we have a user to checkout to, lets do so.
if(isset($user)) {
$asset->fresh()->checkOut($user);
}
return;
}
$this->logError($asset, 'Asset "' . $this->item['name'].'"');
Expand Down
6 changes: 4 additions & 2 deletions app/Importer/ComponentImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ public function createComponentIfNotExists()
$component = null;
$editingComponent = false;
$this->log("Creating Component");
$component = Component::where('name', $this->item['name']);
$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"] . ' already exists. ');
$this->log('A matching Component ' . $this->item["name"] . ' with serial ' .$this->item['serial'].' already exists. ');
if (!$this->updating) {
$this->log("Skipping Component");
return;
Expand Down
9 changes: 6 additions & 3 deletions app/Importer/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,15 @@ protected function createOrFetchUser($row)
// A number was given instead of a name
if (is_numeric($user_name)) {
$this->log('User '.$user_name.' is not a name - assume this user already exists');
$user_username = '';
// No name was given
$user = User::find($user_name);
if($user) {
return $user;
}
$this->log('User with id'.$user_name.' does not exist. Continuing through our processes');
} elseif (empty($user_name)) {

$this->log('No user data provided - skipping user creation, just adding asset');
//$user_username = '';
return false;
} else {
$user_email_array = User::generateFormattedNameFromFullName(Setting::getSettings()->email_format, $user_name);
$first_name = $user_email_array['first_name'];
Expand Down
5 changes: 1 addition & 4 deletions app/Importer/ItemImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ protected function handle($row)
// NO need to call this method if we're running the user import.
// TODO: Merge these methods.
if(get_class($this) !== UserImporter::class) {
if ($this->item["user"] = $this->createOrFetchUser($row)) {
$this->item['assigned_to'] = $this->item['user']->id;
$this->item['assigned_type'] = User::class;
}
$this->item["user"] = $this->createOrFetchUser($row);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/Importer/UserImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function createUserIfNotExists(array $row)
$this->item['username'] = $this->findCsvMatch($row, 'username');
$this->item['first_name'] = $this->findCsvMatch($row, 'first_name');
$this->item['last_name'] = $this->findCsvMatch($row, 'last_name');
$this->item['email'] = $this->findCsvMatch($row, 'user_email');
$this->item['email'] = $this->findCsvMatch($row, 'email');
$this->item['phone'] = $this->findCsvMatch($row, 'phone_number');
$this->item['jobtitle'] = $this->findCsvMatch($row, 'jobtitle');
$this->item['employee_num'] = $this->findCsvMatch($row, 'employee_num');
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public function checkOut($target, $admin = null, $checkout_at = null, $expected_

if ($location != null) {
$this->location_id = $location;
} else {
if($target->location) {
$this->location_id = $target->location->id;
}
}

if ($this->requireAcceptance()) {
Expand Down
1 change: 1 addition & 0 deletions app/Models/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Component extends SnipeModel
'purchase_date',
'min_amt',
'qty',
'serial'
];

public function location()
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
"babel-preset-latest": "^6.24.1",
"cross-env": "^5.0.5",
"jquery": "^3.1.1",
"laravel-mix": "1.4.3",
"laravel-mix": "1.7",
"lodash": "^4.17.4",
"vue": "2.4.4",
"vue-loader": "^13.6.1",
"vue-template-compiler": "2.4.4"
},
"dependencies": {
Expand Down
2 changes: 0 additions & 2 deletions public/build/vue.js

This file was deleted.

1 change: 0 additions & 1 deletion public/build/vue.js.map

This file was deleted.

3,441 changes: 3,439 additions & 2 deletions public/css/AdminLTE.css

Large diffs are not rendered by default.

6,892 changes: 6,889 additions & 3 deletions public/css/app.css

Large diffs are not rendered by default.

4,387 changes: 4,382 additions & 5 deletions public/css/build/all.css

Large diffs are not rendered by default.

4,387 changes: 4,382 additions & 5 deletions public/css/dist/all.css

Large diffs are not rendered by default.

Loading