@@ -66,14 +66,13 @@ public function __construct(IConfig $config,
6666 IURLGenerator $ urlGenerator ,
6767 ICacheFactory $ cacheFactory ,
6868 ILogger $ logger ,
69- ITempManager $ tempManager
70- ) {
69+ ITempManager $ tempManager ) {
7170 $ this ->config = $ config ;
72- $ this ->appData = $ appData ;
7371 $ this ->urlGenerator = $ urlGenerator ;
7472 $ this ->cacheFactory = $ cacheFactory ;
7573 $ this ->logger = $ logger ;
7674 $ this ->tempManager = $ tempManager ;
75+ $ this ->appData = $ appData ;
7776 }
7877
7978 public function getImageUrl (string $ key , bool $ useSvg = true ): string {
@@ -106,7 +105,7 @@ public function getImageUrlAbsolute(string $key, bool $useSvg = true): string {
106105 */
107106 public function getImage (string $ key , bool $ useSvg = true ): ISimpleFile {
108107 $ logo = $ this ->config ->getAppValue ('theming ' , $ key . 'Mime ' , '' );
109- $ folder = $ this ->appData ->getFolder ('images ' );
108+ $ folder = $ this ->getRootFolder () ->getFolder ('images ' );
110109 if ($ logo === '' || !$ folder ->fileExists ($ key )) {
111110 throw new NotFoundException ();
112111 }
@@ -158,9 +157,9 @@ public function getCustomImages(): array {
158157 public function getCacheFolder (): ISimpleFolder {
159158 $ cacheBusterValue = $ this ->config ->getAppValue ('theming ' , 'cachebuster ' , '0 ' );
160159 try {
161- $ folder = $ this ->appData ->getFolder ($ cacheBusterValue );
160+ $ folder = $ this ->getRootFolder () ->getFolder ($ cacheBusterValue );
162161 } catch (NotFoundException $ e ) {
163- $ folder = $ this ->appData ->newFolder ($ cacheBusterValue );
162+ $ folder = $ this ->getRootFolder () ->newFolder ($ cacheBusterValue );
164163 $ this ->cleanup ();
165164 }
166165 return $ folder ;
@@ -202,13 +201,13 @@ public function setCachedImage(string $filename, string $data): ISimpleFile {
202201 public function delete (string $ key ): void {
203202 /* ignore exceptions, since we don't want to fail hard if something goes wrong during cleanup */
204203 try {
205- $ file = $ this ->appData ->getFolder ('images ' )->getFile ($ key );
204+ $ file = $ this ->getRootFolder () ->getFolder ('images ' )->getFile ($ key );
206205 $ file ->delete ();
207206 } catch (NotFoundException $ e ) {
208207 } catch (NotPermittedException $ e ) {
209208 }
210209 try {
211- $ file = $ this ->appData ->getFolder ('images ' )->getFile ($ key . '.png ' );
210+ $ file = $ this ->getRootFolder () ->getFolder ('images ' )->getFile ($ key . '.png ' );
212211 $ file ->delete ();
213212 } catch (NotFoundException $ e ) {
214213 } catch (NotPermittedException $ e ) {
@@ -219,9 +218,9 @@ public function updateImage(string $key, string $tmpFile): string {
219218 $ this ->delete ($ key );
220219
221220 try {
222- $ folder = $ this ->appData ->getFolder ('images ' );
221+ $ folder = $ this ->getRootFolder () ->getFolder ('images ' );
223222 } catch (NotFoundException $ e ) {
224- $ folder = $ this ->appData ->newFolder ('images ' );
223+ $ folder = $ this ->getRootFolder () ->newFolder ('images ' );
225224 }
226225
227226 $ target = $ folder ->newFile ($ key );
@@ -288,7 +287,7 @@ private function getSupportedUploadImageFormats(string $key): array {
288287 */
289288 public function cleanup () {
290289 $ currentFolder = $ this ->getCacheFolder ();
291- $ folders = $ this ->appData ->getDirectoryListing ();
290+ $ folders = $ this ->getRootFolder () ->getDirectoryListing ();
292291 foreach ($ folders as $ folder ) {
293292 if ($ folder ->getName () !== 'images ' && $ folder ->getName () !== $ currentFolder ->getName ()) {
294293 $ folder ->delete ();
@@ -316,4 +315,12 @@ public function shouldReplaceIcons() {
316315 $ cache ->set ('shouldReplaceIcons ' , $ value );
317316 return $ value ;
318317 }
318+
319+ private function getRootFolder (): ISimpleFolder {
320+ try {
321+ return $ this ->appData ->getFolder ('global ' );
322+ } catch (NotFoundException $ e ) {
323+ return $ this ->appData ->newFolder ('global ' );
324+ }
325+ }
319326}
0 commit comments