FamousWolf / randomdata

TYPO3 extensions to generate new random data or replace existing data with random data
GNU General Public License v3.0
14 stars 1 forks source link
anonymization data-generator extension faker random random-generator typo3 typo3-extension

TYPO3 Extension randomdata

TYPO3 extensions to generate new random data or replace existing data with random data

This extensions uses https://github.com/FakerPHP/Faker and was inspired by https://github.com/georgringer/faker. Thanks go out to the builders, contributors and maintainers of those projects.

Requirements

Manual

After installing randomdata in TYPO3 you can run it using the following command:

vendor/bin/typo3 randomdata:generate configuration.yaml

For more information about the command line options, use the following command:

vendor/bin/typo3 help randomdata:generate

The location of the configuration yaml file needs to be inside the site root.

For each record type you want to add to a PID you have to add configuration to the yaml file. The configuration for a single record type in a single pid looks like this:

recordTypeName:
  table: recordTable
  pid: recordPid
  action: action
  count: numberOfRecordsToCreate
  fields:
    field1:
      provider: Provider

A lot of Providers also require additional configuration. These can be placed on the same level as the Provider.

Providers

The following providers are available by default:

Example configuration yaml

categories:
  table: sys_category
  pid: 4
  action: insert
  count: 10
  fields:
    title:
      provider: Words
      minimum: 1
      maximum: 3

news:
  table: tx_news_domain_model_news
  pid: 4
  action: insert
  count: 20
  fields:
    title:
      provider: Sentences
      minimum: 1
      maximum: 1
    teaser:
      provider: Sentences
      minimum: 1
      maximum: 30
    bodytext:
      provider: Paragraphs
      minimum: 1
      maximum: 10
      html: true
    datetime:
      provider: DateTime
      minimum: -1 year
      maximum: now
      format: U
    categories:
      provider: Relation
      table: sys_category
      minimum: 0
      maximum: 5
    fal_media:
      provider: File
      minimum: 0
      maximum: 1
      source: fileadmin/randomimages/
      referenceFields:
        showinpreview:
          provider: FixedValue
          value: 1
    path_segment:
      provider: FixedValue
      value:

Custom Provider

You can create a custom provider from your own extension by adding a class which implements \WIND\Randomdata\Provider\ProviderInterface. It should have at least a static generate method.

You can set your custom provider in the configuration yaml file by setting the full class name in the provider option. For example provider: \My\Custom\Provider

Custom action

If you need anything other than insert or replace as action, you can use the generateItemCustomAction signal slot. You also need to set your action in the $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['randomdata']['allowedActions'] array.