recreate all images for all table uploads

7 posts by 2 authors in: Forums > CMS Builder
Last Post: 3 hours ago   (RSS)

Hi Jeff, 

Try: CMS Setup >Database Editor > Your Menu > Your Upload Field > Modify > Thumbnail Settings > "recreate" link.  That should automatically recreate all your thumbnails.

Let me know if that works for you.  Thanks!

Dave Edis - Senior Developer
interactivetools.com

Nope, that does not work for me. That is what I do now. It is a manual process that only does a single thumbnail at a time. I have 20 tables with several image upload fields (used for different purposes) across 50 client sites. Doing a site at a time would only take 20 clicks, whereas doing it manually takes (50 sites x20 tables x4 thumbs) a minimum of 4000 clicks, assuming only one upload field per table, not including navigating to each table and each upload field in the database editor.

I want to write a plugin to automate it across all selected tables and uploads with one command. Similar to how the permalinks->update table works.

The plugin would work like so:

  1. Display a list of all tables that have 'upload' fields
  2. Select one or more tables
  3. Iterate over each table
    1. iterate over each 'upload' field
      1. iterate over each thumbnail
      2. recreate each thumbnail (requires rebuilding each image, and updating uploads table)

I'm just unsure where to start with triggering the recreate. The first three steps are easy to 3.1.1; I'm stuck on 3.1.2.

I haven't figured out which function to call or if I need to call a Javascript function. Reverse engineering the whole process to find the entry point takes too much time, so a little guidance is all I need.

Jeff Shields

Hi Jeff, 

Sure, here's where the relevant code is: 

  • recreateThumbnails(num) in /cmsb/lib/menus/database/editField_functions.js
  • recreateThumbnails() in /cmsb/lib/upload_functions.php
  • And the code that triggers it is in /cmsb/lib/menus/database/editField.php
<a href="#" onclick="recreateThumbnails('<?php echo $num ?>'); return false;" id="recreateThumbnailsLink<?php echo $num ?>"><?php echo t('recreate'); ?></a>
<span id="recreateThumbnailsStatus<?php echo $num ?>"></span>

If you could piggyback on that code, it might be easiest.  Through the web, you could loop over your tables and create an iframe with each upload field that triggered the start of the js process.  Or, from the command line you could call the PHP recreateThumbnails() directly and fake the $_REQUEST values to make it do what you want.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

Perfect, I will dig into it a bit deeper over the next 2 weeks

Jeff Shields

I was researching the iframe idea and looked through several plugins. However, I am unsure what you mean or why I might need an iframe.

Could you provide a bit more detail?

Thanks.

Jeff Shields

HI Jeff,

I thought we could make use of the CMSB functionality but taking a closer look it didn't seem feasible.  

Try the attached command line script, if you can get it working, and then have it loop over all your tables, fields and thumb numbers, it might do what you need.

Dave Edis - Senior Developer
interactivetools.com
Attachments:

resizer.php 6K