Copying metadata values between schemas?


(Douglas (@finnatic at @waikato)) #1

Has anyone ever had to copy metadata values between schemas for assets?

 

I have an old schema which we're replacing with a new schema - and I'd like to populate values in the new schema with what the old schema had for those fields.  There's more than a handful of assets, so doing it manually for more than a select few would be time consuming.


(Tim Davison) #2

You can rename/drag/re-link existing schema fields and/or sections to new ones and the values are retained.  We do that a fair bit to retrofit existing sites with new schemas.  Metadata table seems to be a tertiary table so the actual primary key is an id, not the name.  

 

Or if you need to truly copy the metadata I use Trigger batching.  Depending on the field type there's a 'Set Metadata Value' or similar action.  Tick replace keywords and use %asset_metadata_x%.  Alternatively (again depending on the field) you can use dynamic parameters section, and use a keyword on the current asset, again using 'asset_metadata_x'.  

 

To trigger batch it use an event you would never use in real life for your site (in my case I always use 'Paypal IPN completed' for trigger batching).  Assuming you need to run it across large sections, be prepared to sit around and wait for the HIPO to complete.  Oh, and I have found (at least in my system) the HIPO jobs sits at 0% until it's completed.  It's just a quirk.  As long as it's processing new stuff it *is* running despite the 0%.  You can update multiple fields this way, just add more actions to the trigger - takes longer the more fields you do at once, but if you let it run overnight or have something else to do it's not so bad.

 

Test run on a few assets first to make sure trigger is working as expected.

 

Then, to confirm the result, generate an asset listing with old and new values side-by-side, probably in a table.  Copy that into excel and do a comparison (or run some JS on-load to compare before and after).  This allows you to catch the ones that were missed (as well as verify to your boss it's actually been done.  Pretty colours are a bonus).

 

I've done several sites, 30K+ assets copying metadata back and forth this way.  It's intensive work but far better than a copy+paste.


(Peter McLeod) #3

Hi

 

You could also use the Javascript API to automate the process... eg:

  • get an array of asset ids you want to update
  • loop through them getting the metadata from to old schema field
  • set/update it in the new schema field (could also do any extra work here to validate or clean the values if needed)

Thanks

Peter


(Evan Wills) #4

@Tim Davison How do you make the trigger fire?


(Tim Davison) #5

Do you mean how to use trigger batching?

 

Squiz manuals: https://manuals.matrix.squizsuite.net/triggers/chapters/batching

 

Basically, right click Triggers > Batching.

 

Select the trigger to run, select the root node to run it on, select the events to fire.  HIPO job starts.


(Evan Wills) #6

thanks