From da721e974914f29fcd00a3267a4608ed4abd7bcf Mon Sep 17 00:00:00 2001
From: Antonio Ospite <ospite@studenti.unina.it>
Date: Mon, 27 Jun 2011 11:57:22 +0200
Subject: [PATCH] Issue #587086: fix the WD php: Division by zero message
X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM<pyWR#k60!#=#>/Vb;]yA5<GWI5`6u&+
 ;6b'@y|8w"wB;4/e!7wYYrcqdJFY,~%Gk_4]cq$Ei/7<j&N3ah(m`ku?pX.&+~:_/wC~dwn^)MizBG
 !pE^+iDQQ1yC6^,)YDKkxDd!T>\I~93>J<_`<4)A{':UrE

When the number of images is less than 200 we get this message when
building the cache:

WD php: Division by zero in .../imagecache.drush.inc on line 163.

Make the code more robust to consider the case when images are
less than 200.

---
 imagecache.drush.inc |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/imagecache.drush.inc b/imagecache.drush.inc
index 63dff6c..7273945 100644
--- a/imagecache.drush.inc
+++ b/imagecache.drush.inc
@@ -140,11 +140,14 @@ function imagecache_drush_preset_build() {
     return FALSE;
   }
   $count = count($files);
+  if ($count == 0) {
+    return FALSE;
+  }
   drush_log(dt('Done. @count files to process using these presets: @presets', array('@count' => $count, '@presets' => implode(' ', $args))), 'ok');
 
   // Generate the images.
   $counter = 0;
-  $mod = round($count / 200);
+  $mod = ($count < 200) ? $count : round($count / 200);
   foreach ($files as $filepath) {
     foreach ($args as $arg) {
       $path = imagecache_create_path($arg, $filepath);
-- 
1.7.5.4

