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.
Requires
- fakerphp/faker: ^1.24
- typo3/cms-core: ^12.4||^13.4
Requires (Dev)
- typo3/coding-standards: ^0.8
- typo3/tailor: ^1.7
- typo3/testing-framework: ^8.0||^9.0
Replaces
- typo3-ter/randomizer: 4.1.1
- dev-main
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.5.0
- 3.4.12
- 3.4.11
- 3.4.9
- 3.4.8
- 3.4.7
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 2.1.0
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 1.2.0
- 1.1.0
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-testtgilabci
- dev-master
- dev-3-3-0-dev
- dev-TYPO3-9
- dev-TYPO3-8
This package is auto-updated.
Last update: 2025-09-25 14:10:50 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
Randomizer | TYPO3 | PHP |
---|---|---|
4 | 12 - 13 | 8.1 - 8.4 |
3.5 | 11 - 12 | 7.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.