@@ -64,18 +64,18 @@ protected function configure() {
6464 protected function execute (InputInterface $ input , OutputInterface $ output ): int {
6565 $ oldOnly = $ input ->getOption ('old-only ' );
6666
67- $ selectedMimetype = $ input ->getOption ('mimetype ' );
68- if ($ selectedMimetype ) {
69- if ($ oldOnly ) {
70- $ output ->writeln ('Mimetype of absent original files cannot be determined. Aborting... ' );
71- return 0 ;
72- } else {
73- if (! $ this ->mimeTypeLoader ->exists ($ selectedMimetype )) {
74- $ output ->writeln ('Mimetype ' . $ selectedMimetype . ' does not exist in database. Aborting... ' );
75- return 0 ;
76- }
77- }
78- }
67+ $ selectedMimetype = $ input ->getOption ('mimetype ' );
68+ if ($ selectedMimetype ) {
69+ if ($ oldOnly ) {
70+ $ output ->writeln ('Mimetype of absent original files cannot be determined. Aborting... ' );
71+ return 0 ;
72+ } else {
73+ if (! $ this ->mimeTypeLoader ->exists ($ selectedMimetype )) {
74+ $ output ->writeln ('Mimetype ' . $ selectedMimetype . ' does not exist in database. Aborting... ' );
75+ return 0 ;
76+ }
77+ }
78+ }
7979
8080 $ dryMode = $ input ->getOption ('dry ' );
8181 if ($ dryMode ) {
@@ -92,11 +92,11 @@ private function deletePreviews(OutputInterface $output, bool $oldOnly, string $
9292 $ previewFoldersToDeleteCount = 0 ;
9393
9494 foreach ($ this ->getPreviewsToDelete ($ output , $ oldOnly , $ selectedMimetype ) as ['name ' => $ previewFileId , 'path ' => $ filePath ]) {
95- if ($ oldOnly || $ filePath === null ) {
96- $ output ->writeln ('Deleting previews of absent original file (fileid: ' . $ previewFileId . ') ' , OutputInterface::VERBOSITY_VERBOSE );
97- } else {
98- $ output ->writeln ('Deleting previews of original file ' . substr ($ filePath , 7 ) . ' (fileid: ' . $ previewFileId . ') ' , OutputInterface::VERBOSITY_VERBOSE );
99- }
95+ if ($ oldOnly || $ filePath === null ) {
96+ $ output ->writeln ('Deleting previews of absent original file (fileid: ' . $ previewFileId . ') ' , OutputInterface::VERBOSITY_VERBOSE );
97+ } else {
98+ $ output ->writeln ('Deleting previews of original file ' . substr ($ filePath , 7 ) . ' (fileid: ' . $ previewFileId . ') ' , OutputInterface::VERBOSITY_VERBOSE );
99+ }
100100
101101 $ previewFoldersToDeleteCount ++;
102102
@@ -120,42 +120,42 @@ private function deletePreviews(OutputInterface $output, bool $oldOnly, string $
120120 // Copy pasted and adjusted from
121121 // "lib/private/Preview/BackgroundCleanupJob.php".
122122 private function getPreviewsToDelete (OutputInterface $ output , bool $ oldOnly , string $ selectedMimetype = null ): \Iterator {
123- // Get preview folder
124- $ qb = $ this ->connection ->getQueryBuilder ();
125- $ qb ->select ('path ' , 'mimetype ' )
126- ->from ('filecache ' )
127- ->where ($ qb ->expr ()->eq ('fileid ' , $ qb ->createNamedParameter ($ this ->previewFolder ->getId ())));
128- $ cursor = $ qb ->execute ();
129- $ data = $ cursor ->fetch ();
130- $ cursor ->closeCursor ();
123+ // Get preview folder
124+ $ qb = $ this ->connection ->getQueryBuilder ();
125+ $ qb ->select ('path ' , 'mimetype ' )
126+ ->from ('filecache ' )
127+ ->where ($ qb ->expr ()->eq ('fileid ' , $ qb ->createNamedParameter ($ this ->previewFolder ->getId ())));
128+ $ cursor = $ qb ->execute ();
129+ $ data = $ cursor ->fetch ();
130+ $ cursor ->closeCursor ();
131131
132- $ output ->writeln ('Preview folder: ' . $ data ['path ' ], OutputInterface::VERBOSITY_VERBOSE );
132+ $ output ->writeln ('Preview folder: ' . $ data ['path ' ], OutputInterface::VERBOSITY_VERBOSE );
133133
134- if ($ data === null ) {
135- return [];
136- }
134+ if ($ data === null ) {
135+ return [];
136+ }
137137
138- // Get previews to delete
139- // Initialize Query Builder
140- $ qb = $ this ->connection ->getQueryBuilder ();
138+ // Get previews to delete
139+ // Initialize Query Builder
140+ $ qb = $ this ->connection ->getQueryBuilder ();
141141
142142 /* This lovely like is the result of the way the new previews are stored
143143 * We take the md5 of the name (fileid) and split the first 7 chars. That way
144144 * there are not a gazillion files in the root of the preview appdata.*/
145145 $ like = $ this ->connection ->escapeLikeParameter ($ data ['path ' ]) . '/_/_/_/_/_/_/_/% ' ;
146146
147- // Specify conditions based on options
148- $ and = $ qb ->expr ()->andX ();
149- $ and ->add ($ qb ->expr ()->like ('a.path ' , $ qb ->createNamedParameter ($ like )));
150- $ and ->add ($ qb ->expr ()->eq ('a.mimetype ' , $ qb ->createNamedParameter ($ this ->mimeTypeLoader ->getId ('httpd/unix-directory ' ))));
151- if ($ oldOnly ) {
152- $ and ->add ($ qb ->expr ()->isNull ('b.fileid ' ));
153- }
154- if ($ selectedMimetype ) {
155- $ and ->add ($ qb ->expr ()->eq ('b.mimetype ' , $ qb ->createNamedParameter ($ this ->mimeTypeLoader ->getId ('image/jpeg ' ))));
156- }
157-
158- // Build query
147+ // Specify conditions based on options
148+ $ and = $ qb ->expr ()->andX ();
149+ $ and ->add ($ qb ->expr ()->like ('a.path ' , $ qb ->createNamedParameter ($ like )));
150+ $ and ->add ($ qb ->expr ()->eq ('a.mimetype ' , $ qb ->createNamedParameter ($ this ->mimeTypeLoader ->getId ('httpd/unix-directory ' ))));
151+ if ($ oldOnly ) {
152+ $ and ->add ($ qb ->expr ()->isNull ('b.fileid ' ));
153+ }
154+ if ($ selectedMimetype ) {
155+ $ and ->add ($ qb ->expr ()->eq ('b.mimetype ' , $ qb ->createNamedParameter ($ this ->mimeTypeLoader ->getId ('image/jpeg ' ))));
156+ }
157+
158+ // Build query
159159 $ qb ->select ('a.name ' , 'b.path ' )
160160 ->from ('filecache ' , 'a ' )
161161 ->leftJoin ('a ' , 'filecache ' , 'b ' , $ qb ->expr ()->eq (
0 commit comments