Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion code_samples/data_migration/examples/repeatable_step.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
fields:
- fieldDefIdentifier: name
languageCode: eng-GB
value: 'Folder ###SSS i SSS###'
value: 'Folder ###XXX i XXX###'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided to unify all the variable usages to ###XXX for consistency.

- fieldDefIdentifier: short_name
languageCode: eng-GB
value: '### faker().name() ###'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- type: repeatable
mode: create
steps:
- type: language
mode: create
metadata:
languageCode: '###XXX code XXX###'
name: '###XXX name XXX###'
enabled: true
items:
- { code: afr-AF, name: Afrikaans }
- { code: alb-SQ, name: Albanian }
- { code: ara-AR, name: Arabic }
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- type: repeatable
mode: create
iteration_counter_name: index
steps:
- type: content
mode: create
metadata:
contentType: folder
mainTranslation: eng-GB
remoteId: 'migration_folder_###XXX index XXX###'
location:
parentLocationId: 2
fields:
- fieldDefIdentifier: name
languageCode: eng-GB
value: '###XXX title XXX###'
items:
- { title: 'Getting Started' }
- { title: 'Advanced Configuration' }
- { title: 'API Reference' }
41 changes: 34 additions & 7 deletions docs/content_management/data_migration/importing_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,59 @@

You can run a set of one or more similar migration steps multiple times by using the special `repeatable` migration type.

A repeatable migration performs the defined migration steps as many times as the `iterations` setting declares.
A repeatable migration performs the defined migration steps as many times as specified:

``` yaml hl_lines="4"
[[= include_file('code_samples/data_migration/examples/repeatable_step.yaml', 0, 5) =]]
```
- with an [interation counter](#repeatable-steps-with-iteration-counter), mimicking the behavior of a [`for` loop](https://www.php.net/manual/en/control-structures.for.php)
- with a [list of items](#repeatable-steps-with-items), mimicking the behavior of a [`foreach` loop](https://www.php.net/manual/en/control-structures.foreach.php)

Check failure on line 92 in docs/content_management/data_migration/importing_data.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/content_management/data_migration/importing_data.md#L92

[Ibexa.Spellcheck] Did you really mean 'foreach'?
Raw output
{"message": "[Ibexa.Spellcheck] Did you really mean 'foreach'?", "location": {"path": "docs/content_management/data_migration/importing_data.md", "range": {"start": {"line": 92, "column": 87}}}, "severity": "ERROR"}

!!! tip

You can use repeatable migration steps, for example, to quickly generate large numbers of content items for testing purposes.

#### Repeatable steps with iteration counter

You can vary the operations using the iteration counter.

For example, to create five Folders, with names ranging from "Folder 0" to "Folder 4", you can run the following migration using the iteration counter `i`:

``` yaml hl_lines="16"
[[= include_file('code_samples/data_migration/examples/repeatable_step.yaml', 0, 16) =]]
``` yaml hl_lines="4 16"
[[= include_code('code_samples/data_migration/examples/repeatable_step.yaml', end_line=16) =]]
```

To vary the content name, the migration above uses [Symfony expression syntax](#expression-syntax).

In the example above, the expression is enclosed in `###` and the repeated string `SSS`.
In the example above, the expression is enclosed in `###` and the repeated string `XXX`.

Check notice on line 110 in docs/content_management/data_migration/importing_data.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/content_management/data_migration/importing_data.md#L110

[Ibexa.Passive] Try to avoid passive tense, when possible.
Raw output
{"message": "[Ibexa.Passive] Try to avoid passive tense, when possible.", "location": {"path": "docs/content_management/data_migration/importing_data.md", "range": {"start": {"line": 110, "column": 38}}}, "severity": "INFO"}

!!! note

Iteration counter is assigned to `i` by default, but you can modify it in the `iteration_counter_name` setting.

#### Repeatable steps with items

By using the `items` key, you can provide an array of items to the `repeatable` step:

Check notice on line 118 in docs/content_management/data_migration/importing_data.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/content_management/data_migration/importing_data.md#L118

[Ibexa.ByUsing] Prefer 'by using' or 'with' to plain 'using'.
Raw output
{"message": "[Ibexa.ByUsing] Prefer 'by using' or 'with' to plain 'using'.", "location": {"path": "docs/content_management/data_migration/importing_data.md", "range": {"start": {"line": 118, "column": 1}}}, "severity": "INFO"}

``` yaml hl_lines="10-13"
[[= include_file('code_samples/data_migration/examples/repeatable_step_with_items.yaml') =]]
```

In the example above, the step runs for each entry declared in `items`.
On each run, the values of `code` and `name` keys are available as variables.

The iteration counter variable (named `i` by default) is also available and holds the zero-based index of the current item.
You can rename it with the `iteration_counter_name` setting and combine it with item properties as in the following example:

``` yaml hl_lines="3 10 16"
[[= include_code('code_samples/data_migration/examples/repeatable_step_with_items_counter.yaml') =]]
```

This migration results in three new content items:

| Content item name | Remote location ID |
| ---------------------- | --------------------- |
| Getting started | `migration_article_0` |
| Advanced Configuration | `migration_article_1` |
| API Reference | `migration_article_2` |

#### Generating fake data

You can also generate fake data with the help of [`FakerPHP`](https://fakerphp.org/).
Expand Down
Loading