Search

I’m starting this in a new thread as the current XML Importer thread is getting a little confusing.

I know that Brian (bzerangue) has been asking questions about populating Select Box Link fields with the importer, his point was more about multiple values.

My issue is related to the actual values in those select box links. I’ll start with a quick overview…

My Data contains an SID and a PID (basically an ID and a Parent ID). These are 4-6 digit numbers. The PID is a number that reflects an SID, like a back reference. The field that I need the PID to be in is the Select Box Link, as this is the only way I can reference the Parent once the data is in Symphony. Problem is, if I feed that into the Select Box Link, it stores my 4-6 digit number as it’s relation_id which is obviously not right, as the relation_id should be the entry it relates to.

I have no way of knowing, on import, what the Symphony generated entry id is (even though it is another previously imported section), so I need to know how to do this.

Is there any way of getting the XML Importer to treat Select Box Links differently when they are chosen in the fields list of the importer, to (for instance) look up the correct entry id for the content provided to it? How difficult would it be to do this?

I know that Brian actually feeds the right ID numbers to his Select Box Link, so if it is fixable how I need it, could there be an option to choose which method to use?

This would be a great addition to the Importer, making it much more extensible (hey hey, coined a keyword there!)

Brainstorm:

The logic I would need is:

  1. Insert the value into the importer field list from an xPath, as would be chosen in the Select Box Link field, via the Entry Editor, in the backend.
  2. XML Importer to look up this value using the field_select_box_link table to find the right relationships, and then use the right tables to find the value.
  3. XML Importer to populate the relevant table’s row with the correct Symphony Generated ID, relating to the value.

Way too difficult for me, quite a lot more logic in code than here. Anyone think this is possible?

Quite obviously would only work with already existing Symphony Data.

Right, the problem that’d you’d be hitting here is more to do with the SBL. It’ll treat numeric data as the ID, so it won’t attempt to handlise the value (which would get the correct resulting entry), instead it thinks that this is relation_id (like you mentioned).

It is possible that instead of soley using a 4-6digit, that you incorporate something like PID2343? AFAIK Symphony will treat that as a handle, and will lookup the SBL for the corresponding Symphony ID. In the XSLT you could then remove the PID for output.

It’s not necessarily nice, but I suppose this is just a limitation of the SBL. It’s a difficult spot to be in, because in 99% of cases, you want the current behaviour, numeric to be a direct ID, and string to a handle. The Brainstorm you posted is the logic that is already applied to handlised values.

If appending PID/SID or something isn’t a solution, you could look at writing a XML Helper function that would take the value and manually lookup the database as you’ve mentioned. I have a feeling that this will throw the datasource filtering off down the track though.

Ahh! @brendo, that explains a lot actually, there’s no problem with me prepending some text to the ID numbers…

I’ll play with it now.

I’ve spent most of the morning trying to come up with an xPath to do it in the importer as the xml is nested, so all children fall under the parent anyway.

The ID method is easier I think. I’ll try both and post the results here for reference.

Cheers!

Nope that doesnt work either…

My other idea was to use the Select Box Link to contain the parent nodes name node, but I can’t even do that as I have to set the Included elements to

//product[@usertypeid = ‘Level #’]

which produces no parent nodes.

Damn it, I’m going to have to re-engineer the xml before I pull it in… Good job I can do that with Symphony, eh? ;)

OK, so I’ve been having a play with XSLT to transform my XML into something more useable.

I’ve found that when I collect elements together using // I can still use the parent-node’s values using ../

I can’t do this with the importer. How does the importer work with relation to the xml, when setting Included Elements? Does it throw away all the rest of the xml?

It uses evaluate instead of query.

Can you post your sections, or maybe an ensemble of this so we can get a better idea of what you are trying to achieve?

Are you trying to create new entries in another section through the SBL?

I know this thread is rather old, but as it suggests that value- or handle-based import into Select Box Links should be possible and I am not able to get this running I'm ignoring the 3-year-break and simply continue the discussion.

Beeing able to import data into SBL without relying on the actual symphony system id would save me alot of time in a project I'm currently working on, so I set up this small test to check what's possible and what's not.

The XML-File I want to import:

<cities>
  <record>
    <name>Berlin</name>
    <country id="1" handle="germany">Germany</country>
  </record>
  <record>
    <name>London</name>
    <country id="2" handle="united-kingdom">United Kingdom</country>
  </record>
</cities>

I use this data to populate an empty Cities-section which is connected to a Countries-section through a Select Box Link. The Countries-section already has 2 entries, Germany with the internal ID 1 and United Kingdom with the internal ID 2.

Given this data I have three options to perform my matching for the SBL-Import - by value, by handle and by ID - but sadly only the last one is populating my SBL, the other methods leave it empty:

  1. by value : country/text() : not working
  2. by handle : country/@handle : not working
  3. by system ID : country/@id : working

(included elements: /root/record )

I tested this with two different Symphony Installations (2.3.2 and 2.2.5) and with the Reference Link Field instead of the SBL but results were always the same.

My two Test-Setups:

--

  • Symphony 2.3.2
  • XML Importer 2.0 (Integration Branch)
  • Select Box Link 1.2.6
  • Reference Link 1.4

--

  • Symphony 2.2.5
  • XML Importer 1.10
  • Select Box Link 1.2.2
  • Reference Link 1.3.7

--

So what I'd really like to know is:

Has anyone ever performed a successful XML-to-SBL-import based on handles or values? Or is this simply not possible at all?

Any help appreciated :)

Let me take a look at this tomorrow, at the very least by system ID : country/@id : working should be working with the 2.3.2 setup.

Edit Oh, I reread that. Yes, that example should work. By handle has not been configured.

It may help to describe exactly what is going on here (for everyone's sake, XML Importer is a bit of a black box):

  1. The XML Importer takes your XML file and uses XPath to treat the result as individual entries. A mock new Entry is created now.
  2. It will iterate over the mappings to extract the value, as evaluated by XPath.
  3. If the mapping's field implements the prepareImportValue function, it will call that using the first available $mode (getValue in the SBL/RL case). This function is passed the result of the XPath expression
  4. If no prepareImportValue function exists, then the importer tries some really basic sanitizing on the expression
  5. Once the value has been established, it is added to an array of this mock Entry's full data (ie, all previous mappings).
  6. After all mappings have been evaluated, the entry is checked to see if it's valid according to the field settings (done with Entry->checkPostData)
  7. If the entry data is valid, it is then processed using Entry->setDataFromPost.
  8. If all that went ok, then the XMLImporter continues to the commit() function, when it determines if the entry is new or needs to be updated.

Ideally, what we are trying to do in steps 3 and 4 is take an XML file of flat information and transform it into an array that the field expects when an Author is creating an entry in the backend. For the SBL field, it expects an array, array('relation_id' => array(1, 2)), which is why @handle is not working as expected. array('relation_id' => array('germany', 'united-kingdom')) is not going to work as the SBL saves ID references.

What is required instead, and this is what the Import/Export CSV extension does, is create a lookup to evaluate using the handle what the linked entry ID is. The SBL does a lookup in the buildDSRetrievalSQL function when a datasource has non numeric values, so I would think this needs to be exposed in the prepareImportValue function as well, so it can determine that if the array generated is non numeric, that it'll actually need to do lookups.

@brendo: thanks a lot for your detailed answer!

So the XML Importer simply isn't prepared for this kind of job yet but the CSV Importer is - never thought about this as an alternative, but as it seems to be capable of what I'm after I'm gonna give it a try tomorrow. Thanks for pointing me there!

Apart from that I would love to see this flexibility integrated in the XML Importer - XML simply feels much more "natural" when working with Symphony :)

I've pushed a fix to the Select Box Link field that will now handle importing when the data given is not an entry ID. This should make things much much simpler when importing!

It's available now, on the integration branch, but will be part of Symphony 2.3.3 as well (due shortly!)

Just a quickie here, would that handle multiple entries? How do we pass multiple entries to the SBL From the XML Importer?

Haven't tested, but australia, new-zealand, spain should be detected as three values I would think.

So I would need a helper then to concatenate nodes. No problem.

So, what the result of this issue? Now I'm trying to do the same. Is there narrower way to do it?

Hey, people, answer please. I'm trying to do the same. I need to import Countries->Areas->Cities values to my sections. It makes me crazy %(. What is the secret idea of populating SBL field types from XML Importer? Can't catch it, sorry. Same issue, new problems...

Hey Sorry, I don't check out the forum so regularly anymore.

To populate sbl with the XML Importer you have to use the relation_id, it would depend very much on what your inputs are and what you have.

What I usually have is a 'converting' function which takes in the String value, looks up the ID in the database and returns a properly formatted array which the Field will then save directly in the database. If you're around on Gitter would make it much easier for me to help you out. But I'll try keep an eye on the Forum

Thank you. I could try this way, either. Where can I find this function example? One more thing: do you know how can I achieve such pretty thing like this, on top of this page. "You're among 1 users online." How to detect on-line user status?

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