Skip to content

Commit c2a36fc

Browse files
Improved migrations doc (#3296)
* Imroved migrations doc * Manual changes * Update docs/content_management/data_migration/importing_data.md Co-authored-by: julitafalcondusza <117284672+julitafalcondusza@users.noreply.github.com> --------- Co-authored-by: julitafalcondusza <117284672+julitafalcondusza@users.noreply.github.com>
1 parent 8eb3d97 commit c2a36fc

10 files changed

Lines changed: 189 additions & 30 deletions

File tree

code_samples/data_migration/examples/create_blog_post_ct.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
metadata:
55
identifier: blog_post
66
mainTranslation: eng-GB
7+
remoteId: blog_post_content_type
8+
creatorId: 14
9+
nameSchema: '<title>'
10+
urlAliasSchema: '<title>'
11+
container: true
12+
defaultAlwaysAvailable: true
13+
defaultSortField: 2 # Location::SORT_FIELD_PUBLISHED
14+
defaultSortOrder: 0 # Location::SORT_ORDER_DESC
715
contentTypeGroups:
816
- Content
917
translations:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-
2+
type: content
3+
mode: create
4+
metadata:
5+
contentType: folder
6+
mainTranslation: eng-GB
7+
creatorId: 14
8+
modificationDate: '2025-06-01T10:00:00+00:00'
9+
publicationDate: '2025-06-01T10:00:00+00:00'
10+
remoteId: options_folder
11+
alwaysAvailable: true
12+
section:
13+
identifier: standard
14+
location:
15+
parentLocationId: 2
16+
# parentLocationRemoteId: root_location
17+
locationRemoteId: options_folder_location
18+
hidden: false
19+
priority: 10
20+
sortField: 9 # Location::SORT_FIELD_NAME
21+
sortOrder: ASC
22+
fields:
23+
- fieldDefIdentifier: name
24+
languageCode: eng-GB
25+
value: 'Folder with all options'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-
2+
type: product_availability
3+
mode: create
4+
product_code: ergo_desk
5+
is_available: true
6+
is_infinite: false
7+
stock: 100
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-
2+
type: service_call
3+
mode: execute
4+
service: App\Migration\ContentImporter
5+
method: import
6+
arguments:
7+
- content.csv
8+
- 42
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-
2+
type: content
3+
mode: update
4+
match:
5+
field: content_remote_id
6+
value: options_folder
7+
metadata:
8+
mainLanguageCode: eng-GB
9+
name: 'Updated folder'
10+
initialLanguageCode: eng-GB
11+
remoteId: f5c88a2209584891056f987fd965b0ba
12+
mainLocationId: 5
13+
creatorId: 14
14+
ownerId: 14
15+
publishedDate: '2002-10-06T15:19:56+00:00'
16+
alwaysAvailable: false
17+
modificationDate: '2025-06-15T10:00:00+00:00'
18+
fields:
19+
- fieldDefIdentifier: name
20+
languageCode: eng-GB
21+
value: 'Updated folder'

code_samples/data_migration/examples/update_user.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
field: login
66
value: admin
77
metadata:
8+
email: admin@example.com
9+
enabled: true
810
password: '###XXX env("ADMIN_PASSWORD") XXX###'

docs/content_management/data_migration/data_migration_actions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ When executed, this migration:
5050

5151
The following migration actions are available out of the box:
5252

53+
- `assign_dashboard_to_user` (Content Create)
5354
- `assign_object_state` (Content Create)
5455
- `assign_parent_location` (Content Create / Update)
5556
- `assign_section` (Content Update)
@@ -91,6 +92,13 @@ mode: Update
9192
- { action: assign_section, identifier: 'media' }
9293
```
9394

95+
When creating a [dashboard](customize_dashboard.md) content item, you can assign it to a specific user, identified by their login:
96+
97+
``` yaml
98+
actions:
99+
- { action: assign_dashboard_to_user, value: admin }
100+
```
101+
94102
### Content types
95103

96104
mode: Create

docs/content_management/data_migration/importing_data.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ The following data migration step modes are available:
5050
| `action_configuration` | &#10004; | &#10004; | &#10004; | | |
5151
| `attribute` | &#10004; | &#10004; | &#10004; | | |
5252
| `attribute_group` | &#10004; | &#10004; | &#10004; | | |
53+
| `company` | &#10004; | | | | |
5354
| `content_type` | &#10004; | &#10004; | &#10004; | | |
5455
| `content_type_group` | &#10004; | &#10004; | &#10004; | | |
5556
| `content` | &#10004; | &#10004; | &#10004; | | |
@@ -71,16 +72,21 @@ The following data migration step modes are available:
7172
| `segment` | &#10004; | &#10004; | &#10004; | | |
7273
| `segment_group` | &#10004; | &#10004; | &#10004; | | |
7374
| `setting` | &#10004; | &#10004; | &#10004; | | |
75+
| `shipping_method` | &#10004; | | | | |
7476
| `user` | &#10004; | &#10004; | | | |
7577
| `user_group` | &#10004; | &#10004; | &#10004; | | |
7678

7779
Additionally, the following special migration types are available:
7880

79-
| `type` | `execute` |
80-
|------------------------|:---------:|
81-
| `repeatable` | &#10004; |
82-
| `sql` | &#10004; |
83-
| `try_catch` | &#10004; |
81+
| `type` | `mode` |
82+
|----------------|-------------------------------|
83+
| `reference` | `load`, `save`, `set`, `list` |
84+
| `repeatable` | `create` |
85+
| `service_call` | `execute` |
86+
| `sql` | `execute` |
87+
| `try_catch` | `execute` |
88+
89+
For more information about the `reference` type, see [References](managing_migrations.md#references).
8490

8591
### Repeatable steps
8692

@@ -112,6 +118,8 @@ In the example above, the expression is enclosed in `###` and the repeated strin
112118
!!! note
113119

114120
Iteration counter is assigned to `i` by default, but you can modify it in the `iteration_counter_name` setting.
121+
The counter starts at `0` by default.
122+
You can change this with the `iteration_counter_starting_value` setting.
115123

116124
#### Repeatable steps with items
117125

@@ -209,6 +217,25 @@ If the exception matches, it's caught and the migration step continues or stops
209217
The migration step is marked as successful and the migration process continues.
210218
Non-matching exceptions throw immediately, halting the migration process and returning an error.
211219

220+
### Service calls
221+
222+
You can call a method of a service by using the `service_call` migration type.
223+
Use it when a migration requires custom logic that isn't covered by the built-in migration types.
224+
225+
A `service_call` migration requires the `service` and `method` properties, and accepts an optional `arguments` list passed to the method:
226+
227+
```yaml
228+
[[= include_file('code_samples/data_migration/examples/service_call_step.yaml') =]]
229+
```
230+
231+
You can only call services that are explicitly listed under the `ibexa_migrations.callable_services` configuration key:
232+
233+
```yaml
234+
ibexa_migrations:
235+
callable_services:
236+
- App\Migration\ContentImporter
237+
```
238+
212239
### Expression syntax
213240

214241
You can use [Symfony expression syntax]([[= symfony_doc =]]/reference/formats/expression_language.html) in data migrations, like in [repeatable steps](#repeatable-steps), where you can use it to generate varied content in migration steps.
@@ -300,6 +327,7 @@ The following examples show what data you can import using data migrations.
300327
The following example shows how to create a content type with two field definitions.
301328

302329
The required metadata keys are: `identifier`, `mainTranslation`, `contentTypeGroups` and `translations`.
330+
The example also shows the optional metadata keys: `nameSchema`, `urlAliasSchema`, `container`, `defaultAlwaysAvailable`, `defaultSortField`, `defaultSortOrder`, `remoteId`, and `creatorId`.
303331

304332
The default values of field definition properties mirror the underlying PHP API, for example:
305333

@@ -314,7 +342,8 @@ The default values of field definition properties mirror the underlying PHP API,
314342

315343
The following example shows how to create two content items: a folder and an article inside it.
316344

317-
When creating a content item, three metadata keys are required: `contentType`, `mainTranslation`, and `parentLocationId`.
345+
When creating a content item, three metadata keys are required: `contentType`, `parentLocationId`, and `mainTranslation`.
346+
The `mainTranslation` property sets content item's main language.
318347

319348
To use the location ID of the folder, which is created automatically by the system, you can use a [reference](managing_migrations.md#references).
320349
In this case you assign the `parent_folder_location_id` reference name to the location ID, and then use it when creating the article.
@@ -323,6 +352,22 @@ In this case you assign the `parent_folder_location_id` reference name to the lo
323352
[[= include_file('code_samples/data_migration/examples/create_parent_and_child_content.yaml') =]]
324353
```
325354

355+
The following example shows the optional `metadata` and `location` properties that you can set when creating a content item.
356+
Instead of `parentLocationId`, you can identify the parent location with `parentLocationRemoteId`.
357+
`sortField` takes the numeric value of one of the `SORT_FIELD_*` constants from the [`Location` class](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Location.html), and `sortOrder` takes `ASC` or `DESC`, case insensitive:
358+
359+
``` yaml
360+
[[= include_file('code_samples/data_migration/examples/create_content_options.yaml') =]]
361+
```
362+
363+
Use the `update` mode to modify an existing content item.
364+
You can match the content item by `content_remote_id`, `location_id`, `parent_location_id`, or `content_type_identifier`.
365+
All `metadata` keys are optional: [`initialLanguageCode`](creating_content.md#translating-content), [`mainLanguageCode`](content_model.md#content-information), `creatorId`, `remoteId`, `alwaysAvailable`, `mainLocationId`, `modificationDate`, `publishedDate`, `name`, and `ownerId`.
366+
367+
``` yaml
368+
[[= include_file('code_samples/data_migration/examples/update_content.yaml') =]]
369+
```
370+
326371
Use the `delete` mode to delete content items:
327372

328373
``` yaml
@@ -412,7 +457,8 @@ You can use an [action](data_migration_actions.md) to assign a role to the user.
412457
[[= include_file('code_samples/data_migration/examples/create_user.yaml') =]]
413458
```
414459

415-
You can also update user information, including passwords:
460+
You can also update the user's email, enabled status, and password.
461+
All `metadata` keys are optional:
416462

417463
``` yaml
418464
[[= include_file('code_samples/data_migration/examples/update_user.yaml') =]]
@@ -503,6 +549,16 @@ The following example shows how to create a price for a product identified by it
503549
[[= include_file('code_samples/data_migration/examples/create_product_price.yaml') =]]
504550
```
505551

552+
#### Product availability
553+
554+
The following example shows how to define the availability and stock of a product identified by its code:
555+
556+
``` yaml
557+
[[= include_file('code_samples/data_migration/examples/create_product_availability.yaml') =]]
558+
```
559+
560+
When `is_infinite` is set to `true`, `stock` must be `null`.
561+
506562
#### Customer groups
507563

508564
The following example shows how to create a customer group with a defined global price discount:

docs/content_management/data_migration/managing_migrations.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,36 @@ The order of migration steps matters - they are executed sequentially from top t
167167
filename: 'references/new_references.yaml'
168168
```
169169

170+
You can also set a reference value manually with the `set` mode, and use the `list` mode to print all references collected so far to the migration log:
171+
172+
```yaml
173+
-
174+
type: reference
175+
mode: set
176+
name: parent_location_id
177+
value: 2
178+
179+
-
180+
type: reference
181+
mode: list
182+
```
183+
170184
## Available reference types
171185

172186
- `content`
173-
- content_id
174-
- location_id
175-
- path
187+
- `content_id`
188+
- `location_id`
189+
- `path`
176190
- `content_type`
177-
- content_type_id
191+
- `content_type_id`
178192
- `language`
179-
- language_id
193+
- `language_id`
194+
- `language_code`
180195
- `role`
181-
- role_id
196+
- `role_id`
197+
- `section`
198+
- `section_id`
199+
- `user`
200+
- `user_id`
182201
- `user_group`
183-
- user_group_id
202+
- `user_group_id`

0 commit comments

Comments
 (0)