From ea8f9a6dd9470714e1b3391d62b3a7898dc1078c Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Feb 2022 13:45:44 -0800 Subject: [PATCH 1/6] Make is_unique fillable Signed-off-by: snipe --- app/Models/CustomField.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index 0f58055254..b9b87f11bb 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -63,6 +63,7 @@ class CustomField extends Model 'field_encrypted', 'help_text', 'show_in_email', + 'is_unique', ]; /** From 41778980bc5ce79fc2abaaeffac6c55ecfa7d08d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Feb 2022 13:45:59 -0800 Subject: [PATCH 2/6] Add migration for is_unique Signed-off-by: snipe --- ..._add_unique_constraint_to_custom_field.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2022_02_16_152431_add_unique_constraint_to_custom_field.php diff --git a/database/migrations/2022_02_16_152431_add_unique_constraint_to_custom_field.php b/database/migrations/2022_02_16_152431_add_unique_constraint_to_custom_field.php new file mode 100644 index 0000000000..346f51d632 --- /dev/null +++ b/database/migrations/2022_02_16_152431_add_unique_constraint_to_custom_field.php @@ -0,0 +1,32 @@ +boolean('is_unique')->nullable()->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('custom_fields', function (Blueprint $table) { + $table->dropColumn('is_unique'); + }); + } +} From 6a91d4d19ea223d969302984463ffbac561880aa Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Feb 2022 13:46:22 -0800 Subject: [PATCH 3/6] Check for uniqueness constraint Signed-off-by: snipe --- app/Models/CustomFieldset.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index bcbe0b81d9..1cf1807d85 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -83,7 +83,11 @@ class CustomFieldset extends Model if (($field->field_encrypted != '1') || (($field->field_encrypted == '1') && (Gate::allows('admin')))) { - $rule[] = ($field->pivot->required == '1') ? 'required' : 'nullable'; + $rule[] = ($field->pivot->required == '1') ? 'required' : 'nullable'; + } + + if ($field->is_unique == '1') { + $rule[] = 'unique'; } array_push($rule, $field->attributes['format']); From a4a0aa5124ed08b121dd6c74bd3b887584626ef2 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Feb 2022 13:47:22 -0800 Subject: [PATCH 4/6] Removed debugging line Signed-off-by: snipe --- app/Http/Requests/ImageUploadRequest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Requests/ImageUploadRequest.php b/app/Http/Requests/ImageUploadRequest.php index 45d7bca5e6..dd7ba37882 100644 --- a/app/Http/Requests/ImageUploadRequest.php +++ b/app/Http/Requests/ImageUploadRequest.php @@ -161,7 +161,6 @@ class ImageUploadRequest extends Request // If the user isn't uploading anything new but wants to delete their old image, do so } else { - \Log::debug('No file passed for '.$form_fieldname); if ($this->input('image_delete') == '1') { \Log::debug('Deleting image'); try { From 824eedf7c23749de16d9c6301d94103e6f7d421a Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Feb 2022 13:47:48 -0800 Subject: [PATCH 5/6] Added UI elements for is_unique Signed-off-by: snipe --- app/Http/Controllers/CustomFieldsController.php | 2 ++ resources/views/custom_fields/fields/edit.blade.php | 11 +++++++++++ resources/views/custom_fields/index.blade.php | 2 ++ 3 files changed, 15 insertions(+) diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index aae7212436..8e29cba748 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -92,6 +92,7 @@ class CustomFieldsController extends Controller "field_values" => $request->get("field_values"), "field_encrypted" => $request->get("field_encrypted", 0), "show_in_email" => $request->get("show_in_email", 0), + "is_unique" => $request->get("is_unique", 0), "user_id" => Auth::id() ]); @@ -211,6 +212,7 @@ class CustomFieldsController extends Controller $field->user_id = Auth::id(); $field->help_text = $request->get("help_text"); $field->show_in_email = $request->get("show_in_email", 0); + $field->is_unique = $request->get("is_unique", 0); if ($request->get('format') == 'CUSTOM REGEX') { $field->format = e($request->get('custom_format')); diff --git a/resources/views/custom_fields/fields/edit.blade.php b/resources/views/custom_fields/fields/edit.blade.php index fd9e78ee3a..ba2fd0c6e0 100644 --- a/resources/views/custom_fields/fields/edit.blade.php +++ b/resources/views/custom_fields/fields/edit.blade.php @@ -116,6 +116,17 @@ + +
+
+ +
+ +
+ @if (!$field->id) diff --git a/resources/views/custom_fields/index.blade.php b/resources/views/custom_fields/index.blade.php index 01314fb7b7..13b69ca714 100644 --- a/resources/views/custom_fields/index.blade.php +++ b/resources/views/custom_fields/index.blade.php @@ -129,6 +129,7 @@ {{ trans('general.name') }} {{ trans('admin/custom_fields/general.help_text')}} {{ trans('general.email') }} + {{ trans('admin/custom_fields/general.unique') }} {{ trans('admin/custom_fields/general.db_field') }} {{ trans('admin/custom_fields/general.field_format') }} {{ trans('admin/custom_fields/general.field_element_short') }} @@ -142,6 +143,7 @@ {{ $field->name }} {{ $field->help_text }} {!! ($field->show_in_email=='1') ? '' : '' !!} + {!! ($field->is_unique=='1') ? '' : '' !!} {{ $field->convertUnicodeDbSlug() }} @if ($field->convertUnicodeDbSlug()!=$field->db_column) From 13832856f1230b988293a5a2969ecb0b0470d3a8 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Feb 2022 13:47:59 -0800 Subject: [PATCH 6/6] Added strings for unique Signed-off-by: snipe --- resources/lang/en/admin/custom_fields/general.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/lang/en/admin/custom_fields/general.php b/resources/lang/en/admin/custom_fields/general.php index 8483c67c69..4c7442b2d5 100644 --- a/resources/lang/en/admin/custom_fields/general.php +++ b/resources/lang/en/admin/custom_fields/general.php @@ -41,5 +41,7 @@ return [ 'make_required' => 'Optional - click to make required', 'reorder' => 'Reorder', 'db_field' => 'DB Field', - 'db_convert_warning' => 'WARNING. This field is in the custom fields table as :db_column but should be :expected .' + 'db_convert_warning' => 'WARNING. This field is in the custom fields table as :db_column but should be :expected .', + 'is_unique' => 'This value must be unique across all assets', + 'unique' => 'Unique', ];