map: add migration
parent
c6edd10c85
commit
99ce1fcfd6
|
@ -206,8 +206,8 @@ trait TimelineQueryDays
|
|||
$query = $this->connection->getQueryBuilder();
|
||||
|
||||
// Get the average location of each cluster
|
||||
$avgLat = $query->createFunction('AVG(latitude) AS avgLat');
|
||||
$avgLng = $query->createFunction('AVG(longitude) AS avgLng');
|
||||
$avgLat = $query->createFunction('AVG(lat) AS avgLat');
|
||||
$avgLng = $query->createFunction('AVG(lon) AS avgLng');
|
||||
$count = $query->createFunction('COUNT(*) AS count');
|
||||
$query->select($avgLat, $avgLng, $count)
|
||||
->from('memories', 'm')
|
||||
|
@ -217,7 +217,7 @@ trait TimelineQueryDays
|
|||
$query = $this->joinFilecache($query, $root, $recursive, $archive);
|
||||
|
||||
// Group by cluster
|
||||
$groupFunction = $query->createFunction('latitude DIV '.$boxSize.', longitude DIV '.$boxSize);
|
||||
$groupFunction = $query->createFunction('lat DIV '.$boxSize.', lon DIV '.$boxSize);
|
||||
$query->groupBy($groupFunction);
|
||||
|
||||
// Apply all transformations (including map bounds)
|
||||
|
|
|
@ -44,10 +44,10 @@ trait TimelineQueryFilters
|
|||
{
|
||||
$query->andWhere(
|
||||
$query->expr()->andX(
|
||||
$query->expr()->gte('m.latitude', $query->createNamedParameter($minLat, IQueryBuilder::PARAM_STR)),
|
||||
$query->expr()->lte('m.latitude', $query->createNamedParameter($maxLat, IQueryBuilder::PARAM_STR)),
|
||||
$query->expr()->gte('m.longitude', $query->createNamedParameter($minLng, IQueryBuilder::PARAM_STR)),
|
||||
$query->expr()->lte('m.longitude', $query->createNamedParameter($maxLng, IQueryBuilder::PARAM_STR))
|
||||
$query->expr()->gte('m.lat', $query->createNamedParameter($minLat, IQueryBuilder::PARAM_STR)),
|
||||
$query->expr()->lte('m.lat', $query->createNamedParameter($maxLat, IQueryBuilder::PARAM_STR)),
|
||||
$query->expr()->gte('m.lon', $query->createNamedParameter($minLng, IQueryBuilder::PARAM_STR)),
|
||||
$query->expr()->lte('m.lon', $query->createNamedParameter($maxLng, IQueryBuilder::PARAM_STR))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -158,6 +158,8 @@ class TimelineWrite
|
|||
}
|
||||
|
||||
// Store location data
|
||||
$lat = null;
|
||||
$lon = null;
|
||||
if (\array_key_exists('GPSLatitude', $exif) && \array_key_exists('GPSLongitude', $exif)) {
|
||||
try {
|
||||
$lat = (float) $exif['GPSLatitude'];
|
||||
|
@ -169,40 +171,39 @@ class TimelineWrite
|
|||
}
|
||||
}
|
||||
|
||||
// Parameters for insert or update
|
||||
$params = [
|
||||
'fileid' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
|
||||
'objectid' => $query->createNamedParameter((string) $fileId, IQueryBuilder::PARAM_STR),
|
||||
'dayid' => $query->createNamedParameter($dayId, IQueryBuilder::PARAM_INT),
|
||||
'datetaken' => $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR),
|
||||
'mtime' => $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT),
|
||||
'isvideo' => $query->createNamedParameter($isvideo, IQueryBuilder::PARAM_INT),
|
||||
'video_duration' => $query->createNamedParameter($videoDuration, IQueryBuilder::PARAM_INT),
|
||||
'w' => $query->createNamedParameter($w, IQueryBuilder::PARAM_INT),
|
||||
'h' => $query->createNamedParameter($h, IQueryBuilder::PARAM_INT),
|
||||
'exif' => $query->createNamedParameter($exifJson, IQueryBuilder::PARAM_STR),
|
||||
'liveid' => $query->createNamedParameter($liveid, IQueryBuilder::PARAM_STR),
|
||||
'lat' => $query->createNamedParameter($lat, IQueryBuilder::PARAM_STR),
|
||||
'lon' => $query->createNamedParameter($lon, IQueryBuilder::PARAM_STR),
|
||||
];
|
||||
|
||||
if ($prevRow) {
|
||||
// Update existing row
|
||||
// No need to set objectid again
|
||||
$query->update('memories')
|
||||
->set('dayid', $query->createNamedParameter($dayId, IQueryBuilder::PARAM_INT))
|
||||
->set('datetaken', $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR))
|
||||
->set('mtime', $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT))
|
||||
->set('isvideo', $query->createNamedParameter($isvideo, IQueryBuilder::PARAM_INT))
|
||||
->set('video_duration', $query->createNamedParameter($videoDuration, IQueryBuilder::PARAM_INT))
|
||||
->set('w', $query->createNamedParameter($w, IQueryBuilder::PARAM_INT))
|
||||
->set('h', $query->createNamedParameter($h, IQueryBuilder::PARAM_INT))
|
||||
->set('exif', $query->createNamedParameter($exifJson, IQueryBuilder::PARAM_STR))
|
||||
->set('liveid', $query->createNamedParameter($liveid, IQueryBuilder::PARAM_STR))
|
||||
->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)))
|
||||
;
|
||||
foreach ($params as $key => $value) {
|
||||
if ('objectid' !== $key && 'fileid' !== $key) {
|
||||
$query->set($key, $value);
|
||||
}
|
||||
}
|
||||
$query->executeStatement();
|
||||
} else {
|
||||
// Try to create new row
|
||||
try {
|
||||
$query->insert('memories')
|
||||
->values([
|
||||
'fileid' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
|
||||
'objectid' => $query->createNamedParameter((string) $fileId, IQueryBuilder::PARAM_STR),
|
||||
'dayid' => $query->createNamedParameter($dayId, IQueryBuilder::PARAM_INT),
|
||||
'datetaken' => $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR),
|
||||
'mtime' => $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT),
|
||||
'isvideo' => $query->createNamedParameter($isvideo, IQueryBuilder::PARAM_INT),
|
||||
'video_duration' => $query->createNamedParameter($videoDuration, IQueryBuilder::PARAM_INT),
|
||||
'w' => $query->createNamedParameter($w, IQueryBuilder::PARAM_INT),
|
||||
'h' => $query->createNamedParameter($h, IQueryBuilder::PARAM_INT),
|
||||
'exif' => $query->createNamedParameter($exifJson, IQueryBuilder::PARAM_STR),
|
||||
'liveid' => $query->createNamedParameter($liveid, IQueryBuilder::PARAM_STR),
|
||||
])
|
||||
;
|
||||
$query->insert('memories')->values($params);
|
||||
$query->executeStatement();
|
||||
} catch (\Exception $ex) {
|
||||
error_log('Failed to create memories record: '.$ex->getMessage());
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Your name <your@email.com>
|
||||
* @author Your name <your@email.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace OCA\Memories\Migration;
|
||||
|
||||
use OCP\DB\ISchemaWrapper;
|
||||
use OCP\DB\Types;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
|
||||
/**
|
||||
* Auto-generated migration step: Please modify to your needs!
|
||||
*/
|
||||
class Version401100Date20230208181533 extends SimpleMigrationStep
|
||||
{
|
||||
/**
|
||||
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
||||
*/
|
||||
public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
||||
*/
|
||||
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper
|
||||
{
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
$table = $schema->getTable('memories');
|
||||
|
||||
if (!$table->hasColumn('lat')) {
|
||||
$table->addColumn('lat', Types::DECIMAL, [
|
||||
'notnull' => false,
|
||||
'default' => null,
|
||||
'precision' => 8,
|
||||
'scale' => 6,
|
||||
]);
|
||||
$table->addColumn('lon', Types::DECIMAL, [
|
||||
'notnull' => false,
|
||||
'default' => null,
|
||||
'precision' => 9,
|
||||
'scale' => 6,
|
||||
]);
|
||||
|
||||
$table->addIndex(['lat', 'lon'], 'memories_lat_lon_index');
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
||||
*/
|
||||
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue