mhuber84/randomizer

This TYPO3 extension allows you to randomize the content of database tables, either during a database export or directly in the database. The extension is useful for anonymizing data on or for development systems. The random values are generated with the fakerphp/faker package.

Installs: 23 800

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Forks: 1

Type:typo3-cms-extension

4.1.1 2025-08-25 15:55 UTC

README

What does it do?

This extension allows you to randomize the content of database tables, either during a database export or directly in the database.

The extension is useful for anonymizing data on or for development systems. The random values are generated with the fakerphp/faker package.

Randomize in the database

If a field in a table from the mapping contains a value, that value is replaced with a randomly generated one. Empty fields are ignored.

Randomize during export

If a field in a table from the mapping contains a value, that value is replaced with a randomly generated one. By default, only configured tables are exported. However, you can also export the entire database.

Installation

Install the extension by using Composer: composer req mhuber84/randomizer. To use the export feature, install the extension in production. Otherwise, you can add the option --dev to install it on development systems only. The extension is also available in the [TYPO3 Extension Repository] (https://extensions.typo3.org/extension/randomizer/).

Compatibility

RandomizerTYPO3PHP
412 - 138.1 - 8.4
3.511 - 127.4 - 8.3

Configuration

Configure the tables and fields in config/system/additional.php or your site packages ext_localconf.php.

Here is an example configuration for the fe_users table. Available faker providers/formatters are listed at https://fakerphp.github.io/formatters/. An additional Array faker provider is \Mhuber84\Randomizer\FakerProviders\ArrayProvider. It can return a serialzed and json array. It is used for the field 'uc' in this example.

The tables that you want to randomize must have a unique column named uid!

// Database fields to formatter mapping. https://fakerphp.github.io/formatters/
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['faker.']['mapping.']['fe_users.'] = [
    //TYPO3 Core fields
    'username' => 'userName',
    'password' => 'password',
    'address' => 'streetAddress',
    'telephone' => 'phoneNumber',
    'fax' => 'phoneNumber',
    'email' => 'safeEmail',
    'uc' => 'serialized',
    'zip' => 'postcode',
    'city' => 'city',
    'country' => 'countryCode',
    'www' => 'url',
    'company' => 'company',
    //'image' => '', //TODO
    'first_name' => 'firstName',
    'last_name' => 'lastName',
    'middle_name' => 'firstName',
    'felogin_forgotHash' => 'md5',
];

// List of unique fields. Fields have to be defined in the mapping, too! https://fakerphp.github.io/#modifiers
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['faker.']['unique.']['fe_users.'] = [
    //TYPO3 Core fields
    'username' => true,
];

// Locale for generated values. https://fakerphp.github.io/#localization
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['faker.']['locale'] = 'de_DE';

// List of equal fields.
// This has nothing to do with faker, but is useful for fe_users table if username and email are synchronized.
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['equal.']['fe_users.'] = [
    // The field 'email' gets the value of field 'username'.
    'email' => 'username',
];

// Skip these uids. Do not change them with faker and the equals stuff.
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['skipUids.']['fe_users'] = [
    // List of uids
    2,
    15,
];

Usage

Randomize in the database

ATTENTION: By default the database changes are not written to the database! If you really want to randomize the values in the database, add the --no-dry-run option.

Run the cli command:

vendor/bin/typo3cms randomizer:randomize

Run vendor/bin/typo3cms randomizer:randomize -h to see all options.

Randomize during export

Run the cli command:

vendor/bin/typo3cms randomizer:export mydatabase.sql

Run vendor/bin/typo3cms randomizer:export -h to see all options.

Custom faker providers

Register your provider in your ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['faker.']['providers.']['myProvider'] = \Vendor\Namespace\To\MyProvider::class;

Write your provider based on \Faker\Provider\Base. There is an example in \Mhuber84\Randomizer\FakerProviders\ExampleProvider and \Mhuber84\Randomizer\FakerProviders\ArrayProvider. More information on custom providers are available at https://github.com/fzaninotto/Faker#faker-internals-understanding-providers.

Development

Development is done with ddev.

Functional tests

There are two functionial tests for the two commands. You can run them with

ddev functional-tests "^12" "8.2"
ddev functional-tests "^12" "8.3"
ddev functional-tests "^12" "8.4"
ddev functional-tests "^13" "8.2"
ddev functional-tests "^13" "8.3"
ddev functional-tests "^13" "8.4"

Code quality

PHP CS Fixer:

ddev composer require --dev friendsofphp/php-cs-fixer:^3.86
ddev exec .Build/bin/php-cs-fixer fix

Rector & Fractor

Rector:

ddev composer require --dev ssch/typo3-rector:^3.6
ddev exec .Build/bin/rector process

Fractor:

ddev composer require --dev a9f/typo3-fractor:^0.5
ddev exec .Build/bin/fractor process

Credits

Many thanks go out to François Zaninotto and his package fzaninotto/faker!

And also thank you https://github.com/orgs/FakerPHP/people for forking the original package and maintainig it after the original package was archived.

Many thanks for the inspiration to this package go out to Georg Ringer and his package georgringer/gdpr!

Author

Marco Huber, @mhuber84@troet.cafe, mail@marco-huber.de

Feel free to contribute and send in pull requests or create an issue.