Implement includsion (fix #1)

pull/37/head
Varun Patil 2022-08-17 23:51:48 +00:00
parent 5d20cc2e7c
commit 68b28ed2ec
4 changed files with 33 additions and 16 deletions

View File

@ -13,6 +13,7 @@
1. ☁ Clone this into your `apps` folder of your Nextcloud.
1. ⚒️ Install `exiftool` (`sudo apt install exiftool`).
1. 📸 Place all photos you want on the timeline in a folder called `Photos` in the root of your home.
1. Run `php ./occ polaroid:index` to generate metadata indices for existing photos.
1. Consider installing the [preview generator](https://github.com/rullzer/previewgenerator) for pre-generating thumbnails.

View File

@ -115,14 +115,6 @@ class Index extends Command {
private function parseFolder(Folder $folder): void {
try {
$folderPath = $folder->getPath();
// Respect the '.nomedia' file. If present don't traverse the folder
// Same for external mounts with previews disabled
if ($folder->nodeExists('.nomedia')) {
$this->output->writeln('Skipping folder ' . $folderPath);
return;
}
$this->output->writeln('Scanning folder ' . $folderPath);
$nodes = $folder->getDirectoryListing();

View File

@ -74,25 +74,42 @@ class Util {
}
// Get parameters
$mtime = $file->getMtime();
$user = $file->getOwner()->getUID();
$fileId = $file->getId();
$timeline = (bool)(preg_match('/^files\\/photos/i', $file->getInternalPath()));
// Check if need to update
$sql = 'SELECT COUNT(*) as e
FROM oc_polaroid
WHERE file_id = ? AND user_id = ? AND mtime = ? AND timeline = ?';
$exists = $this->connection->executeQuery($sql, [
$fileId, $user, $mtime, $timeline,
], [
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_INT, \PDO::PARAM_BOOL,
])->fetch();
if (intval($exists['e']) > 0) {
return;
}
// Get more parameters
$dateTaken = $this->getDateTaken($file);
$dayId = floor($dateTaken / 86400);
$dateTaken = gmdate('Y-m-d H:i:s', $dateTaken);
$sql = 'INSERT
INTO oc_polaroid (day_id, date_taken, is_video, user_id, file_id)
VALUES (?, ?, ?, ?, ?)
INTO oc_polaroid (day_id, date_taken, is_video, timeline, mtime, user_id, file_id)
VALUES (?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
day_id = ?, date_taken = ?, is_video = ?';
day_id = ?, date_taken = ?, is_video = ?, timeline = ?, mtime = ?';
$this->connection->executeStatement($sql, [
$dayId, $dateTaken, $is_video,
$dayId, $dateTaken, $is_video, $timeline, $mtime,
$user, $fileId,
$dayId, $dateTaken, $is_video,
$dayId, $dateTaken, $is_video, $timeline, $mtime,
], [
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL,
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_BOOL, \PDO::PARAM_INT,
\PDO::PARAM_STR, \PDO::PARAM_INT,
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL,
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_BOOL, \PDO::PARAM_INT,
]);
}

View File

@ -44,11 +44,18 @@
'notnull' => false,
'default' => false
]);
$table->addColumn('mtime', Types::INTEGER, [
'notnull' => true,
]);
$table->addColumn('timeline', Types::BOOLEAN, [
'notnull' => false,
'default' => false
]);
$table->setPrimaryKey(['id']);
$table->addIndex(['user_id'], 'polaroid_user_id_index');
$table->addIndex(['day_id'], 'polaroid_day_id_index');
$table->addIndex(['user_id', 'day_id'], 'polaroid_ud_index');
$table->addIndex(['user_id', 'day_id', 'timeline'], 'polaroid_udt_index');
$table->addUniqueIndex(['user_id', 'file_id'], 'polaroid_day_uf_ui');
}