2828use OCP \ICacheFactory ;
2929use OCP \IL10N ;
3030use OCP \IPreview ;
31+ use Psr \Log \LoggerInterface ;
3132
3233class GeophotoService {
3334
@@ -45,6 +46,7 @@ class GeophotoService {
4546 private \OCP \ICache $ backgroundJobCache ;
4647
4748 public function __construct (
49+ private LoggerInterface $ logger ,
4850 IRootFolder $ root ,
4951 IL10N $ l10n ,
5052 GeophotoMapper $ photoMapper ,
@@ -72,11 +74,16 @@ public function __construct(
7274 * @return bool
7375 */
7476 public function clearCache (string $ userId = '' ): bool {
75- $ a = $ this ->photosCache ->clear ($ userId );
76- $ b = $ this ->timeOrderedPointSetsCache ->clear ($ userId );
77- $ c = $ this ->backgroundJobCache ->clear ('recentlyAdded: ' .$ userId );
78- $ d = $ this ->backgroundJobCache ->clear ('recentlyUpdated: ' .$ userId );
79- return $ a and $ b and $ c and $ d ;
77+ try {
78+ $ this ->photosCache ->clear ($ userId );
79+ $ this ->timeOrderedPointSetsCache ->clear ($ userId );
80+ $ this ->backgroundJobCache ->clear ('recentlyAdded: ' .$ userId );
81+ $ this ->backgroundJobCache ->clear ('recentlyUpdated: ' .$ userId );
82+ return true ;
83+
84+ } catch (\Exception $ e ) {
85+ return false ;
86+ }
8087 }
8188
8289 /**
@@ -106,56 +113,53 @@ public function getAll(string $userId, $folder = null, bool $respectNomediaAndNo
106113 $ photoEntities = $ this ->photoMapper ->findAll ($ userId );
107114
108115 $ filesById = [];
109- $ cache = $ folder ->getStorage ()->getCache ();
110116 $ previewEnableMimetypes = $ this ->getPreviewEnabledMimetypes ();
111117 foreach ($ photoEntities as $ photoEntity ) {
112- $ cacheEntry = $ cache ->get ($ photoEntity ->getFileId ());
113- if ($ cacheEntry ) {
114- // this path is relative to owner's storage
115- //$path = $cacheEntry->getPath();
116- //but we want it relative to current user's storage
117- $ files = $ folder ->getById ($ photoEntity ->getFileId ());
118- if (empty ($ files )) {
119- continue ;
120- }
121- $ file = array_shift ($ files );
122- if ($ file === null ) {
123- continue ;
124- }
125- $ path = $ userFolder ->getRelativePath ($ file ->getPath ());
126- $ isIgnored = false ;
127- foreach ($ ignoredPaths as $ ignoredPath ) {
128- if (str_starts_with ($ path , $ ignoredPath )) {
129- $ isIgnored = true ;
130- break ;
131- }
118+ // this path is relative to owner's storage
119+ //$path = $cacheEntry->getPath();
120+ //but we want it relative to current user's storage
121+ $ files = $ folder ->getById ($ photoEntity ->getFileId ());
122+ if (empty ($ files )) {
123+ continue ;
124+ }
125+ $ file = array_shift ($ files );
126+
127+ if ($ file === null ) {
128+ continue ;
129+ }
130+ $ path = $ userFolder ->getRelativePath ($ file ->getPath ());
131+ $ isIgnored = false ;
132+ foreach ($ ignoredPaths as $ ignoredPath ) {
133+ if (str_starts_with ($ path , $ ignoredPath )) {
134+ $ isIgnored = true ;
135+ break ;
132136 }
133- if (!$ isIgnored ) {
134- $ isRoot = $ file === $ userFolder ;
137+ }
138+ if (!$ isIgnored ) {
139+ $ isRoot = $ file === $ userFolder ;
135140
136- $ file_object = new \stdClass ();
137- $ file_object ->fileId = $ photoEntity ->getFileId ();
138- $ file_object ->fileid = $ file_object ->fileId ;
139- $ file_object ->lat = $ photoEntity ->getLat ();
140- $ file_object ->lng = $ photoEntity ->getLng ();
141- $ file_object ->dateTaken = $ photoEntity ->getDateTaken () ?? \time ();
142- $ file_object ->basename = $ isRoot ? '' : $ file ->getName ();
143- $ file_object ->filename = $ this ->normalizePath ($ path );
144- $ file_object ->etag = $ cacheEntry ->getEtag ();
145- //Not working for NC21 as Viewer requires String representation of permissions
146- // $file_object->permissions = $file->getPermissions();
147- $ file_object ->type = $ file ->getType ();
148- $ file_object ->mime = $ file ->getMimetype ();
149- $ file_object ->lastmod = $ file ->getMTime ();
150- $ file_object ->size = $ file ->getSize ();
151- $ file_object ->path = $ path ;
152- $ file_object ->isReadable = $ file ->isReadable ();
153- $ file_object ->isUpdateable = $ file ->isUpdateable ();
154- $ file_object ->isShareable = $ file ->isShareable ();
155- $ file_object ->isDeletable = $ file ->isDeletable ();
156- $ file_object ->hasPreview = in_array ($ cacheEntry ->getMimeType (), $ previewEnableMimetypes );
157- $ filesById [] = $ file_object ;
158- }
141+ $ file_object = new \stdClass ();
142+ $ file_object ->fileId = $ photoEntity ->getFileId ();
143+ $ file_object ->fileid = $ file_object ->fileId ;
144+ $ file_object ->lat = $ photoEntity ->getLat ();
145+ $ file_object ->lng = $ photoEntity ->getLng ();
146+ $ file_object ->dateTaken = $ photoEntity ->getDateTaken () ?? \time ();
147+ $ file_object ->basename = $ isRoot ? '' : $ file ->getName ();
148+ $ file_object ->filename = $ this ->normalizePath ($ path );
149+ $ file_object ->etag = $ file ->getEtag ();
150+ //Not working for NC21 as Viewer requires String representation of permissions
151+ // $file_object->permissions = $file->getPermissions();
152+ $ file_object ->type = $ file ->getType ();
153+ $ file_object ->mime = $ file ->getMimetype ();
154+ $ file_object ->lastmod = $ file ->getMTime ();
155+ $ file_object ->size = $ file ->getSize ();
156+ $ file_object ->path = $ path ;
157+ $ file_object ->isReadable = $ file ->isReadable ();
158+ $ file_object ->isUpdateable = $ file ->isUpdateable ();
159+ $ file_object ->isShareable = $ file ->isShareable ();
160+ $ file_object ->isDeletable = $ file ->isDeletable ();
161+ $ file_object ->hasPreview = in_array ($ file_object ->mime , $ previewEnableMimetypes );
162+ $ filesById [] = $ file_object ;
159163 }
160164 }
161165 $ this ->photosCache ->set ($ key , $ filesById , 60 * 60 * 24 );
@@ -199,65 +203,61 @@ public function getNonLocalized(string $userId, $folder = null, bool $respectNom
199203 $ tz = new \DateTimeZone (\date_default_timezone_get ());
200204 }
201205 foreach ($ photoEntities as $ photoEntity ) {
202- $ cacheEntry = $ cache ->get ($ photoEntity ->getFileId ());
203- if ($ cacheEntry ) {
204- // this path is relative to owner's storage
205- //$path = $cacheEntry->getPath();
206- // but we want it relative to current user's storage
207- $ files = $ folder ->getById ($ photoEntity ->getFileId ());
208- if (empty ($ files )) {
209- continue ;
210- }
211- $ file = array_shift ($ files );
212- if ($ file === null ) {
213- continue ;
214- }
215- $ path = $ userFolder ->getRelativePath ($ file ->getPath ());
216- $ isIgnored = false ;
217- foreach ($ ignoredPaths as $ ignoredPath ) {
218- if (str_starts_with ($ path , $ ignoredPath )) {
219- $ isIgnored = true ;
220- break ;
221- }
206+ // this path is relative to owner's storage
207+ //$path = $cacheEntry->getPath();
208+ // but we want it relative to current user's storage
209+ $ files = $ folder ->getById ($ photoEntity ->getFileId ());
210+ if (empty ($ files )) {
211+ continue ;
212+ }
213+ $ file = array_shift ($ files );
214+ if ($ file === null ) {
215+ continue ;
216+ }
217+ $ path = $ userFolder ->getRelativePath ($ file ->getPath ());
218+ $ isIgnored = false ;
219+ foreach ($ ignoredPaths as $ ignoredPath ) {
220+ if (str_starts_with ($ path , $ ignoredPath )) {
221+ $ isIgnored = true ;
222+ break ;
222223 }
223- if (!$ isIgnored ) {
224- $ isRoot = $ file === $ userFolder ;
224+ }
225+ if (!$ isIgnored ) {
226+ $ isRoot = $ file === $ userFolder ;
225227
226- //Unfortunately Exif stores the local and not the UTC time. There is no way to get the timezone, therefore it has to be given by the user.
227- $ date = $ photoEntity ->getDateTaken () ?? \time ();
228+ //Unfortunately Exif stores the local and not the UTC time. There is no way to get the timezone, therefore it has to be given by the user.
229+ $ date = $ photoEntity ->getDateTaken () ?? \time ();
228230
229- $ dateWithTimezone = new \DateTime (gmdate ('Y-m-d H:i:s ' , $ date ), $ tz );
230- $ locations = $ this ->getLocationGuesses ($ dateWithTimezone ->getTimestamp ());
231- foreach ($ locations as $ key => $ location ) {
232- $ file_object = new \stdClass ();
233- $ file_object ->fileId = $ photoEntity ->getFileId ();
234- $ file_object ->fileid = $ file_object ->fileId ;
235- $ file_object ->path = $ this ->normalizePath ($ path );
236- $ file_object ->hasPreview = in_array ($ cacheEntry ->getMimeType (), $ previewEnableMimetypes );
237- $ file_object ->lat = $ location [0 ];
238- $ file_object ->lng = $ location [1 ];
239- $ file_object ->dateTaken = $ date ;
240- $ file_object ->basename = $ isRoot ? '' : $ file ->getName ();
241- $ file_object ->filename = $ this ->normalizePath ($ path );
242- $ file_object ->etag = $ cacheEntry ->getEtag ();
243- //Not working for NC21 as Viewer requires String representation of permissions
244- // $file_object->permissions = $file->getPermissions();
245- $ file_object ->type = $ file ->getType ();
246- $ file_object ->mime = $ file ->getMimetype ();
247- $ file_object ->lastmod = $ file ->getMTime ();
248- $ file_object ->size = $ file ->getSize ();
249- $ file_object ->path = $ path ;
250- $ file_object ->isReadable = $ file ->isReadable ();
251- $ file_object ->isUpdateable = $ file ->isUpdateable ();
252- $ file_object ->isShareable = $ file ->isShareable ();
253- $ file_object ->isDeletable = $ file ->isDeletable ();
254- $ file_object ->hasPreview = in_array ($ cacheEntry ->getMimeType (), $ previewEnableMimetypes );
255- $ file_object ->trackOrDeviceId = $ key ;
256- if (!array_key_exists ($ key , $ suggestionsBySource )) {
257- $ suggestionsBySource [$ key ] = [];
258- }
259- $ suggestionsBySource [$ key ][] = $ file_object ;
231+ $ dateWithTimezone = new \DateTime (gmdate ('Y-m-d H:i:s ' , $ date ), $ tz );
232+ $ locations = $ this ->getLocationGuesses ($ dateWithTimezone ->getTimestamp ());
233+ foreach ($ locations as $ key => $ location ) {
234+ $ file_object = new \stdClass ();
235+ $ file_object ->fileId = $ photoEntity ->getFileId ();
236+ $ file_object ->fileid = $ file_object ->fileId ;
237+ $ file_object ->path = $ this ->normalizePath ($ path );
238+ $ file_object ->mime = $ file ->getMimetype ();
239+ $ file_object ->hasPreview = in_array ($ file_object ->mime , $ previewEnableMimetypes );
240+ $ file_object ->lat = $ location [0 ];
241+ $ file_object ->lng = $ location [1 ];
242+ $ file_object ->dateTaken = $ date ;
243+ $ file_object ->basename = $ isRoot ? '' : $ file ->getName ();
244+ $ file_object ->filename = $ this ->normalizePath ($ path );
245+ $ file_object ->etag = $ file ->getEtag ();
246+ //Not working for NC21 as Viewer requires String representation of permissions
247+ // $file_object->permissions = $file->getPermissions();
248+ $ file_object ->type = $ file ->getType ();
249+ $ file_object ->lastmod = $ file ->getMTime ();
250+ $ file_object ->size = $ file ->getSize ();
251+ $ file_object ->path = $ path ;
252+ $ file_object ->isReadable = $ file ->isReadable ();
253+ $ file_object ->isUpdateable = $ file ->isUpdateable ();
254+ $ file_object ->isShareable = $ file ->isShareable ();
255+ $ file_object ->isDeletable = $ file ->isDeletable ();
256+ $ file_object ->trackOrDeviceId = $ key ;
257+ if (!array_key_exists ($ key , $ suggestionsBySource )) {
258+ $ suggestionsBySource [$ key ] = [];
260259 }
260+ $ suggestionsBySource [$ key ][] = $ file_object ;
261261 }
262262 }
263263 }
@@ -357,6 +357,7 @@ private function loadTimeorderedPointSets(string $userId, $folder = null, bool $
357357 */
358358 private function getTracksFromGPX ($ content ): array {
359359 $ tracks = [];
360+ libxml_use_internal_errors (false );
360361 $ gpx = simplexml_load_string ($ content );
361362 foreach ($ gpx ->trk as $ trk ) {
362363 $ tracks [] = $ trk ;
0 commit comments