Commit faf20e8444bcdaace5698499c45524307105e331

Authored by Paul Barrett
1 parent eb5cf7a7

Set thumbnailer to attempt creation of thumbnail on display if not already exists

plugins/thumbnails/thumbnails.php
... ... @@ -146,10 +146,12 @@ class thumbnailGenerator extends BaseProcessor {
146 146 $default->log->debug('Thumbnail Generator Plugin: PDF file does not exist, cannot generate a thumbnail');
147 147 return false;
148 148 }
  149 +
149 150 // if a previous version of the thumbnail exists - delete it
150 151 if (file_exists($thumbnailfile)) {
151 152 @unlink($thumbnailfile);
152 153 }
  154 +
153 155 // do generation
154 156 if (extension_loaded('imagick')) {
155 157 $result= shell_exec("convert -size 200x200 {$pdfFile}[0] -resize 200x200 $thumbnailfile");
... ... @@ -179,8 +181,18 @@ class ThumbnailViewlet extends KTDocumentViewlet {
179 181 $pdfDir = $default->pdfDirectory;
180 182 $thumbnailfile = $pdfDir . '/thumbnails/'.$documentId.'.jpg';
181 183  
182   - // check that file exists
183   - if (!file_exists($thumbnailfile)) return '';
  184 + // check that file exists, attempt to create if not
  185 + if (!file_exists($thumbnailfile))
  186 + {
  187 + // try to create, return on failure
  188 + $thumbnailer = new thumbnailGenerator();
  189 + $thumbnailer->setDocument($this->oDocument);
  190 + $thumbnailer->processDocument();
  191 + if (!file_exists($thumbnailfile)) {
  192 + return '';
  193 + }
  194 + }
  195 +
184 196 // NOTE this is to turn the config setting for the PDF directory into a proper URL and not a path
185 197 $thumbnailUrl = str_replace($default->varDirectory, 'var/', $thumbnailfile);
186 198 $oTemplate->setData(array('thumbnail' => $thumbnailUrl));
... ...