Asset import from xml and asset id creation


(Alderman) #1

Hi.

 

We are looking to create an xml file from certain items in our our current (non-squiz) cms for import into squiz.  I've noticed from looking at an actual export from squiz, that we made, that an asset is created with a named id and then all sub parts of the asset (e.g. body copies etc..) are created with ids that are increments of the initial asset id.

 

e.g.

 

<action>    <action_id>create_Page_Standard_8044</action_id>
   <action_type>create_asset</action_type>
   <type_code>Page_Standard</type_code>
   <link_type>1</link_type>
   <parentid>1</parentid>
   <value></value>
   <is_dependant>0</is_dependant>
   <is_exclusive>0</is_exclusive>
</action>

 

<action>
   <action_id>create_Bodycopy_8045</action_id>
   <action_type>create_asset</action_type>
   <type_code>Bodycopy</type_code>
   <link_type>2</link_type>
   <parentid>[[output://create_Page_Standard_8044.assetid]]</parentid>
   <value></value>
   <is_dependant>1</is_dependant>
   <is_exclusive>1</is_exclusive>
</action>

 

My questions are:

 

Would we need to generate a hand-crafted set of asset ids in our export file?

 

How does Squiz track the next available asset ID? 

 

If we hand-craft a set of ids what happens the next time we create an asset in the ordinary way through the squiz back-end?

 

Is there a keyword replacement we could use to make squiz select the next available id as it runs through the xml file?

 

How would we handle parent IDs?

 

Many thanks.

 

Jeff.


(Benjamin Pearson) #2

<parentid>1</parentid>

The only assetid in your example is this one. You will need at least one assetid to join to the current asset tree you have (as a parentid). The rest of the parentids can be done by:

[[output://create_Page_Standard_8044.assetid]]

(from your example). If you are talking about these lines: "<action_id>create_Page_Standard_8044</action_id>" as being assetids, they are not. They are simply unique ids for the XML so it can use the above output:// code. If you run the export as XML tool on a current Matrix system, it will use the current assetid to generate this unique id but when imported it will not use this id to generate an asset id. It will just use the next one.
 
Hope that helps.


(Alderman) #3

Thanks Ben - that's exactly what I hoped would be the case.


(Anthony) #4

Hi Jeff

Just to let you know I've successfully bulk imported assets from external data using this technique, so its definitely worth you persevering! From my experience the <action_id> string is actually completely arbitrary as long as each is unique within the file you're importing. Its only a convention of the export feature that it uses the current asset IDs of the assets its exporting. You could use a string based on some reference in your current non-squiz system if that helped you make up unique strings.

Good luck!

Tony


(Alderman) #5

Thanks Tony - we will just use our current CMS's unique item id in that string.  It's also good to know someone else has used the tool in anger.

 

Jeff.


(Alderman) #6

One further question - Does anyone use this tool for moving development work to a production server?


(Anthony) #7

Yes quite often. (And thats not the bulk import I was referring to earlier which was a one-off exercise to create some assets from a separate data feed).

 

It works OK-ish. There are a few limitations, which might be bugs that might have been fixed in more recent versions (we were on a very old version when I first started using export / import and now we're on 4.16). Only a couple of the things I've had trouble with:

 

  • Nested assets within a standard page or a paint layout - they seem to come across OK and look fine in the admin screen but rarely work. Seem to have to acquire locks, note the nested asset ID, blank out the asset ID, commit, reenter the same ID and recommit. Only takes a moment but would be a right pain if you had loads of them to deal with. Must be a bug, so maybe fixed by now.
  • Anything related to designs / parse files

 

What it is really clever about is patching up anything with an asset ID in it from the source system and mapping it into the target system. It even seems to find the ./?a=nnnn syntax buried in raw HTML DIVs and converts them. There's one big caveat to that though - not unreasonably... you have to export / import ALL the assets you want to move in one go. If you do it in multiple tranches then any reference to assets not in that export will be unchanged.

 

Our production and dev servers are both VM images. What we tend to do is work on a big chunk of functionality over in DEV, get it all tested etc. Then use export / import to move it over to production. But then we'll throw away our dev server image and replace it with a clone of production before starting the next big package of work. That way msot of the asset IDs in DEV are always the same as prod except for work-in-progress.

 

I'm definitely not saying the above is best practice, but it happens to suit the way we work. Be very interested to hear what other folks do.


(Aleksb Mit) #8

Hi,

I am new to this forum and new user of SquizMatrix and now facing the same problem of import/export. I want to export from dev and import to live.

 

I inherited live site, never used squiz before, which didn't have any dev environment, now I have created it with clone of the live web site

 

But before I import the work from clone v4.18.0 to live I thought to test it first (as never done it before), so downloaded the v4.18.7 and it is  basically out of the box, nothing defined yet, bare bone, I've run import for only one file from version 4.18.0 (clone) , the js file from design folder to new 4.18.7 version. But it fails.

 

This is just a test, just to see how all works and how to role back if it fails, so I am wondering  do I need to import folder structure first with  import_folder_structure.php or I need to have one more clone of the live site, to act as second dev and then to try to import to new clone?  Can you just import to blank installation?

 

Anthony, It would be good to share your experience in more details if possible, for exporting to live environment, I've thought just to sync DBs?

e.g. how you deal with "Anything related to designs / parse files"?

 

I have thought that import/export will auto pick up dependent assets?

Any help is appreciated.

 

P.S.

I did checked the http://manuals.matrix.squizsuite.net/server-administrator/chapters/import-scripts

But not really for beginner.


(Nic Hubbard) #9

Have you looked at the backup scripts? You should just be able to backup the dev system and unpack, then import the DB for the site site. That is, if your live site has nothing currently on it and you are fine moving the entire Matrix instance, not just a Site asset. :)


(Aleksb Mit) #10

Hi Nic,

 

Thank you for your reply. Yep, that looks as good solution for transfering to 'new' web site.

 

We do have live site and clone of it that we use as dev system. Now, we have developed some new layouts and forms on the clone, how to transfer that work to live without copying/repplicating it by hand?

Can export/import scripts be used for that?

 

Thanks


(Nic Hubbard) #11

Yes, that should work. Have you tested them yet?


(Alderman) #12

Thanks for reminding me to complete this thread NIc.

 

Yes we now have templates in our current cms exporting content to Squiz export/import xml format and those are being imported in bulk into Squiz (tidying up the old html is a whole other story :-)  )

 

The driver for this was the need to create thousands of profiles in Squiz.  The content team are delighted that they don't have to create them from scratch one-by-one.

 

Jeff.