Merge branch 'develop' into features/import_models

This commit is contained in:
snipe 2024-11-13 15:51:36 +00:00 committed by GitHub
commit 220902a8b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 39 deletions

View file

@ -180,8 +180,8 @@ class CheckoutableListener
$notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint); $notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint);
$notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams $notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams
} else { } else {
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint) Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
->notify($this->getCheckinNotification($event)); ->notify($this->getCheckinNotification($event));
} }
} }
} catch (ClientException $e) { } catch (ClientException $e) {

View file

@ -117,44 +117,45 @@ class Importer extends Component
public function updatingTypeOfImport($type) public function updatingTypeOfImport($type)
{ {
// go through each header, find a matching field to try and map it to.
// go through each header, find a matching field to try and map it to.
foreach ($this->headerRow as $i => $header) { foreach ($this->headerRow as $i => $header) {
// do we have something mapped already? // do we have something mapped already?
if (array_key_exists($i, $this->field_map)) { if (array_key_exists($i, $this->field_map)) {
// yes, we do. Is it valid for this type of import? // yes, we do. Is it valid for this type of import?
// (e.g. the import type might have been changed...?) // (e.g. the import type might have been changed...?)
if (array_key_exists($this->field_map[$i], $this->columnOptions[$type])) { if (array_key_exists($this->field_map[$i], $this->columnOptions[$type])) {
//yes, this key *is* valid. Continue on to the next field. //yes, this key *is* valid. Continue on to the next field.
continue; continue;
} else { } else {
//no, this key is *INVALID* for this import type. Better set it to null //no, this key is *INVALID* for this import type. Better set it to null
// and we'll hope that the $aliases_fields or something else picks it up. // and we'll hope that the $aliases_fields or something else picks it up.
$this->field_map[$i] = null; // fingers crossed! But it's not likely, tbh. $this->field_map[$i] = null; // fingers crossed! But it's not likely, tbh.
} // TODO - strictly speaking, this isn't necessary here I don't think. } // TODO - strictly speaking, this isn't necessary here I don't think.
} }
// first, check for exact matches // first, check for exact matches
foreach ($this->columnOptions[$type] as $v => $text) { foreach ($this->columnOptions[$type] as $v => $text) {
if (strcasecmp($text, $header) === 0) { // case-INSENSITIVe on purpose! if (strcasecmp($text, $header) === 0) { // case-INSENSITIVe on purpose!
$this->field_map[$i] = $v; $this->field_map[$i] = $v;
continue 2; //don't bother with the alias check, go to the next header continue 2; //don't bother with the alias check, go to the next header
}
} }
// if you got here, we didn't find a match. Try the $aliases_fields }
foreach ($this->aliases_fields as $key => $alias_values) { // if you got here, we didn't find a match. Try the $aliases_fields
foreach ($alias_values as $alias_value) { foreach ($this->aliases_fields as $key => $alias_values) {
if (strcasecmp($alias_value, $header) === 0) { // aLsO CaSe-INSENSitiVE! foreach ($alias_values as $alias_value) {
// Make *absolutely* sure that this key actually _exists_ in this import type - if (strcasecmp($alias_value, $header) === 0) { // aLsO CaSe-INSENSitiVE!
// you can trigger this by importing accessories with a 'Warranty' column (which don't exist // Make *absolutely* sure that this key actually _exists_ in this import type -
// in "Accessories"!) // you can trigger this by importing accessories with a 'Warranty' column (which don't exist
// in "Accessories"!)
if (array_key_exists($key, $this->columnOptions[$type])) { if (array_key_exists($key, $this->columnOptions[$type])) {
$this->field_map[$i] = $key; $this->field_map[$i] = $key;
continue 3; // bust out of both of these loops; as well as the surrounding one - e.g. move on to the next header continue 3; // bust out of both of these loops; as well as the surrounding one - e.g. move on to the next header
}
} }
} }
} }
// and if you got here, we got nothing. Let's recommend 'null' }
$this->field_map[$i] = null; // Booooo :( // and if you got here, we got nothing. Let's recommend 'null'
$this->field_map[$i] = null; // Booooo :(
} }
} }
@ -552,7 +553,6 @@ class Importer extends Component
$this->field_map = null; $this->field_map = null;
foreach ($this->headerRow as $element) { foreach ($this->headerRow as $element) {
if (isset($this->activeFile->field_map[$element])) { if (isset($this->activeFile->field_map[$element])) {
$this->field_map[] = $this->activeFile->field_map[$element]; $this->field_map[] = $this->activeFile->field_map[$element];
} else { } else {
@ -585,18 +585,16 @@ class Importer extends Component
if (Storage::delete('private_uploads/imports/' . $import->file_path)) { if (Storage::delete('private_uploads/imports/' . $import->file_path)) {
$import->delete(); $import->delete();
$this->message = trans('admin/hardware/message.import.file_delete_success'); $this->message = trans('admin/hardware/message.import.file_delete_success');
$this->message_type = 'success'; $this->message_type = 'success';
unset($this->files); unset($this->files);
return; return;
} }
$this->message = trans('admin/hardware/message.import.file_delete_error'); $this->message = trans('admin/hardware/message.import.file_delete_error');
$this->message_type = 'danger'; $this->message_type = 'danger';
} }
public function clearMessage() public function clearMessage()
@ -620,7 +618,7 @@ class Importer extends Component
public function render() public function render()
{ {
return view('livewire.importer') return view('livewire.importer')
->extends('layouts.default') ->extends('layouts.default')
->section('content'); ->section('content');
} }
} }

View file

@ -117,6 +117,9 @@ class SlackSettingsForm extends Component
public function updatedwebhookEndpoint() { public function updatedwebhookEndpoint() {
$this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows'); $this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows');
} }
public function updatedwebhookEndpoint() {
$this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows');
}
private function isButtonDisabled() { private function isButtonDisabled() {
if (empty($this->webhook_endpoint)) { if (empty($this->webhook_endpoint)) {

View file

@ -145,6 +145,7 @@ class ImportFactory extends Factory
} }
/** /**
* Create an asset model import type. * Create an asset model import type.
* *