diff --git a/lib/DB/Place/PlaceMapper.php b/lib/DB/Place/PlaceMapper.php index b3d7feb82..4c8248f5c 100644 --- a/lib/DB/Place/PlaceMapper.php +++ b/lib/DB/Place/PlaceMapper.php @@ -154,9 +154,4 @@ public function findFileForUserAndPlace(string $userId, string $place, string $f $rows[0]['meta_value_string'] ); } - - public function setPlaceForFile(string $place, int $fileId): void { - $metadata = $this->filesMetadataManager->getMetadata($fileId, true); - $metadata->setString('gps', $place, true); - } } diff --git a/lib/Listener/PlaceMetadataProvider.php b/lib/Listener/PlaceMetadataProvider.php index ca0046de4..29b15d95c 100644 --- a/lib/Listener/PlaceMetadataProvider.php +++ b/lib/Listener/PlaceMetadataProvider.php @@ -42,7 +42,7 @@ public function handle(Event $event): void { if ($event instanceof MetadataBackgroundEvent) { $metadata = $event->getMetadata(); - $place = $this->mediaPlaceManager->getPlaceForFile($event->getNode()->getId()); + $place = $this->mediaPlaceManager->getPlaceForMetadata($metadata); if ($place !== null) { $metadata->setString('photos-place', $place, true); } diff --git a/lib/Service/MediaPlaceManager.php b/lib/Service/MediaPlaceManager.php index 3013b552d..5bc1f6076 100644 --- a/lib/Service/MediaPlaceManager.php +++ b/lib/Service/MediaPlaceManager.php @@ -9,8 +9,8 @@ namespace OCA\Photos\Service; use OCA\Photos\DB\Place\PlaceMapper; -use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException; use OCP\FilesMetadata\IFilesMetadataManager; +use OCP\FilesMetadata\Model\IFilesMetadata; class MediaPlaceManager { public function __construct( @@ -21,22 +21,17 @@ public function __construct( } public function setPlaceForFile(int $fileId): void { - $place = $this->getPlaceForFile($fileId); + $metadata = $this->filesMetadataManager->getMetadata($fileId, true); + $place = $this->getPlaceForMetadata($metadata); if ($place === null) { return; } - $this->placeMapper->setPlaceForFile($place, $fileId); + $metadata->setString('gps', $place, true); } - public function getPlaceForFile(int $fileId): ?string { - try { - $metadata = $this->filesMetadataManager->getMetadata($fileId, true); - } catch (FilesMetadataNotFoundException) { - return null; - } - + public function getPlaceForMetadata(IFilesMetadata $metadata): ?string { if (!$this->rgcService->arePlacesEnabled() || !$metadata->hasKey('photos-gps')) { return null; }