Quantcast
Channel: Planet Plone - Where Developers And Integrators Write
Viewing all articles
Browse latest Browse all 3535

Simples Consultoria: Products.contentmigration saves the day

$
0
0

Disclaimer

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

The Problem

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.

The Solution

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.

The Code

file: convert.py

Run it with:

./bin/instance run convert.py

Viewing all articles
Browse latest Browse all 3535

Trending Articles