Search

Destinations Ensemble and XML Importer

Here is a proof of concept for an ensemble that has the ability to take the front end entry form, with some slight modifications to indicate which fields are section links and which columns should appear in the entries list view, and dynamically build the forms necessary for importing individual entries or importing multiple entries into a single section. To view this data source, install the ensemble and navigate to the following with {$root} replaced by the address of the install directory:

 {$root}/symphony/blueprints/datasources/edit/destinations_sections/

Note the addition of the container elements:

<destinations-sections>
    <section branch="parent">
        <title lowercase="continents" handle="continents">Continents</title>
        <type lowercase="continent" handle="continent">Continent</type>
        <form method="post" action="" enctype="multipart/form-data">
            <input name="MAX_FILE_SIZE" type="hidden" value="5242880" />
            <label class="show">Continent
                <input name="fields[continent]" type="text" />
            </label>
            ...
        </form>
    </section>
    <section branch="self">
        <title lowercase="countries" handle="countries">Countries</title>
        <type lowercase="country" handle="country">Country</type>
        <form method="post" action="" enctype="multipart/form-data">
            <input name="MAX_FILE_SIZE" type="hidden" value="5242880" />
            <label class="show">Country
                <input name="fields[country]" type="text" />
            </label>
            <label class="show">Continent
                <select name="fields[continent]" class="section-link"/>
            </label>
            ...
        </form>
    </section>
    <section branch="child">
        <title lowercase="regions" handle="regions">Regions</title>
        <type lowercase="region" handle="region">Region</type>
        <form method="post" action="" enctype="multipart/form-data">
            <input name="MAX_FILE_SIZE" type="hidden" value="5242880" />
            <label class="show">Region
                <input name="fields[region]" type="text" />
            </label>
            ...
        </form>
    </section>
<destinations-sections>

While I haven’t provided cases for all types of fields, input, textarea and select fields, including section links, should work for the most part (since I primarily wanted to illustrate the concept of being able to import data).

Destinations Ensemble 0.2

Updated the ensemble from Symphony 2 Beta Revision 5 to Symphony 2.0 (zip download). It also includes a brief introduction to Symphony that provides a quick tour of the system.

Instructions

I have built an ensemble that is similar to all my other ensembles, but this time using a different triad of sections:

Destinations

  • Continents
  • Countries
  • Regions

Included in the ensemble are examples of the XML that I have used as Static XML data sources. Flat files can be found here:

{$workspace}/assets/xml/

These XML files were built from an ensemble that is currently in development for a travel affiliate site.

The overview page allows the ability to view the links between sections:

{$root}/destinations/

To start with, only the Continents section has been populated, although, you'll notice that the description field is empty, even though the data source includes this. I'll let you experiment with deleting these and reimporting using the individual entry importer to preserve this data.

{$root}/destinations/continents/

To view an import in action, go to the following address (I have not added links in the interface for importing, since I figured this would be something that might be used only at the outset of a project rather than on a continual basis):

{$root}/destinations/continents/import/

In this case, all entries are represented in the section data, so there is no need to import any additional data. The ability to import data for an entry is disabled when the section handle field is already populated with data that matches the import data.

Now, view the countries list:

{$root}/destinations/countries/

A single country entry exists in the Countries section: Canada. I have created a Static XML data source called "Import Countries by Continent"

{$root}/symphony/blueprints/datasources/edit/import_countries_by_continent/

and I have configured the Countries page:

{$root}/symphony/blueprints/pages/edit/10/

with the following parameter:

<!-- configure import -->
<xsl:param name="import-entries" select="/data/import-countries-by-continent/continent/entry"/>

This data source will be imported into the page as a multiple entry form:

{$root}/destinations/countries/import/

You'll notice that Canada has been singled out as a duplicate entry. Saving the form will create new entries for all but this entry, since the lack of any input data for the handle field will cause the creation of this entry to fail.

However, before you go ahead and click the import button, notice that you can type in the handle of any of the entries to switch to single entry import mode:

{$root}/destinations/countries/import/ao/

This allows you to import each entry, one at a time. (Here there is the possibility of adding duplicate entries if you're not careful. I haven't added any logic to warn of duplicate entries.)

The same master template is used to build the forms for all three sections. Each page template provides additional configuration parameters that are specific to each page.

A Warning

I have not thoroughly tested everything. I believe there are some problems with the way multiple entry forms deal with non-section-link select menu options. For example, the Type column for the Regions section does not accurately display the correct type of region for the US states that have been included as a data source you can try importing for the United States.

{$root}/symphony/blueprints/datasources/edit/import_regions_us/

To import the US states, you first need to attach the data source to the Regions page and change the import configuration for the page to the following:

<!-- configure import -->
<xsl:param name="import-entries" select="/data/import-regions-us/entry"/>

And you may want to modify the template to force it to select "State", for instance. Otherwise, you'll need to manually change the select menu for each entry. Also, the section link for Regions will likely fail to show the correct country, as I have configure it to work with a data source that is grouped by the parent section link entry. I'll leave that as homework for anyone who wants to add the ability to automatically test for different XML structures to find the appropriate data for each field and field type.

Destinations Ensemble 0.2

Updated the ensemble from Symphony 2 Beta Revision 5 to Symphony 2.0 (zip download). It also includes a brief introduction to Symphony that provides a quick tour of the system. (See above)

This is cool idea. Have You thought about making it to be able to split enty into two connected entries (i'm sorry i didn't try it yet, so maybe it already can do that)? That would make perfect, flexible bridge for upgrading Symphony 1.7 to Symphony 2.0 (and later 2.0 to 3.0 :).

@ahwayakchih, could you explain what you mean by splitting an entry into two connected entries.

One of the goals I had in creating this ensemble was to demonstrate the possibility of importing data from other content management systems into Symphony. As long as you have valid XML to feed into Symphony, this method works quite well, although it does require some work to set up the import.

I was thinking that a next step would be to create ensembles that work similar to popular CMS, such as Textpattern and WordPress, and to have the necessary fields set up so that it would be possible to generate an XML export, then import the data into Symphony. Of course, the same method could be used for importing data from Symphony 1.7 to 2.0. However, it's impossible to assume the data structures with Symphony, unless you're working with a default Symphony 1.7 install with no modifications made to custom fields.

The perfect bridge would be a custom import script for each CMS, but, in absence of that, I think this method could work, and ultimately be more flexible, since it would be possible to map data to whatever fields you wanted to, depending on how you set up the configuration files. Inevitably, I find that Symphony blows away so many limitations that you end up wanting to build something entirely different anyway.

bauhouse, by splitting i meant to get entry from Symphony v1.7, and then create separate entries based on that one, e.g., 2 photo entries, 1 whatever entry, and "main" entry in the end (so it has links to 3 entries, just created). So, from one XML data, call more than 1 forms.

However, it's impossible to assume the data structures with Symphony

Yes, that's why i think that idea to first export XML and then write XSL/XML to import it, is best way to upgrade incompatible CMS-es.

I think this method could work, and ultimately be more flexible, since it would be possible to map data to whatever fields you wanted to, depending on how you set up the configuration files.

I couldn't agree more :).

Inevitably, I find that Symphony blows away so many limitations that you end up wanting to build something entirely different anyway.

Indeed.

@ahwayakchih, I am assuming that you are talking about saving entries to three different sections: Photos, Categories, and Articles, for example. Unfortunately, the current implementation of custom admin forms doesn't provide the ability to save to more than one section at a time. So, I think it would be necessary to set up separate imports for each section.

The way I would go about it would be to think about the parent-child relationships between each of the sections. Categories might be the parent of Articles, which would be the parent of Photos, for instance. First, you would import the list of Categories, then you would import the Articles, linking them to the Categories section, then you would import the Photos, linking them to the corresponding article(s).

bauhouse, that's very good idea! I don't know why i was thinking i have to import everything all in one run.

So if i import Categories first, will it "remember" their original IDs and new IDs, so when it starts importing Articles it will what value to put into section link field?

IDs are automatically assigned by Symphony according to order of entry creation, so I'm guessing you'll probably have better results matching handles during the import. This could get complicated by multiple entries having the same values for a particular field, but I doubt that would be the case with category titles.

Yes, sorry i used wrong words - i meant "something that uniquely marks each entry" (so IDs too, but also handles).

For example i could put original IDs into exported data, and then keep them somewhere with imported data. So next time importing script bumps into entry that is linked to one of categories, i can find that category by it's original ID/handle/whatever, and set section link value to that category new (after import) ID :).

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details