1717use OC \Preview \Db \PreviewMapper ;
1818use OCP \DB \Exception ;
1919use OCP \Files \IMimeTypeDetector ;
20+ use OCP \Files \IMimeTypeLoader ;
2021use OCP \Files \NotFoundException ;
2122use OCP \Files \NotPermittedException ;
2223use OCP \IAppConfig ;
@@ -40,6 +41,7 @@ public function __construct(
4041 private readonly IMimeTypeDetector $ mimeTypeDetector ,
4142 private readonly LoggerInterface $ logger ,
4243 private readonly ISnowflakeGenerator $ generator ,
44+ private readonly IMimeTypeLoader $ mimeTypeLoader ,
4345 ) {
4446 $ this ->instanceId = $ this ->config ->getSystemValueString ('instanceid ' );
4547 $ this ->rootFolder = $ this ->config ->getSystemValue ('datadirectory ' , OC ::$ SERVERROOT . '/data ' );
@@ -133,9 +135,9 @@ public function scan(): int {
133135 ->setMaxResults (1 )
134136 ->runAcrossAllShards () // Unavoidable because we can't extract the storage_id from the preview name
135137 ->executeQuery ()
136- ->fetchAll ();
138+ ->fetchAssociative ();
137139
138- if (empty ( $ result) ) {
140+ if ($ result === false ) {
139141 // original file is deleted
140142 @unlink ($ file ->getRealPath ());
141143 continue ;
@@ -151,9 +153,9 @@ public function scan(): int {
151153 }
152154 }
153155
154- $ preview ->setStorageId ($ result [0 ][ 'storage ' ]);
155- $ preview ->setEtag ($ result [0 ][ 'etag ' ]);
156- $ preview ->setSourceMimetype ($ result [0 ][ 'mimetype ' ]);
156+ $ preview ->setStorageId ($ result ['storage ' ]);
157+ $ preview ->setEtag ($ result ['etag ' ]);
158+ $ preview ->setSourceMimetype ($ this -> mimeTypeLoader -> getMimetypeById ( $ result ['mimetype ' ]) );
157159 $ preview ->generateId ();
158160 // try to insert, if that fails the preview is already in the DB
159161 $ this ->previewMapper ->insert ($ preview );
0 commit comments