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 ,
@@ -106,56 +108,53 @@ public function getAll(string $userId, $folder = null, bool $respectNomediaAndNo
106108 $ photoEntities = $ this ->photoMapper ->findAll ($ userId );
107109
108110 $ filesById = [];
109- $ cache = $ folder ->getStorage ()->getCache ();
110111 $ previewEnableMimetypes = $ this ->getPreviewEnabledMimetypes ();
111112 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- }
113+ // this path is relative to owner's storage
114+ //$path = $cacheEntry->getPath();
115+ //but we want it relative to current user's storage
116+ $ files = $ folder ->getById ($ photoEntity ->getFileId ());
117+ if (empty ($ files )) {
118+ continue ;
119+ }
120+ $ file = array_shift ($ files );
121+
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 ;
132131 }
133- if (!$ isIgnored ) {
134- $ isRoot = $ file === $ userFolder ;
132+ }
133+ if (!$ isIgnored ) {
134+ $ isRoot = $ file === $ userFolder ;
135135
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- }
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 = $ file ->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 ($ file_object ->mime , $ previewEnableMimetypes );
157+ $ filesById [] = $ file_object ;
159158 }
160159 }
161160 $ this ->photosCache ->set ($ key , $ filesById , 60 * 60 * 24 );
@@ -199,65 +198,61 @@ public function getNonLocalized(string $userId, $folder = null, bool $respectNom
199198 $ tz = new \DateTimeZone (\date_default_timezone_get ());
200199 }
201200 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- }
201+ // this path is relative to owner's storage
202+ //$path = $cacheEntry->getPath();
203+ // but we want it relative to current user's storage
204+ $ files = $ folder ->getById ($ photoEntity ->getFileId ());
205+ if (empty ($ files )) {
206+ continue ;
207+ }
208+ $ file = array_shift ($ files );
209+ if ($ file === null ) {
210+ continue ;
211+ }
212+ $ path = $ userFolder ->getRelativePath ($ file ->getPath ());
213+ $ isIgnored = false ;
214+ foreach ($ ignoredPaths as $ ignoredPath ) {
215+ if (str_starts_with ($ path , $ ignoredPath )) {
216+ $ isIgnored = true ;
217+ break ;
222218 }
223- if (!$ isIgnored ) {
224- $ isRoot = $ file === $ userFolder ;
219+ }
220+ if (!$ isIgnored ) {
221+ $ isRoot = $ file === $ userFolder ;
225222
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 ();
223+ //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.
224+ $ date = $ photoEntity ->getDateTaken () ?? \time ();
228225
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 ;
226+ $ dateWithTimezone = new \DateTime (gmdate ('Y-m-d H:i:s ' , $ date ), $ tz );
227+ $ locations = $ this ->getLocationGuesses ($ dateWithTimezone ->getTimestamp ());
228+ foreach ($ locations as $ key => $ location ) {
229+ $ file_object = new \stdClass ();
230+ $ file_object ->fileId = $ photoEntity ->getFileId ();
231+ $ file_object ->fileid = $ file_object ->fileId ;
232+ $ file_object ->path = $ this ->normalizePath ($ path );
233+ $ file_object ->mime = $ file ->getMimetype ();
234+ $ file_object ->hasPreview = in_array ($ file_object ->mime , $ previewEnableMimetypes );
235+ $ file_object ->lat = $ location [0 ];
236+ $ file_object ->lng = $ location [1 ];
237+ $ file_object ->dateTaken = $ date ;
238+ $ file_object ->basename = $ isRoot ? '' : $ file ->getName ();
239+ $ file_object ->filename = $ this ->normalizePath ($ path );
240+ $ file_object ->etag = $ file ->getEtag ();
241+ //Not working for NC21 as Viewer requires String representation of permissions
242+ // $file_object->permissions = $file->getPermissions();
243+ $ file_object ->type = $ file ->getType ();
244+ $ file_object ->lastmod = $ file ->getMTime ();
245+ $ file_object ->size = $ file ->getSize ();
246+ $ file_object ->path = $ path ;
247+ $ file_object ->isReadable = $ file ->isReadable ();
248+ $ file_object ->isUpdateable = $ file ->isUpdateable ();
249+ $ file_object ->isShareable = $ file ->isShareable ();
250+ $ file_object ->isDeletable = $ file ->isDeletable ();
251+ $ file_object ->trackOrDeviceId = $ key ;
252+ if (!array_key_exists ($ key , $ suggestionsBySource )) {
253+ $ suggestionsBySource [$ key ] = [];
260254 }
255+ $ suggestionsBySource [$ key ][] = $ file_object ;
261256 }
262257 }
263258 }
@@ -357,6 +352,7 @@ private function loadTimeorderedPointSets(string $userId, $folder = null, bool $
357352 */
358353 private function getTracksFromGPX ($ content ): array {
359354 $ tracks = [];
355+ libxml_use_internal_errors (false );
360356 $ gpx = simplexml_load_string ($ content );
361357 foreach ($ gpx ->trk as $ trk ) {
362358 $ tracks [] = $ trk ;
0 commit comments