@@ -136,19 +136,19 @@ class BackgroundService {
136136 private string $ userId ;
137137 private IAppDataFactory $ appDataFactory ;
138138
139- public function __construct (
140- IRootFolder $ rootFolder ,
141- IAppDataFactory $ appDataFactory ,
142- IConfig $ config ,
143- ?string $ userId
144- ) {
139+ public function __construct (IRootFolder $ rootFolder ,
140+ IAppData $ appData ,
141+ IConfig $ config ,
142+ ?string $ userId ,
143+ IAppDataFactory $ appDataFactory ) {
145144 if ($ userId === null ) {
146145 return ;
147146 }
147+
148148 $ this ->rootFolder = $ rootFolder ;
149- $ this ->appData = $ appDataFactory ->get (Application::APP_ID );
150149 $ this ->config = $ config ;
151150 $ this ->userId = $ userId ;
151+ $ this ->appData = $ appData ;
152152 $ this ->appDataFactory = $ appDataFactory ;
153153 }
154154
@@ -167,12 +167,15 @@ public function setDefaultBackground(): void {
167167 public function setFileBackground ($ path ): void {
168168 $ this ->config ->setUserValue ($ this ->userId , Application::APP_ID , 'background ' , 'custom ' );
169169 $ userFolder = $ this ->rootFolder ->getUserFolder ($ this ->userId );
170+
170171 /** @var File $file */
171172 $ file = $ userFolder ->get ($ path );
172173 $ image = new \OCP \Image ();
174+
173175 if ($ image ->loadFromFileHandle ($ file ->fopen ('r ' )) === false ) {
174176 throw new InvalidArgumentException ('Invalid image file ' );
175177 }
178+
176179 $ this ->getAppDataFolder ()->newFile ('background.jpg ' , $ file ->fopen ('r ' ));
177180 }
178181
@@ -207,14 +210,21 @@ public function getBackground(): ?ISimpleFile {
207210 }
208211
209212 /**
213+ * Storing the data in appdata/theming/users/USERID
214+ *
210215 * @return ISimpleFolder
211216 * @throws NotPermittedException
212217 */
213218 private function getAppDataFolder (): ISimpleFolder {
214219 try {
215- return $ this ->appData ->getFolder ($ this ->userId );
220+ $ rootFolder = $ this ->appData ->getFolder ('users ' );
221+ } catch (NotFoundException $ e ) {
222+ $ rootFolder = $ this ->appData ->newFolder ('users ' );
223+ }
224+ try {
225+ return $ rootFolder ->getFolder ($ this ->userId );
216226 } catch (NotFoundException $ e ) {
217- return $ this -> appData ->newFolder ($ this ->userId );
227+ return $ rootFolder ->newFolder ($ this ->userId );
218228 }
219229 }
220230}
0 commit comments