Skip to content

Commit 95cd910

Browse files
committed
Added doc for repeatable step with items. Unified expressions to use ###XXX
1 parent a28e3bc commit 95cd910

4 files changed

Lines changed: 68 additions & 8 deletions

File tree

code_samples/data_migration/examples/repeatable_step.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
fields:
1414
- fieldDefIdentifier: name
1515
languageCode: eng-GB
16-
value: 'Folder ###SSS i SSS###'
16+
value: 'Folder ###XXX i XXX###'
1717
- fieldDefIdentifier: short_name
1818
languageCode: eng-GB
1919
value: '### faker().name() ###'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- type: repeatable
2+
mode: create
3+
steps:
4+
- type: language
5+
mode: create
6+
metadata:
7+
languageCode: '###XXX code XXX###'
8+
name: '###XXX name XXX###'
9+
enabled: true
10+
items:
11+
- { code: afr-AF, name: Afrikaans }
12+
- { code: alb-SQ, name: Albanian }
13+
- { code: ara-AR, name: Arabic }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- type: repeatable
2+
mode: create
3+
iteration_counter_name: index
4+
steps:
5+
- type: content
6+
mode: create
7+
metadata:
8+
contentType: folder
9+
mainTranslation: eng-GB
10+
remoteId: 'migration_folder_###XXX index XXX###'
11+
location:
12+
parentLocationId: 2
13+
fields:
14+
- fieldDefIdentifier: name
15+
languageCode: eng-GB
16+
value: '###XXX title XXX###'
17+
items:
18+
- { title: 'Getting Started' }
19+
- { title: 'Advanced Configuration' }
20+
- { title: 'API Reference' }

docs/content_management/data_migration/importing_data.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,59 @@ Additionally, the following special migration types are available:
8686

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

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

91-
``` yaml hl_lines="4"
92-
[[= include_file('code_samples/data_migration/examples/repeatable_step.yaml', 0, 5) =]]
93-
```
91+
- 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)
92+
- 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)
9493

9594
!!! tip
9695

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

98+
#### Repeatable steps with iteration counter
99+
99100
You can vary the operations using the iteration counter.
100101

101102
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`:
102103

103-
``` yaml hl_lines="16"
104-
[[= include_file('code_samples/data_migration/examples/repeatable_step.yaml', 0, 16) =]]
104+
``` yaml hl_lines="4 16"
105+
[[= include_code('code_samples/data_migration/examples/repeatable_step.yaml', end_line=16) =]]
105106
```
106107

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

109-
In the example above, the expression is enclosed in `###` and the repeated string `SSS`.
110+
In the example above, the expression is enclosed in `###` and the repeated string `XXX`.
110111

111112
!!! note
112113

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

116+
#### Repeatable steps with items
117+
118+
By using the `items` key, you can provide an array of items to the `repeatable` step:
119+
120+
``` yaml hl_lines="10-13"
121+
[[= include_file('code_samples/data_migration/examples/repeatable_step_with_items.yaml') =]]
122+
```
123+
124+
In the example above, the step runs for each entry declared in `items`.
125+
On each run, the values of `code` and `name` keys are available as variables.
126+
127+
The iteration counter variable (named `i` by default) is also available and holds the zero-based index of the current item.
128+
You can rename it with the `iteration_counter_name` setting and combine it with item properties as in the following example:
129+
130+
``` yaml hl_lines="3 10 16"
131+
[[= include_code('code_samples/data_migration/examples/repeatable_step_with_items_counter.yaml') =]]
132+
```
133+
134+
This migration results in three new content items:
135+
136+
| Content item name | Remote location ID |
137+
| ---------------------- | --------------------- |
138+
| Getting started | `migration_article_0` |
139+
| Advanced Configuration | `migration_article_1` |
140+
| API Reference | `migration_article_2` |
141+
115142
#### Generating fake data
116143

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

0 commit comments

Comments
 (0)