Import from xml script


(Tmlalazi) #1
greetings all,
 
I am trying to update my assets with descriptive metadata to no joy. I've been digging through the forums hoping someone has wanted to do a similar thing in the past to no avail. I have tried the import from XML script and it's looking like it only works if you are creating new assets. I think to myself surely there are people who would like to do this every now and then and sure enough there are but they tend to use the  csv to xml but the issue is that my metadata has a lot of commas in it.
 
This is some of the XML (I didn't put all of it as it  is a repeat of the same thing), the metadata goes in the variable '$description'. 
 
<?xml version="1.0" encoding="UTF-8"?>
<actions>
  <action>
    <action_id>set_Image_31450_metadata_field_832</action_id>
    <action_type>set_metadata_value</action_type>
    <asset>[[output://create_Image_31450.assetid]]</asset>
    <fieldid>832</fieldid>
    <value>![CDATA[$description]]</value>
  </action>
  <action>
    <action_id>set_Image_31452_metadata_field_832</action_id>
    <action_type>set_metadata_value</action_type>
    <asset>[[output://create_Image_31452.assetid]]</asset>
    <fieldid>832</fieldid>
    <value>![CDATA[$description]]</value>
  </action>
 
The error is as follows
 
set_Image_31450_metadata_field_832                                    +---------
--------------------------------------------------------------------------------
-----------------------------------------------------------------------------+
| MySource Error
 
       |
|-------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------|
| Failed getting asset for set_metadata_value action "set_Image_31450_metadata_f
ield_832" - attribute references action "create_Image_31450" that has not yet be
en run |
+-------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------+
 
Thus there is a create_image_asset_ID that has to be run which becomes a handle for the set_Image_31450_metadata_field_832 action. But I have the assets already created all i want is to set the metadata. So may be there should be another action like the Hipo job (hipo_job_import_assets_from_xml.inc line 148) {if($action['action_type'][0] === 'create_file_asset') {
} which will look at just setting metadata or other attributes of the already created assets. 
 
 
 

(Anthony) #2

I think your problem is easy enough... the XML format uses a special "output://" notation so that on a normal import, updates relate back to the asset just created (whose asset ID couldnt possibly be known at the time the script was written), You've left this in your code:

 

<asset>[[output://create_Image_31450.assetid]]</asset>

 

Which the import routine cant handle because there was no action_id called "create_Image_31450". Bear in mind the action ID's are just literal text and can be anything you like, just by convention the export routine uses the original source asset number in there.

 

So... just change your file so that the <asset> element has the actual asset number you want to update:

 

<asset>31450</asset>

 

Hope that works for you!


(Tmlalazi) #3

But of course, I had thought that, that may have been the issue but without any documentation I didn't want to mess with anything as my understanding of the matter wasn't enough. Thank you very much. It works, so now I'll concentrate on the format of the text.