Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 1.83 KB

File metadata and controls

60 lines (40 loc) · 1.83 KB
description
Create a custom step for data migrations.

Create data migration step

Besides the built-in migrations steps, you can also create custom ones.

To create a custom migration step, you need:

  • A step class, to store any additional data that you might require.
  • A step normalizer, to convert YAML definition into your step class.
  • A step executor, to handle the step.

The following example shows how to create a step that replaces all ibexa_string fields that have an old company name with "New Company Name".

Create step class

First, create a step class, in src/Migrations/Step/ReplaceNameStep.php:

[[= include_file('code_samples/data_migration/src/Migrations/Step/ReplaceNameStep.php') =]]

Create normalizer

Then you need a normalizer to convert data that comes from YAML into a step object, in src/Migrations/Step/ReplaceNameStepNormalizer.php:

[[= include_file('code_samples/data_migration/src/Migrations/Step/ReplaceNameStepNormalizer.php') =]]

Then, tag the step normalizer, so it's recognized by the serializer used for migrations.

[[= include_file('code_samples/data_migration/config/custom_services.yaml', 18, 23) =]]

Create executor

And finally, create an executor to perform the step, in src/Migrations/Step/ReplaceNameExecutor.php:

[[= include_file('code_samples/data_migration/src/Migrations/Step/ReplaceNameStepExecutor.php') =]]

Tag the executor with ibexa.migrations.step_executor tag.

[[= include_file('code_samples/data_migration/config/custom_services.yaml', 23, 27) =]]

Then you can create a migration file that represents this step in your application:

-   type: company_name
    mode: replace
    replacement: 'New Company Name' # as declared in normalizer, this is optional