Products.contentmigration saves the day
You write your transmogrifier pipeline, import content into Plone, see your images listed there just to -- at the last possible moment -- find out they were imported as files. No time to run the pipeline again... Then, the old, Products.contentmigration comes to rescue you
Summary above seems to be written by a bad Michael Bay movie publicist but something like that happened at work today. So let's forget about the plot holes and enjoy some lines of code
After importing 5Gb worth of static html, pdf's and images from filesystem to a customer's newly created site (thanks Dylan Jay for funnelweb) and testing it for the past 3 days, everything seemed ok. News Items, Pages, Files and Images where all available.
But... 2 hours before a meeting, where the site would be presented to our customer's stakeholders, someone noticed that in a area of the site all images where imported as files. Their icons was ok but they were Files.
There was no time to rerun the import -- and the original data was not on the same server, so it would take a while just to move it there -- so the idea was to convert File (ATBlob) to Image (ATBlob) in-place.
We've played with contentmigration quite a few times so it seemed like the right path to go. Write a Python script and run it from the command line on an unused instance.
What seemed very easy to do -- after all, contentmigration is well documented and you could always look for the migration implemented by plone.app.blob -- but there was a catch.
File and Image content types are very similar and "all you need to do" is move the data from field 'file' to the field 'image'. On their blob implementations, both types, use archetypes.schemaextender neither 'file' or 'image' field are defined on the content but on adapters.
So, it was needed to remove the plone.app.blob.interfaces.IATBlobFile interface from the migrated content, otherwise archetypes.schemaextender would try to adapt to IATBlobFile and to IATBlobImage, both interfaces providing a primary field.
Run it with:
./bin/instance run convert.py