Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/Commands/sql/sanitize/SanitizeUserFieldsCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'];
Expand Down Expand Up @@ -98,21 +98,31 @@ 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();
$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]));
}
}
}

#[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)]
Expand Down