diff --git a/lib/Db/TimelineWrite.php b/lib/Db/TimelineWrite.php index c95b7685..27b14508 100644 --- a/lib/Db/TimelineWrite.php +++ b/lib/Db/TimelineWrite.php @@ -78,6 +78,7 @@ class TimelineWrite { $dateTaken = Exif::getDateTaken($file, $exif); $dayId = floor($dateTaken / 86400); $dateTaken = gmdate('Y-m-d H:i:s', $dateTaken); + [$w, $h] = Exif::getDimensions($exif); if ($prevRow) { // Update existing row @@ -86,6 +87,8 @@ class TimelineWrite { ->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('w', $query->createNamedParameter($w, IQueryBuilder::PARAM_INT)) + ->set('h', $query->createNamedParameter($h, IQueryBuilder::PARAM_INT)) ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); $query->executeStatement(); } else { @@ -98,6 +101,8 @@ class TimelineWrite { 'datetaken' => $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR), 'mtime' => $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT), 'isvideo' => $query->createNamedParameter($isvideo, IQueryBuilder::PARAM_INT), + 'w' => $query->createNamedParameter($w, IQueryBuilder::PARAM_INT), + 'h' => $query->createNamedParameter($h, IQueryBuilder::PARAM_INT), ]); $query->executeStatement(); } catch (\Exception $ex) { diff --git a/lib/Exif.php b/lib/Exif.php index 10002c09..e5b20980 100644 --- a/lib/Exif.php +++ b/lib/Exif.php @@ -313,6 +313,17 @@ class Exif { return self::forgetTimezone($dateTaken); } + /** + * Get image dimensions from Exif data + * @param array $exif + * @return array [width, height] + */ + public static function getDimensions(array &$exif) { + $width = $exif['ImageWidth'] ?? 0; + $height = $exif['ImageHeight'] ?? 0; + return [$width, $height]; + } + /** * Update exif date using exiftool * diff --git a/lib/Migration/Version400000Date20221015121115.php b/lib/Migration/Version400000Date20221015121115.php new file mode 100644 index 00000000..8cf3f731 --- /dev/null +++ b/lib/Migration/Version400000Date20221015121115.php @@ -0,0 +1,83 @@ + + * + * @author Your name + * + * @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 . + * + */ + +namespace OCA\Memories\Migration; + +use Closure; +use OCP\DB\Types; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +/** + * Auto-generated migration step: Please modify to your needs! + */ +class Version400000Date20221015121115 extends SimpleMigrationStep { + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if (!$schema->hasTable('memories')) { + throw new \Exception('Memories table does not exist'); + } + + $table = $schema->getTable('memories'); + + $table->addColumn('w', Types::INTEGER, [ + 'notnull' => true, + 'default' => 0, + ]); + $table->addColumn('h', Types::INTEGER, [ + 'notnull' => true, + 'default' => 0, + ]); + + return $schema; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { + } +}