From 394a1b32bb2ea4935bcd16afc73d5e6776beeef0 Mon Sep 17 00:00:00 2001 From: tavi toporjinschi Date: Thu, 14 Nov 2024 20:22:19 +0200 Subject: [PATCH 1/2] #6160: Sanitize Number fields on sql:sanitize Update SanitizeUserFieldsCommands.php --- .../sql/sanitize/SanitizeUserFieldsCommands.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php b/src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php index b858e62154..9d73b9c24b 100644 --- a/src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php +++ b/src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php @@ -69,7 +69,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']; @@ -98,6 +98,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 d60e5cac342655f849b8c3b0b01d6157ca5298ea Mon Sep 17 00:00:00 2001 From: tavi toporjinschi Date: Thu, 14 Nov 2024 21:33:33 +0200 Subject: [PATCH 2/2] Text updates to include number besides string/text fields. --- src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php b/src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php index 9d73b9c24b..c59778312f 100644 --- a/src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php +++ b/src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php @@ -46,7 +46,7 @@ public function getEntityFieldManager() } /** - * Sanitize string fields associated with the user. + * Sanitize string and number fields associated with the user. */ #[CLI\Hook(type: HookManager::POST_COMMAND_HOOK, target: SanitizeCommands::SANITIZE)] public function sanitize($result, CommandData $commandData): void @@ -114,7 +114,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])); } } } @@ -122,7 +122,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)]