Friday, 29 July 2022

Migrate Sitecore media library items into Content Hub - Part 2

 In the first part of this series I explained how we can generate excel files of Sitecore media library and their public links and how can use these in Sitecore Content Hub in an import operation using the creation component, to pull these media items into Content Hub DAM,  in this part I will show how you can update media library references/usage and replace image fields pointing to media library to point to Content hub using public links.   



If you didn't go through the previous post I would highly suggest to check it out, as we will depend on one of its output to get the replace job done, so here is the link: 


Now, if you remember, the first PowerShell script in the previous post, we got to pull all assets into Content Hub DAM and we created public links for these assets, in addition we get one extra CSV file which we will use to look for any usage of the media asset, this is one way of doing it, another way is to depends on the links database to get the usages of each single media asset (image, pdf...etc) using PowerShell as well and then replace the raw value of a field pointing to media item like below: 

<image mediaid="{123e4567-e89b-12d3-a456-426655440000}" />


and replace it with a format of image field raw value pointing to Sitecore Content Hub DAM: 


<image width='$($width)' height='$($height)' alt='$($alt)' src='$($imgSrc)' stylelabs-content-id='$($stylelabsId)' stylelabs-content-type='Image' thumbnailsrc='$($thumbnailSrc)' />


In the following Sitecore PowerShell we input two parameters, the first one is the csv file which contains the references/identifiers/public links from the first script, and the second param is the list of items to be updated (this can be generated through another PowerShell script), so basically you would need two CSV files as below: 

  1. The first csv file is the one generated previously which contains the public links and identifiers
  2. The second csv file is a file contains the media item Id to the Content Item Id relation. 

Here is the full PowerShell script: 


Hopefully this will be useful, if you have any questions please feel free to reach out to me through comments or email.

No comments:

Post a Comment