11<?php
2+
23/**
34 * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
45 * SPDX-License-Identifier: AGPL-3.0-or-later
2021use OCP \Preview \BeforePreviewFetchedEvent ;
2122use OCP \Preview \IProviderV2 ;
2223use OCP \Preview \IVersionedPreviewFile ;
24+ use Psr \Log \LoggerInterface ;
2325
2426class Generator {
2527 public const SEMAPHORE_ID_ALL = 0x0a11 ;
2628 public const SEMAPHORE_ID_NEW = 0x07ea ;
2729
28- /** @var IPreview */
29- private $ previewManager ;
30- /** @var IConfig */
31- private $ config ;
32- /** @var IAppData */
33- private $ appData ;
34- /** @var GeneratorHelper */
35- private $ helper ;
36- /** @var IEventDispatcher */
37- private $ eventDispatcher ;
38-
3930 public function __construct (
40- IConfig $ config ,
41- IPreview $ previewManager ,
42- IAppData $ appData ,
43- GeneratorHelper $ helper ,
44- IEventDispatcher $ eventDispatcher ,
31+ private IConfig $ config ,
32+ private IPreview $ previewManager ,
33+ private IAppData $ appData ,
34+ private GeneratorHelper $ helper ,
35+ private IEventDispatcher $ eventDispatcher ,
36+ private LoggerInterface $ logger ,
4537 ) {
46- $ this ->config = $ config ;
47- $ this ->previewManager = $ previewManager ;
48- $ this ->appData = $ appData ;
49- $ this ->helper = $ helper ;
50- $ this ->eventDispatcher = $ eventDispatcher ;
5138 }
5239
5340 /**
@@ -83,6 +70,16 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,
8370 $ mimeType ,
8471 ));
8572
73+ $ this ->logger ->debug ('Requesting preview for {path} with width={width}, height={height}, crop={crop}, mode={mode}, mimeType={mimeType} ' , [
74+ 'path ' => $ file ->getPath (),
75+ 'width ' => $ width ,
76+ 'height ' => $ height ,
77+ 'crop ' => $ crop ,
78+ 'mode ' => $ mode ,
79+ 'mimeType ' => $ mimeType ,
80+ ]);
81+
82+
8683 // since we only ask for one preview, and the generate method return the last one it created, it returns the one we want
8784 return $ this ->generatePreviews ($ file , [$ specification ], $ mimeType );
8885 }
@@ -100,6 +97,7 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,
10097 public function generatePreviews (File $ file , array $ specifications , $ mimeType = null ) {
10198 //Make sure that we can read the file
10299 if (!$ file ->isReadable ()) {
100+ $ this ->logger ->warning ('Cannot read file: {path}, skipping preview generation. ' , ['path ' => $ file ->getPath ()]);
103101 throw new NotFoundException ('Cannot read file ' );
104102 }
105103
@@ -121,6 +119,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
121119 $ maxPreviewImage = null ; // only load the image when we need it
122120 if ($ maxPreview ->getSize () === 0 ) {
123121 $ maxPreview ->delete ();
122+ $ this ->logger ->error ("Max preview generated for file {$ file ->getPath ()} has size 0, deleting and throwing exception. " );
124123 throw new NotFoundException ('Max preview size 0, invalid! ' );
125124 }
126125
@@ -167,6 +166,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
167166 $ maxPreviewImage = $ this ->helper ->getImage ($ maxPreview );
168167 }
169168
169+ $ this ->logger ->warning ('Cached preview not found for file {path}, generating a new preview. ' , ['path ' => $ file ->getPath ()]);
170170 $ preview = $ this ->generatePreview ($ previewFolder , $ maxPreviewImage , $ width , $ height , $ crop , $ maxWidth , $ maxHeight , $ previewVersion );
171171 // New file, augment our array
172172 $ previewFiles [] = $ preview ;
@@ -335,6 +335,11 @@ private function generateProviderPreview(ISimpleFolder $previewFolder, File $fil
335335 $ previewConcurrency = $ this ->getNumConcurrentPreviews ('preview_concurrency_new ' );
336336 $ sem = self ::guardWithSemaphore (self ::SEMAPHORE_ID_NEW , $ previewConcurrency );
337337 try {
338+ $ this ->logger ->debug ('Calling preview provider for {mimeType} with width={width}, height={height} ' , [
339+ 'mimeType ' => $ mimeType ,
340+ 'width ' => $ width ,
341+ 'height ' => $ height ,
342+ ]);
338343 $ preview = $ this ->helper ->getThumbnail ($ provider , $ file , $ width , $ height );
339344 } finally {
340345 self ::unguardWithSemaphore ($ sem );
@@ -558,6 +563,7 @@ private function getCachedPreview($files, $width, $height, $crop, $mimeType, $pr
558563 $ path = $ this ->generatePath ($ width , $ height , $ crop , false , $ mimeType , $ prefix );
559564 foreach ($ files as $ file ) {
560565 if ($ file ->getName () === $ path ) {
566+ $ this ->logger ->debug ('Found cached preview: {path} ' , ['path ' => $ path ]);
561567 return $ file ;
562568 }
563569 }
0 commit comments