diff --git a/CHANGELOG.md b/CHANGELOG.md index e03bab6d1..ddf1f3de6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. ## [Unreleased] -- **Important**: It is recommended to run `occ memories:places-setup` again if you use MySQL or MariaDB +- **Important**: You must run `occ memories:places-setup` again after this update - Hide files starting with `.` in the timeline - Prevent automatically retrying failed indexing jobs - Support for 3GP videos ([#1055](https://github.com/pulsejet/memories/issues/1055)) diff --git a/lib/Db/TimelineWrite.php b/lib/Db/TimelineWrite.php index 2e09c3bbe..c4262fcb3 100644 --- a/lib/Db/TimelineWrite.php +++ b/lib/Db/TimelineWrite.php @@ -10,6 +10,7 @@ use OCP\Files\File; use OCP\IDBConnection; use OCP\Lock\ILockingProvider; +use Psr\Log\LoggerInterface; const DELETE_TABLES = ['memories', 'memories_livephoto', 'memories_places', 'memories_failures']; const TRUNCATE_TABLES = ['memories_mapclusters']; @@ -25,6 +26,7 @@ public function __construct( protected IDBConnection $connection, protected LivePhoto $livePhoto, protected ILockingProvider $lockingProvider, + protected LoggerInterface $logger, ) {} /** diff --git a/lib/Db/TimelineWritePlaces.php b/lib/Db/TimelineWritePlaces.php index c17b7ecdd..0da6bfa7d 100644 --- a/lib/Db/TimelineWritePlaces.php +++ b/lib/Db/TimelineWritePlaces.php @@ -15,6 +15,7 @@ trait TimelineWritePlaces { protected IDBConnection $connection; + protected LoggerInterface $logger; /** * Add places data for a file. @@ -48,7 +49,15 @@ public function updatePlacesData(int $fileId, ?float $lat, ?float $lon): array } // Get places - $rows = \OC::$server->get(\OCA\Memories\Service\Places::class)->queryPoint($lat, $lon); + try { + $rows = \OC::$server->get(\OCA\Memories\Service\Places::class) + ->queryPoint($lat, $lon) + ; + } catch (\Exception $e) { + $this->logger->error("Error querying places: {$e->getMessage()}", ['app' => 'memories']); + + return []; + } // Get last ID, i.e. the ID with highest admin_level but <= 8 $crows = array_filter($rows, static fn ($row) => $row['admin_level'] <= 8); diff --git a/lib/Migration/Version602003Date20240310203729.php b/lib/Migration/Version602003Date20240310203729.php index b59bb2003..3b80ddcf7 100644 --- a/lib/Migration/Version602003Date20240310203729.php +++ b/lib/Migration/Version602003Date20240310203729.php @@ -65,6 +65,11 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op $table->addIndex(['fileid', 'mtime'], 'memories_fail_fid_mt_idx'); } + // This version changes the geometry of planet + \OC::$server->get(\OCA\Memories\Settings\SystemConfig::class) + ->set('memories.gis_type', -1) + ; + return $schema; } diff --git a/lib/Service/Places.php b/lib/Service/Places.php index 011810666..ceab6f727 100644 --- a/lib/Service/Places.php +++ b/lib/Service/Places.php @@ -99,9 +99,9 @@ public function queryPoint(float $lat, float $lon): array // Construct WHERE clause depending on GIS type $where = null; if (GIS_TYPE_MYSQL === $gisType) { - $where = "ST_Contains(geometry, ST_GeomFromText('POINT({$lon} {$lat})', 4326))"; + $where = "ST_Contains(geometry, ST_GeomFromText('POINT({$lat} {$lon})', 4326))"; } elseif (GIS_TYPE_POSTGRES === $gisType) { - $where = "POINT('{$lon},{$lat}') <@ geometry"; + $where = "POINT('{$lat},{$lon}') <@ geometry"; } else { return []; } @@ -325,27 +325,35 @@ public function importPlanet(string $datafile): void ++$idx; $geometry = ''; + // Every polygon must have at least 3 points if (\count($coords) < 3) { echo "ERROR: Invalid polygon {$polyid}\n"; continue; } + // Check if coordinates are valid + foreach ($coords as [$lon, $lat]) { + if ($lon < -180 || $lon > 180 || $lat < -90 || $lat > 90) { + echo "ERROR: Invalid coordinates for polygon {$polyid}\n"; + + continue 2; + } + } + if (GIS_TYPE_MYSQL === $gis) { $points = implode(',', array_map(static function (array $point) { - $x = $point[0]; - $y = $point[1]; + [$lon, $lat] = $point; - return "{$x} {$y}"; + return "{$lat} {$lon}"; }, $coords)); $geometry = "POLYGON(({$points}))"; } elseif (GIS_TYPE_POSTGRES === $gis) { $geometry = implode(',', array_map(static function (array $point) { - $x = $point[0]; - $y = $point[1]; + [$lon, $lat] = $point; - return "({$x},{$y})"; + return "({$lat},{$lon})"; }, $coords)); } @@ -382,7 +390,7 @@ public function importPlanet(string $datafile): void // Mark success echo "Planet database imported successfully!\n"; flush(); - $this->config->setSystemValue('memories.gis_type', $gis); + SystemConfig::set('memories.gis_type', $gis); // Delete data file @unlink($datafile);