11<?php
22
33declare (strict_types=1 );
4- /**
5- * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
4+
5+ /*
6+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH
7+ * SPDX-FileContributor: Carl Schwan
68 * SPDX-License-Identifier: AGPL-3.0-or-later
79 */
810
1719use OCP \DB \Exception ;
1820use OCP \Files \AppData \IAppDataFactory ;
1921use OCP \Files \IAppData ;
20- use OCP \Files \SimpleFS \ ISimpleFile ;
22+ use OCP \Files \NotFoundException ;
2123use OCP \Files \SimpleFS \ISimpleFolder ;
2224use OCP \IAppConfig ;
2325use OCP \IDBConnection ;
@@ -42,15 +44,6 @@ public function __construct(
4244 }
4345
4446 protected function run (mixed $ argument ): void {
45- try {
46- $ this ->doRun ($ argument );
47- } catch (\Throwable $ exception ) {
48- echo $ exception ->getMessage ();
49- throw $ exception ;
50- }
51- }
52-
53- private function doRun ($ argument ): void {
5447 if ($ this ->appConfig ->getValueBool ('core ' , 'previewMovedDone ' )) {
5548 return ;
5649 }
@@ -118,8 +111,12 @@ private function doRun($argument): void {
118111 }
119112 }
120113
121- // Delete any leftover preview directory
122- $ this ->appData ->getFolder ('. ' )->delete ();
114+ try {
115+ // Delete any leftover preview directory
116+ $ this ->appData ->getFolder ('. ' )->delete ();
117+ } catch (NotFoundException ) {
118+ // ignore
119+ }
123120 $ this ->appConfig ->setValueBool ('core ' , 'previewMovedDone ' , true );
124121 }
125122
@@ -166,7 +163,7 @@ private function processPreviews(array $previewFolders, bool $simplePaths): void
166163 $ qb = $ this ->connection ->getQueryBuilder ();
167164 $ qb ->select ('* ' )
168165 ->from ('filecache ' )
169- ->where ($ qb ->expr ()->like ('fileid ' , $ qb ->createNamedParameter ($ fileId )));
166+ ->where ($ qb ->expr ()->eq ('fileid ' , $ qb ->createNamedParameter ($ fileId )));
170167
171168 $ result = $ qb ->executeQuery ();
172169 $ result = $ result ->fetchAll ();
@@ -175,13 +172,17 @@ private function processPreviews(array $previewFolders, bool $simplePaths): void
175172 foreach ($ previewFiles as $ previewFile ) {
176173 $ preview = new Preview ();
177174 $ preview ->setFileId ((int )$ fileId );
178- $ preview ->setOldFileId ($ previewFile ['file ' ]->getId ());
175+ /** @var SimpleFile $file */
176+ $ file = $ previewFile ['file ' ];
177+ $ preview ->setOldFileId ($ file ->getId ());
178+ $ preview ->setStorageId ($ result [0 ]['storage ' ]);
179179 $ preview ->setEtag ($ result [0 ]['etag ' ]);
180180 $ preview ->setMtime ($ previewFile ['mtime ' ]);
181181 $ preview ->setWidth ($ previewFile ['width ' ]);
182182 $ preview ->setHeight ($ previewFile ['height ' ]);
183- $ preview ->setCrop ($ previewFile ['crop ' ]);
184- $ preview ->setIsMax ($ previewFile ['max ' ]);
183+ $ preview ->setCropped ($ previewFile ['crop ' ]);
184+ $ preview ->setMax ($ previewFile ['max ' ]);
185+ $ preview ->setEncrypted (false );
185186 $ preview ->setMimetype (match ($ previewFile ['extension ' ]) {
186187 'png ' => IPreview::MIMETYPE_PNG ,
187188 'webp ' => IPreview::MIMETYPE_WEBP ,
0 commit comments