mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Merge pull request #11405 from snipe/fixes/use_db_column_instead_of_converted_value
Only care about the custom field's converted name when updating the custom field itself
This commit is contained in:
commit
14d8fb66aa
|
@ -544,11 +544,11 @@ class AssetsController extends Controller
|
||||||
foreach ($model->fieldset->fields as $field) {
|
foreach ($model->fieldset->fields as $field) {
|
||||||
|
|
||||||
// Set the field value based on what was sent in the request
|
// Set the field value based on what was sent in the request
|
||||||
$field_val = $request->input($field->convertUnicodeDbSlug(), null);
|
$field_val = $request->input($field->db_column, null);
|
||||||
|
|
||||||
// If input value is null, use custom field's default value
|
// If input value is null, use custom field's default value
|
||||||
if ($field_val == null) {
|
if ($field_val == null) {
|
||||||
\Log::debug('Field value for '.$field->convertUnicodeDbSlug().' is null');
|
\Log::debug('Field value for '.$field->db_column.' is null');
|
||||||
$field_val = $field->defaultValue($request->get('model_id'));
|
$field_val = $field->defaultValue($request->get('model_id'));
|
||||||
\Log::debug('Use the default fieldset value of '.$field->defaultValue($request->get('model_id')));
|
\Log::debug('Use the default fieldset value of '.$field->defaultValue($request->get('model_id')));
|
||||||
}
|
}
|
||||||
|
@ -563,13 +563,13 @@ class AssetsController extends Controller
|
||||||
if (($field_val == null) && ($request->has('model_id') != '')) {
|
if (($field_val == null) && ($request->has('model_id') != '')) {
|
||||||
$field_val = \Crypt::encrypt($field->defaultValue($request->get('model_id')));
|
$field_val = \Crypt::encrypt($field->defaultValue($request->get('model_id')));
|
||||||
} else {
|
} else {
|
||||||
$field_val = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
|
$field_val = \Crypt::encrypt($request->input($field->db_column));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = $field_val;
|
$asset->{$field->db_column} = $field_val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,13 +634,13 @@ class AssetsController extends Controller
|
||||||
// Update custom fields
|
// Update custom fields
|
||||||
if (($model = AssetModel::find($asset->model_id)) && (isset($model->fieldset))) {
|
if (($model = AssetModel::find($asset->model_id)) && (isset($model->fieldset))) {
|
||||||
foreach ($model->fieldset->fields as $field) {
|
foreach ($model->fieldset->fields as $field) {
|
||||||
if ($request->has($field->convertUnicodeDbSlug())) {
|
if ($request->has($field->db_column)) {
|
||||||
if ($field->field_encrypted == '1') {
|
if ($field->field_encrypted == '1') {
|
||||||
if (Gate::allows('admin')) {
|
if (Gate::allows('admin')) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
|
$asset->{$field->db_column} = \Crypt::encrypt($request->input($field->db_column));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
|
$asset->{$field->db_column} = $request->input($field->db_column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,17 +168,17 @@ class AssetsController extends Controller
|
||||||
foreach ($model->fieldset->fields as $field) {
|
foreach ($model->fieldset->fields as $field) {
|
||||||
if ($field->field_encrypted == '1') {
|
if ($field->field_encrypted == '1') {
|
||||||
if (Gate::allows('admin')) {
|
if (Gate::allows('admin')) {
|
||||||
if (is_array($request->input($field->convertUnicodeDbSlug()))) {
|
if (is_array($request->input($field->db_column))) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(implode(', ', $request->input($field->convertUnicodeDbSlug())));
|
$asset->{$field->db_column} = \Crypt::encrypt(implode(', ', $request->input($field->db_column)));
|
||||||
} else {
|
} else {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
|
$asset->{$field->db_column} = \Crypt::encrypt($request->input($field->db_column));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (is_array($request->input($field->convertUnicodeDbSlug()))) {
|
if (is_array($request->input($field->db_column))) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = implode(', ', $request->input($field->convertUnicodeDbSlug()));
|
$asset->{$field->db_column} = implode(', ', $request->input($field->db_column));
|
||||||
} else {
|
} else {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
|
$asset->{$field->db_column} = $request->input($field->db_column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,17 +356,17 @@ class AssetsController extends Controller
|
||||||
foreach ($model->fieldset->fields as $field) {
|
foreach ($model->fieldset->fields as $field) {
|
||||||
if ($field->field_encrypted == '1') {
|
if ($field->field_encrypted == '1') {
|
||||||
if (Gate::allows('admin')) {
|
if (Gate::allows('admin')) {
|
||||||
if (is_array($request->input($field->convertUnicodeDbSlug()))) {
|
if (is_array($request->input($field->db_column))) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(implode(', ', $request->input($field->convertUnicodeDbSlug())));
|
$asset->{$field->db_column} = \Crypt::encrypt(implode(', ', $request->input($field->db_column)));
|
||||||
} else {
|
} else {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
|
$asset->{$field->db_column} = \Crypt::encrypt($request->input($field->db_column));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (is_array($request->input($field->convertUnicodeDbSlug()))) {
|
if (is_array($request->input($field->db_column))) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = implode(', ', $request->input($field->convertUnicodeDbSlug()));
|
$asset->{$field->db_column} = implode(', ', $request->input($field->db_column));
|
||||||
} else {
|
} else {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
|
$asset->{$field->db_column} = $request->input($field->db_column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,8 +94,8 @@ class AssetsTransformer
|
||||||
$fields_array = [];
|
$fields_array = [];
|
||||||
|
|
||||||
foreach ($asset->model->fieldset->fields as $field) {
|
foreach ($asset->model->fieldset->fields as $field) {
|
||||||
if ($field->isFieldDecryptable($asset->{$field->convertUnicodeDbSlug()})) {
|
if ($field->isFieldDecryptable($asset->{$field->db_column})) {
|
||||||
$decrypted = Helper::gracefulDecrypt($field, $asset->{$field->convertUnicodeDbSlug()});
|
$decrypted = Helper::gracefulDecrypt($field, $asset->{$field->db_column});
|
||||||
$value = (Gate::allows('superadmin')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
|
$value = (Gate::allows('superadmin')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
|
||||||
|
|
||||||
if ($field->format == 'DATE'){
|
if ($field->format == 'DATE'){
|
||||||
|
@ -107,21 +107,21 @@ class AssetsTransformer
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields_array[$field->name] = [
|
$fields_array[$field->name] = [
|
||||||
'field' => e($field->convertUnicodeDbSlug()),
|
'field' => e($field->db_column),
|
||||||
'value' => e($value),
|
'value' => e($value),
|
||||||
'field_format' => $field->format,
|
'field_format' => $field->format,
|
||||||
'element' => $field->element,
|
'element' => $field->element,
|
||||||
];
|
];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$value = $asset->{$field->convertUnicodeDbSlug()};
|
$value = $asset->{$field->db_column};
|
||||||
|
|
||||||
if (($field->format == 'DATE') && (!is_null($value)) && ($value!='')){
|
if (($field->format == 'DATE') && (!is_null($value)) && ($value!='')){
|
||||||
$value = Helper::getFormattedDateObject($value, 'date', false);
|
$value = Helper::getFormattedDateObject($value, 'date', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields_array[$field->name] = [
|
$fields_array[$field->name] = [
|
||||||
'field' => e($field->convertUnicodeDbSlug()),
|
'field' => e($field->db_column),
|
||||||
'value' => e($value),
|
'value' => e($value),
|
||||||
'field_format' => $field->format,
|
'field_format' => $field->format,
|
||||||
'element' => $field->element,
|
'element' => $field->element,
|
||||||
|
|
|
@ -39,7 +39,7 @@ class ComponentsAssetsTransformer
|
||||||
|
|
||||||
if ($asset->model->fieldset) {
|
if ($asset->model->fieldset) {
|
||||||
foreach ($asset->model->fieldset->fields as $field) {
|
foreach ($asset->model->fieldset->fields as $field) {
|
||||||
$fields_array = [$field->name => $asset->{$field->convertUnicodeDbSlug()}];
|
$fields_array = [$field->name => $asset->{$field->db_column}];
|
||||||
$array += $fields_array;
|
$array += $fields_array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ class CustomField extends Model
|
||||||
|
|
||||||
// Column already exists on the assets table - nothing to do here.
|
// Column already exists on the assets table - nothing to do here.
|
||||||
// This *shouldn't* happen in the wild.
|
// This *shouldn't* happen in the wild.
|
||||||
if (Schema::hasColumn(self::$table_name, $custom_field->convertUnicodeDbSlug())) {
|
if (Schema::hasColumn(self::$table_name, $custom_field->db_column)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ class CustomField extends Model
|
||||||
// Drop the assets column if we've deleted it from custom fields
|
// Drop the assets column if we've deleted it from custom fields
|
||||||
self::deleting(function ($custom_field) {
|
self::deleting(function ($custom_field) {
|
||||||
return Schema::table(self::$table_name, function ($table) use ($custom_field) {
|
return Schema::table(self::$table_name, function ($table) use ($custom_field) {
|
||||||
$table->dropColumn($custom_field->convertUnicodeDbSlug());
|
$table->dropColumn($custom_field->db_column);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ class AssetAuditPresenter extends Presenter
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$layout[] = [
|
$layout[] = [
|
||||||
'field' => 'custom_fields.'.$field->convertUnicodeDbSlug(),
|
'field' => 'custom_fields.'.$field->db_column,
|
||||||
'searchable' => true,
|
'searchable' => true,
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'visible' => false,
|
'visible' => false,
|
||||||
|
|
|
@ -263,7 +263,7 @@ class AssetPresenter extends Presenter
|
||||||
// name can break the listings page. - snipe
|
// name can break the listings page. - snipe
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$layout[] = [
|
$layout[] = [
|
||||||
'field' => 'custom_fields.'.$field->convertUnicodeDbSlug(),
|
'field' => 'custom_fields.'.$field->db_column,
|
||||||
'searchable' => true,
|
'searchable' => true,
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'switchable' => true,
|
'switchable' => true,
|
||||||
|
|
Loading…
Reference in a new issue