diff --git a/classes/TextimageImager.inc b/classes/TextimageImager.inc index 6094486..734483f 100644 --- a/classes/TextimageImager.inc +++ b/classes/TextimageImager.inc @@ -300,20 +300,6 @@ abstract class TextimageImager { */ protected static function buildImage($style, $source, $uri, $extension) { - // Don't start generating the image if generation is in progress - // in another thread. - $lock_name = 'textimage_process:' . $uri; - if (!file_exists($uri)) { - $lock_acquired = lock_acquire($lock_name); - if (!$lock_acquired) { - return FALSE; - } - } - - // Reset state. - self::setState(); - self::setState('building_module', 'textimage'); - // If no source image specified, we are processing a pure Textimage // request. In that case we need to use a dummy 1x1 image stored // in textimage/misc/images, and prepend an additional @@ -333,22 +319,29 @@ abstract class TextimageImager { $style['effects'] = $cleanup_effect + $style['effects']; } - // Try to generate the image, unless another thread just did it while we - // were acquiring the lock. - $success = file_exists($uri) || image_style_create_derivative($style, $source, $uri); - if (!$success) { - return FALSE; - }; - // Reset state. self::setState(); + self::setState('building_module', 'textimage'); + + // Try a lock to the file generation process. If cannot get the lock, + // return success if the file exists already. Otherwise return failure. + $lock_name = 'textimage_process:' . $uri; + if(!$lock_acquired = lock_acquire($lock_name)) { + return file_exists($uri) ? TRUE : FALSE; + } + + // Generate the image. + $success = image_style_create_derivative($style, $source, $uri); // Release lock. if (!empty($lock_acquired)) { lock_release($lock_name); } - return TRUE; + // Reset state. + self::setState(); + + return $success; } /**