I have a site with a substantial number of nodes with PDFs attached. Currently I am using an Imagecache custom action (as specified in the Community documentation) to display an image of the front page, linked to the PDF file.
The problem I have with this is that it does not seem to be supported or maintained at all, and the latest versions have broken the custom action solution, so I have no upgrade path to D7. So, I would like to convert to "PDF to Imagefield", which is supported.
The question is, how to convert my existing nodes?
I have an idea of how to go about it but I would appreciate it if somebody could take a look and tell me if it seems sensible. Here's what I propose:
1) Modify the content type:
a) add an Image field
b) configure the PDF file field to connect it to the Image field
2) Create a script which will do the following:
a) find all the nodes of the appropriate content type (select statement on the node table)
b) for each node:
- node_load
- node-save
What I hope is that this will invoke hook_nodeapi for each node, thus causing PDF to Imagefield to do its thing and generate a new file.
Though I wonder whether an enhancement to the module, to check whether the image file exists before displaying and creating it if it does not, would not be a better solution (but I don't think I have the capacity for this)

Comments

dman’s picture

Most of the 'script' you are looking for could be managed by views_bulk_operations, so I'd suggest having a play with that.
There you can build a view to select what you want, and trigger any node actions,

Calling pdf_to_imagefield_node_presave(&$node), node_save() is probably the action you want to trigger - that will fill in any missing pieces.
Your basic idea is also correct

If there were to be an addition to the module, it would be by publishing a hook_node_operations action that would 'refresh pdf_to_imagefield settings' - and would be invoked from the content management screen or VBO.

joel_guesclin’s picture

Many thanks for this pointer - I did not write to say so because I only just got the time to start looking at VBO and trying to see how it works. Could I ask you to clarify something for me? I'm not sure how you go about including the "pdf_to_imagefield_node_presave(&$node)" action. Should I expect this to show up automatically in the VBO configuration of a View once I have defined a content field that actually uses it? Or will I have to write custom code as shown here?

dman’s picture

In the short term, I'd say to use VBO 'custom PHP code' - which lets you run any functions over all the selected nodes.
That function code would be just

pdf_to_imagefield_node_presave($node);
node_save($node);

In the fullness of time, then yeah the module should include a published, documented action you can just select from the list of available VBO actions, as described in that documentation page.
But until then, just use VBO + PHP code in the UI.

joel_guesclin’s picture

Many thanks, I did get this to work as you suggested, though given the parameter requirements in VBO the actual code to use is this:

pdf_to_imagefield_node_presave(&$object);
node_save(&$object);
dman’s picture

Status: Active » Closed (works as designed)