Skip to content

Importer

Importes is a service located in App\Bundle\CmsAdminBundle\Services to import and export content types into the CMS.

Transitivity

The logic of import/export:

php
$projectA = ...;
$projectB = ...;

$rawEntityA = $projectA->export(1234);

$newId = $projectB->import($rawEntityA);

$rawEntityB = $projectB->export($newId);

assert $rawEntityA == $rawEntityB;

Example of article with import/export API:

shell
~$ $ curl -s -H "Authorization: Bearer $TOKEN" http://admin.starbase.lo:8080/api/importer/articles/29 | \
     xmllint --format - | tee q.xml | \
     curl -s -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/xml' -d @- \
            http://admin.starbase.lo:8080/api/importer/articles | xmllint --format -
<?xml version="1.0"?>
<item>
  <success>1</success>
  <articleId>49</articleId>
</item>

In this example, the 29 article export is imported as 49 article.

There are some requirements:

  • The sourceId must not be the same in the destination content.
  • The origin content template must exist in destination project.
  • The category assigned to the content must exist in the destination project.
  • Same modules must exist in the origin and destination
  • To summarize the origin structure and dependencies like category, template, tags, modules must be the same in both projects.

Articles

Modules

The module structure is exported in ArticleRoot::modules.

Indicate ['autoroles' => ''] element in the xml to create the list of roles in the same order automatically.

For example, with the xml datamodel:

xml
...
<modules>
  <__roles>main_image</__roles>
  <__roles>supratitle</__roles>
  <__roles>title</__roles>
  <__roles>epigraph</__roles>
  <__roles>content_colaborating</__roles>
  <__roles>author_location</__roles>
  <__roles>paragraph</__roles>
  <__roles>paragraph--1</__roles>
  <__roles>paragraph--2</__roles>
  <__roles>branded</__roles>
  <__roles>tags</__roles>
  <__roles>comments</__roles>
  <__roles>outbrain</__roles>
  <__roles>sidebar</__roles>
  <content_colaborating/>
  <epigraph>
    <content>que cosas</content>
  </epigraph>
  <main_image>
    <__roles>image_description</__roles>
    <__roles>image_credit</__roles>
    <__contentModels>
      <type>image</type>
      <id>1</id>
    </__contentModels>
    <__contentModels>
      <type>video</type>
    </__contentModels>
    <image_description>
      <content>Champions</content>
      <cmId>1</cmId>
    </image_description>
    <image_credit/>
    <__settings>
      <focal_point_image_x/>
      <default>1</default>
      <focal_point_image_y/>
      <focal_point_image_zoom/>
      <focal_point_image_width/>
      <crop_image/>
    </__settings>
  </main_image>
  ...
</modules>

After removing roles:

xml
<modules>
  <autoroles />
  <main_image>
    <autoroles />
    <image_description>
      <content>Champions</content>
      <cmId>1</cmId>
    </image_description>
    <__contentModels>
      <type>image</type>
      <id>1</id>
    </__contentModels>
  </main_image>
  <supratitle>
    <content>Supra title por ejemplo</content>
  </supratitle>
  <title>
    <content>Noticia 0123</content>
  </title>
  <epigraph>
    <content>un epigrafe</content>
  </epigraph>
  <paragraph>
    <content>&#xBF;Ha sido &#xE9;sto el primer p&#xE1;rrafo?</content>
  </paragraph>
  <paragraph--1>
    <content>P&#xE1;rrafo parrafito.</content>
  </paragraph--1>
  <paragraph--2>
    <content>Otro p&#xE1;rrafo.</content>
  </paragraph--2>
</modules>

The modules order is important.

Boards

Same as articles.

Users

A random plainPassowrd generated is assigned to the exported user.

If a plainPassowrd is not indicated in the importation, a new random one is generated.

UUID

Entities that have one or multiple external ids can be exported/imported by the source_id (recommended) or by internal id.

Layout structures are complex because of wf-modules (that build HTML from templates) so identify the id of an entity is hard, for example:

xml
    ...
    <main_image>
      <__roles>image_description</__roles>
      <__roles>image_credit</__roles>
      <__contentModels>
        <type>image</type>
        <id>1</id>                          <<< it is an image by the `type`
      </__contentModels>
      <__contentModels>
        <type>video</type>
      </__contentModels>
      <image_description>
        <content>Champions</content>
        <cmId>1</cmId>                      <<< go to wf-module to guess what it is
        ...

The exportation does not add the id attribute to the xml, but the importation requires it.

xml
    ...
    <main_image>
      <__contentModels>
        <type>image</type>
        <id>uuid:image:j109sdjkl12md97110d</id>
      </__contentModels>
      <image_description>
        <content>Champions</content>
        <cmId>uuid:image:j109sdjkl12md97110d</cmId>
        ...