Search

Now that I’ve got this extension working, I have to say that it really rocks! Thanks Rowan & Nick!

It’s my XML Importer day today so please excuse all my posts in this thread. The import I’m trying to handle is tricky as the XML is complicated and I’m running into a few strange issues and a few things I can’t seem to solve. I know that this extension just reached version 0.1 so I expect that it’s quite easy to break things but maybe someone has a idea or recommendation how to get these things working.

CDATA

My XML generally looks like these two examples:

<Description><![CDATA[Sagt ein Bild mehr als tausend Worte? Was entsteht, wenn eine Künstlerin ein altes Gemälde<BR />abfotografiert und die Fotografie als künstlerische Arbeit ausstellt? Was macht das Potential<BR />von Kunst aus, was sind ihre Politiken und warum und wie beschäftigen wir uns mit ihr?<BR />Welche Praxisfelder tun sich mit einer kunstwissenschaftlichen Auseinandersetzung auf?<BR />Diese Einführung in die Kunstwissenschaft vermittelt grundlegende Begriffe und Methoden<BR />des wissenschaftlichen Umgangs mit Kunst. Neben der Beschreibung und Analyse<BR />unterschiedlicher Kunstgattungen wie Malerei, Skulptur, Architektur, Fotografie, Installation<BR />oder Video steht auch der Umgang mit verschiedenen Textsorten (Künstlermonographien,<BR />biographische Texte, Künstlerinterviews, Kunstkritik) auf dem Seminarprogramm. Die<BR />Veranstaltung ermöglicht vielfältige Einblicke in die Kunst des 19. und 20. Jahrhunderts und<BR />zeigt, dass sich auch der Zugang zu historischen Kunstformen aus den jeweils<BR />zeitgenössischen Interessen und Fragen heraus verstehen lässt.]]></Description>

<Title><![CDATA[Einführung in die Kunstwissenschaft]]></Title>

While the first example is imported as it should, the value of the latter is doubled for some reasons:

Einführung in die KunstwissenschaftEinführung in die Kunstwissenschaft

Allow multiple

I’ve got some items that I’d like to import into a select box:

<TestForms>
    <TestForm ID="1" Checked="true"><![CDATA[Hausarbeit]]></TestForm>
    <TestForm ID="2" Checked="false"><![CDATA[Klausur]]></TestForm>
    <TestForm ID="3" Checked="true"><![CDATA[mündliche Prüfung]]></TestForm>
    <TestForm ID="4" Checked="false"><![CDATA[kleiner Leistungsnachweis]]></TestForm>
    <TestForm ID="5" Checked="false"><![CDATA[Referat]]></TestForm>
    <TestForm ID="6" Checked="false"><![CDATA[Präsentation]]></TestForm>
    <TestForm ID="7" Checked="false"><![CDATA[Entwurfsarbeit]]></TestForm>
    <TestForm ID="8" Checked="false"><![CDATA[Dokumentation]]></TestForm>
</TestForms>

All these values are set as static options in the select box options - so far, so good. But how do I fetch the values of TestForms/TestForm[@Checked = 'true'] and add them to my select box. TestForms/TestForm[@Checked = 'true']/text() will return Hausarbeitmündliche Prüfung and TestForms/TestForm[@Checked = 'true'] will return nothing at all when I pass it to a XMLImporterHelper function for further processing. Unfortunately it seems not to be possible to split the result of the first xPath expression into an array as I need something like this:

array("Hausarbeit", "mündliche Prüfung");

Thanks for your help,
Nils

Okay, new day, new solutions:

  • Problem #1 wasn’t related to this extension - our XML export added a second element with the same name and content by mistake (some issues are easy to fix but hard to find).
  • Problem #2 can be solved by not joining the values of a node list directly but depending on the field context (join the values for inputs but handle them as array for select boxes etc.). I forked the original repository and added special support for select boxes, taglists and author fields: http://github.com/nilshoerrmann/xmlimporter/commit/958328baada3292ffa9aa6fccbb0e01f27134c98

Sweet! I remember adding this on my old version of the Import Manager (predecessor of XML Importer) but it must have been lost in translation somewhere.

Ah, all these different field type are making imports complicated! And to make things even worse here’s a new problem:

I’m still working on the import of our university courses. I have a section in Symphony that contains all the fields I need but I’m not importing into all these fields: There are some information I like to add in my Symphony backend that are not present in my imported XML. I have a unique ID for each entry so I’m making use of the update option the XML Importer offers. My problem is that each time when I update/re-import from my source XML the importer seems to delete all field data before recreating the values with the new data. This is just fine for those fields that are populated during the import but those with my additional information are just empty afterwards.

The XML Importer uses Symphony’s EntryManager: Does anybody know if there is a option so that the manager skips existing and unchanged fields?

And by the way, maybe these import helpers might be useful for others:

Dates and Times

/**
 * Convert dates from "1 January 2010, 12:00 to 2 January 2010, 12:00"
 * to a suitable array for the Date and Time field.
 */     
static function convertDateTime($string) {
    list($from, $to) = explode(' to ', $string);
    // Get from date and time
    list($sdate, $stime) = explode(', ', $from);
    list($sday, $smonth, $syear) = explode('.', $sdate);
    if(strlen($stime) == 2) {
        $shrs = intval($stime);
        $smin = 0;
    }
    else {
        list($shrs, $smin) = explode('.', $stime);
    }           
    // Get to date and time
    list($edate, $etime) = explode(', ', $to);
    list($eday, $emonth, $eyear) = explode('.', $edate);
    if(strlen($etime) == 2) {
        $ehrs = intval($etime);
        $emin = 0;
    }
    else {
        list($ehrs, $emin) = explode('.', $etime);
    }
    // Create range
    $range = array();
    $range['start'][] = date('j F Y, H:i', mktime($shrs, $smin, 0, $smonth, $sday, $syear));
    $range['end'][] = date('j F Y, H:i', mktime($ehrs, $emin, 0, $emonth, $eday, $eyear));
    return $range;
}

Checkboxes

/**
 * Return "yes" if a import node is found.
 * Helpful for populating checkboxes
 */
static function sayYes($string) {
    return 'yes';
}

Lists

/**
 * Create a markdown formatted list element for each text line
 */
static function createList($string) {
    if(empty($string)) return;
    // Get lines
    $lines = explode('<br />', $string);
    // Create list
    $list = '';
    foreach($lines as $line) {
        $list .= '- ' . $line . "n";
    }
    return $list;
}

Is this possible to run importers periodically using crontab?

I tried to periodically request URL http://www.example.com/symphony/extension/xmlimporter/importers/run/inporter/, but to execute it I must be logged in.

Bump. I need to find a way to do it ASAP. I tried to use it with shell extension with no luck so far…

I think something like this might work:

  • create an Author account in Symphony and enable “Allow remote login”
  • copy the “hash” portion from the end of the URL
  • log out of Symphony and try viewing the page with this URL:

http://www.example.com/symphony/extension/xmlimporter/importers/run/inporter/?auth-token={hash}

THANK YOU!!!!

Hey guys,

I can’t get this working. I’ve just upgraded to 2.07 and downloaded the current XML importer extension, but when I create an importer it has empty fields. That is, I’m filling out all the fields and then they go blank when I save it.

Obviously, I can’t get it to do anything.

Feels like a permissions issue, but I don’t know what files to look for.

Any ideas?

Ravi,

Anything in /workspace/xml-importers/? Can you maybe pastie the contents of the file?

yeah - the php file was created but it has (had – I’ve been messing with it) an empty array for the fields

with some tinkering, I am getting a basic import happening now (though I am sure I’m not doing it quite correctly), but I can’t figure out what to do with the xpath value if I need to import multiple entries (like multiple select box links). Using IDs I can hook up one ‘parent’ per entry, but I have no idea how to add multiple links.

OK i did get it to work after updating with the latest commits, but I still had to manually create the field information in the actual importer. I still can’t properly save changes to the fields from symphony’s interface.

Yeah I had the same issue on a fresh install of 2.0.7 with the latest version of XML Importer. Hopefully someone will get a chance to look at it soon…

I’m still working on the import of our university courses. I have a section in Symphony that contains all the fields I need but I’m not importing into all these fields: There are some information I like to add in my Symphony backend that are not present in my imported XML. I have a unique ID for each entry so I’m making use of the update option the XML Importer offers. My problem is that each time when I update/re-import from my source XML the importer seems to delete all field data before recreating the values with the new data. This is just fine for those fields that are populated during the import but those with my additional information are just empty afterwards.

The XML Importer uses Symphony’s EntryManager: Does anybody know if there is a option so that the manager skips existing and unchanged fields?

I’d like to re-ask this question. Rowan and Nick: Do you have a hint where to start when trying to handle this issue?

OK i did get it to work after updating with the latest commits, but I still had to manually create the field information in the actual importer. I still can’t properly save changes to the fields from symphony’s interface.

I use this extension with Symphony 2.0.7 (updated from 2.0.6) without problems, but I’m using the code from my own fork of the extension. Do you have any errors in your logs?

The XML Importer uses Symphony’s EntryManager: Does anybody know if there is a option so that the manager skips existing and unchanged fields?

This must be possible, since it is how Events work: you can post one single field value through an Event and it will update the entry, without touching other fields.

My guess is to start in class.xmlimporter.php and the validate() method. Line 190 iterates over the entries that need creating/updating and line 200 begins a loop over the values. I’m guessing that line 208:

$values[$field->get('element_name')] = $value;

Is incorrectly setting the value to nothing if the value isn’t found in the incoming XML? Maybe I’m wrong, since the setDataFromPost at this stage is passing simulate as true.

So I can’t actually figure out where the entries are saved. Usually the commit() method is called on each entry which then persists the data back to the database. But this isn’t being called anywhere…

Thanks for the input, Nick.

So I can’t actually figure out where the entries are saved. Usually the commit() method is called on each entry which then persists the data back to the database. But this isn’t being called anywhere…

That’s a bug I fixed here: http://github.com/nilshoerrmann/xmlimporter/commit/958328baada3292ffa9aa6fccbb0e01f27134c98#L0R296

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