eZ Platform Discussions

Migrating eZ Platform EE forms from development to production


#1

eZ Platform EE (Enterprise Edition) comes with a form building tool that allows content editors to create dynamic forms. This functionality builds on the eZ Studio landing page editing functionality, as the form builder is a block type for it.

Moving forms from one environment (dev/staging/prod…) to another is currently not supported by the core product. A third party tool, Kaliop Migrations Bundle, can be used to migrate eZ Platform EE Forms from one environment to another.

In addition to the content objects themselves, developers will need to migrate database tables used to store collected form information. The export of these tables needs to be done manually, but the import can be done using the Migrations Bundle’s SQL import feature.

The steps for this are roughly as follows:

Create a landing page

Create a landing page with the content as you normally would. If you are exporting multiple forms at a time, I recommend creating a container folder as well.

In our example case we will use Contenet Object IDs:

  • Form container (folder): 7915
  • Form (landing page): 7916

Export content object(s)

To export migrations from one environment to another, use the provided generate command to export forms, and a container for them:

./app/console kaliop:migration:generate --type=content --match-type=content_id --match-value=7915,7916 AppBundle forms

This will create a migrations file with a name similar to src/AppBundle/MigrationVersions/20180109101754_forms.yml. This migration file contains YAML like:

-
  type: content
  mode: create
  content_type: folder
  parent_location: 2

...more fields...

  attributes:
    name: 'Forms (2018)'

-
  type: content
  mode: create
  content_type: landing_page

...more fields...

  attributes:
    name: 'Example Form'
    description: 'Example Form'
    page: '{"page":{"layout":"default","title":"Example Form","zones":[{"id":"default_id","name":"default","blocks":[{"id":"b-67029b0d-5e31-fd29-acaa-b31b32460ec5","type":"formbuilder","name":"Form","view":"basic","ttl":"0","attributes":{"formId":"1"}}]}]}}'

To enable placement of forms dynamically to the folder, you can use the references feature in the Kaliop Migrations Bundle. First create a reference to the container folder migration:

references:
  -
    identifier: container_location
    attribute: location_id

Then replace the parent location with the reference for the landing page replacement:

parent_location: reference:container_location

Export form DB tables

In addition to the content objects, the form builder uses the following tables in the database:

  • ezformbuilder_form
  • ezformbuilder_form_content_relation
  • ezformbuilder_form_submission
  • ezformbuilder_form_version

You’ll also need to export the related entries for your newly created forms (block in a landing page).

When you are starting with new forms and are certain the databases are identical in terms of IDs, you can use a simple DB dump. To generate a SQL migration with Kaliop Migrations, run:

./app/console kaliop:migration:generate AppBundle --format=sql forms

This will create an empty SQL file to src/AppBundle/MigrationVersions/20180109102138_mysql_forms.sql. Next dump the four tables to this file from your local database:

mysqldump -uuser -ppwd mydb ezformbuilder_form ezformbuilder_form_content_relation ezformbuilder_form_submission ezformbuilder_form_version > src/AppBundle/MigrationVersions/20180109102138_mysql_forms.sql

Note: Matching the tables and the objects is done using content object IDs and forms, so this is not reliable to transfer from one location to another. You will need more sophisticated solutions like PHP migrations to manage this.

Add migrations to version control

Next add both of the migrations to version control:

  • src/AppBundle/MigrationVersions/20180109102138_mysql_forms.sql
  • src/AppBundle/MigrationVersions/20180109101754_forms.yml

Commit and push the code to the shared repository.

Running migrations

In your target environment, pull the code and execute migrations with:

./app/console kaliop:migration:migrate

This will start execution of migrations that have not yet been ran in the target environment. For the example the output will be something along the lines:

+---+--------------------------------+-------+
| # | Migration                      | Notes |
+---+--------------------------------+-------+
| 1 | 20180109101754_forms.yml       |       |
| 2 | 20180109102138_mysql_forms.sql |       |
+---+--------------------------------+-------+

Once the migration is complete, your database will have all the data needed to run the forms. Remember to verify that the forms are visible and editable.

If the forms are not available, there are likely mismatches between generated content objects and form data in the additional database tables.

For more information and tips for using Kaliop Migrations see this thread: eZ Platform content / database migration tips with Kaliop Migrations Bundle


eZ Platform content / database migration tips with Kaliop Migrations Bundle