diff options
author | Julien Veyssier <eneiluj@posteo.net> | 2020-11-24 03:35:23 +0300 |
---|---|---|
committer | Julien Veyssier <eneiluj@posteo.net> | 2021-07-06 13:43:19 +0300 |
commit | 067e598aec444d3fd37d76c8267805070e50fa4a (patch) | |
tree | 925cc1f13bc3a7ecca17bc01881f27d428a9be42 /lib | |
parent | 7872f036b2efc8122ee1fa23eaa640102f99b7a5 (diff) |
implement photo move/reset action history
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Service/PhotofilesService.php | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/lib/Service/PhotofilesService.php b/lib/Service/PhotofilesService.php index 851e8d16..d7b491c7 100644 --- a/lib/Service/PhotofilesService.php +++ b/lib/Service/PhotofilesService.php @@ -197,7 +197,7 @@ class PhotofilesService { $lat = $lats[0] ?? 0; $lng = $lngs[0] ?? 0; $userFolder = $this->root->getUserFolder($userId); - $nbDone = 0; + $done = []; foreach ($paths as $dirPath) { $cleanDirPath = str_replace(array('../', '..\\'), '', $dirPath); if ($userFolder->nodeExists($cleanDirPath)) { @@ -206,53 +206,74 @@ class PhotofilesService { $nodes = $dir->getDirectoryListing(); foreach($nodes as $node) { if ($this->isPhoto($node) && $node->isUpdateable()) { + $photo = $this->photoMapper->findByFileId($userId, $node->getId()); + $done[] = [ + 'path' => preg_replace('/^files/', '', $node->getInternalPath()), + 'lat' => $lat, + 'lng' => $lng, + 'oldLat' => $photo ? $photo->getLat() : null, + 'oldLng' => $photo ? $photo->getLng() : null, + ]; $this->setExifCoords($node, $lat, $lng); $this->updateByFileNow($node); - $nbDone++; } } } } } - return $nbDone; + return $done; } private function setFilesCoords($userId, $paths, $lats, $lngs) { $userFolder = $this->root->getUserFolder($userId); - $nbDone = 0; + $done = []; foreach ($paths as $i => $path) { $cleanpath = str_replace(array('../', '..\\'), '', $path); if ($userFolder->nodeExists($cleanpath)) { $file = $userFolder->get($cleanpath); - if ($this->isPhoto($file) and $file->isUpdateable()) { + if ($this->isPhoto($file) && $file->isUpdateable()) { $lat = (count($lats) > $i) ? $lats[$i] : $lats[0]; $lng = (count($lngs) > $i) ? $lngs[$i] : $lngs[0]; + $photo = $this->photoMapper->findByFileId($userId, $file->getId()); + $done[] = [ + 'path' => preg_replace('/^files/', '', $file->getInternalPath()), + 'lat' => $lat, + 'lng' => $lng, + 'oldLat' => $photo ? $photo->getLat() : null, + 'oldLng' => $photo ? $photo->getLng() : null, + ]; $this->setExifCoords($file, $lat, $lng); $this->updateByFileNow($file); - $nbDone++; } } } - return $nbDone; + return $done; } public function resetPhotosFilesCoords($userId, $paths) { $userFolder = $this->root->getUserFolder($userId); - $nbDone = 0; + $done = []; foreach ($paths as $i => $path) { $cleanpath = str_replace(array('../', '..\\'), '', $path); if ($userFolder->nodeExists($cleanpath)) { $file = $userFolder->get($cleanpath); if ($this->isPhoto($file) && $file->isUpdateable()) { + $photo = $this->photoMapper->findByFileId($userId, $file->getId()); + $done[] = [ + 'path' => preg_replace('/^files/', '', $file->getInternalPath()), + 'lat' => null, + 'lng' => null, + 'oldLat' => $photo ? $photo->getLat() : null, + 'oldLng' => $photo ? $photo->getLng() : null, + ]; $this->resetExifCoords($file); $this->photoMapper->updateByFileId($file->getId(), null, null); - $nbDone++; } } } - return $nbDone; + return $done; } // avoid adding photo if it already exists in the DB |