From f02e62a4c46682faff331a622ea9b4f273e9b59c Mon Sep 17 00:00:00 2001 From: tavi toporjinschi Date: Thu, 14 Nov 2024 21:24:30 +0200 Subject: [PATCH 1/2] #6160: Sanitize Number fields on sql:sanitize Update SanitizeUserFieldsCommands.php --- .../Commands/sql/SanitizeUserFieldsCommands.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Drupal/Commands/sql/SanitizeUserFieldsCommands.php b/src/Drupal/Commands/sql/SanitizeUserFieldsCommands.php index f4ca3ffad2..931811b215 100644 --- a/src/Drupal/Commands/sql/SanitizeUserFieldsCommands.php +++ b/src/Drupal/Commands/sql/SanitizeUserFieldsCommands.php @@ -66,7 +66,7 @@ public function sanitize($result, CommandData $commandData): void $query = $conn->update($table); $name = $def->getName(); $field_type_class = \Drupal::service('plugin.manager.field.field_type')->getPluginClass($def->getType()); - $supported_field_types = ['email', 'string', 'string_long', 'telephone', 'text', 'text_long', 'text_with_summary']; + $supported_field_types = ['email', 'string', 'string_long', 'telephone', 'text', 'text_long', 'text_with_summary', 'integer', 'decimal']; if (in_array($def->getType(), $supported_field_types)) { $value_array = $field_type_class::generateSampleValue($def); $value = $value_array['value']; @@ -108,6 +108,16 @@ public function sanitize($result, CommandData $commandData): void ]); $execute = true; break; + + case 'integer': + $query->fields([$name . '_value' => 123]); + $execute = true; + break; + + case 'decimal': + $query->fields([$name . '_value' => 123.45]); + $execute = true; + break; } if ($execute) { $query->execute(); From 178ee4870b3acecec26a2062149109a7c5f6a4f2 Mon Sep 17 00:00:00 2001 From: tavi toporjinschi Date: Thu, 14 Nov 2024 21:46:08 +0200 Subject: [PATCH 2/2] Text updates to include number besides string/text fields. --- src/Drupal/Commands/sql/SanitizeUserFieldsCommands.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Drupal/Commands/sql/SanitizeUserFieldsCommands.php b/src/Drupal/Commands/sql/SanitizeUserFieldsCommands.php index 931811b215..3737e05d73 100644 --- a/src/Drupal/Commands/sql/SanitizeUserFieldsCommands.php +++ b/src/Drupal/Commands/sql/SanitizeUserFieldsCommands.php @@ -41,7 +41,7 @@ public function getEntityFieldManager() } /** - * Sanitize string fields associated with the user. + * Sanitize string and number fields associated with the user. * * @todo Use Drupal services to get field info. */ @@ -124,7 +124,7 @@ public function sanitize($result, CommandData $commandData): void $this->entityTypeManager->getStorage('user')->resetCache(); $this->logger()->success(dt('!table table sanitized.', ['!table' => $table])); } else { - $this->logger()->success(dt('No text fields for users need sanitizing.', ['!table' => $table])); + $this->logger()->success(dt('No text and number fields for users need sanitizing.', ['!table' => $table])); } } } @@ -132,7 +132,7 @@ public function sanitize($result, CommandData $commandData): void #[CLI\Hook(type: HookManager::ON_EVENT, target: SanitizeCommands::CONFIRMS)] public function messages(&$messages, InputInterface $input): void { - $messages[] = dt('Sanitize text fields associated with users.'); + $messages[] = dt('Sanitize text and number fields associated with users.'); } #[CLI\Hook(type: HookManager::OPTION_HOOK, target: SanitizeCommands::SANITIZE)]