Fix timeline after move

pull/37/head
Varun Patil 2022-08-18 00:35:14 +00:00
parent 833ce737b7
commit 0a3bfc096f
5 changed files with 29 additions and 21 deletions

View File

@ -13,7 +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. 📸 Place all photos you want on the timeline in a folder called `Photos` (case sensitive) 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

@ -34,6 +34,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\Events\Node\NodeDeletedEvent;
use OCP\Files\Events\Node\NodeRenamedEvent;
use OCP\Files\Events\Node\NodeTouchedEvent;
class Application extends App implements IBootstrap {
@ -65,6 +66,7 @@ class Application extends App implements IBootstrap {
public function register(IRegistrationContext $context): void {
$context->registerEventListener(NodeWrittenEvent::class, PostWriteListener::class);
$context->registerEventListener(NodeRenamedEvent::class, PostWriteListener::class);
$context->registerEventListener(NodeTouchedEvent::class, PostWriteListener::class);
$context->registerEventListener(NodeDeletedEvent::class, PostDeleteListener::class);
}

View File

@ -77,16 +77,15 @@ class Util {
$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 *PREFIX*polaroid
WHERE file_id = ? AND user_id = ? AND mtime = ? AND timeline = ?';
WHERE file_id = ? AND user_id = ? AND mtime = ?';
$exists = $this->connection->executeQuery($sql, [
$fileId, $user, $mtime, $timeline,
$fileId, $user, $mtime,
], [
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_INT, \PDO::PARAM_BOOL,
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_INT,
])->fetch();
if (intval($exists['e']) > 0) {
return;
@ -98,18 +97,18 @@ class Util {
$dateTaken = gmdate('Y-m-d H:i:s', $dateTaken);
$sql = 'INSERT
INTO *PREFIX*polaroid (day_id, date_taken, is_video, timeline, mtime, user_id, file_id)
VALUES (?, ?, ?, ?, ?, ?, ?)
INTO *PREFIX*polaroid (day_id, date_taken, is_video, mtime, user_id, file_id)
VALUES (?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
day_id = ?, date_taken = ?, is_video = ?, timeline = ?, mtime = ?';
day_id = ?, date_taken = ?, is_video = ?, mtime = ?';
$this->connection->executeStatement($sql, [
$dayId, $dateTaken, $is_video, $timeline, $mtime,
$dayId, $dateTaken, $is_video, $mtime,
$user, $fileId,
$dayId, $dateTaken, $is_video, $timeline, $mtime,
$dayId, $dateTaken, $is_video, $mtime,
], [
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_BOOL, \PDO::PARAM_INT,
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_INT,
\PDO::PARAM_STR, \PDO::PARAM_INT,
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_BOOL, \PDO::PARAM_INT,
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_INT,
]);
}
@ -133,7 +132,10 @@ class Util {
): array {
$sql = 'SELECT day_id, COUNT(file_id) AS count
FROM `*PREFIX*polaroid`
WHERE user_id=?
INNER JOIN `*PREFIX*filecache`
ON user_id=?
AND `*PREFIX*polaroid`.`file_id` = `*PREFIX*filecache`.`fileid`
AND `*PREFIX*filecache`.`path` LIKE "files/Photos/%"
GROUP BY day_id
ORDER BY day_id DESC';
$rows = $this->connection->executeQuery($sql, [$user], [
@ -146,7 +148,7 @@ class Util {
$sql = 'SELECT day_id, COUNT(file_id) AS count
FROM `*PREFIX*polaroid`
INNER JOIN `*PREFIX*filecache`
ON `*PREFIX*polaroid`.`file_id` = `*PREFIX*filecache`.`fileid`
ON `*PREFIX*polaroid`.`file_id` = `*PREFIX*filecache`.`fileid`
AND (`*PREFIX*filecache`.`parent`=? OR `*PREFIX*filecache`.`fileid`=?)
GROUP BY day_id
ORDER BY day_id DESC';
@ -174,7 +176,8 @@ class Util {
$sql = 'SELECT file_id, *PREFIX*filecache.etag, is_video
FROM *PREFIX*polaroid
LEFT JOIN *PREFIX*filecache
ON *PREFIX*filecache.fileid = *PREFIX*polaroid.file_id
ON *PREFIX*filecache.fileid = *PREFIX*polaroid.file_id
AND `*PREFIX*filecache`.`path` LIKE "files/Photos/%"
WHERE user_id = ? AND day_id = ?
ORDER BY date_taken DESC';
$rows = $this->connection->executeQuery($sql, [$user, $dayId], [

View File

@ -25,6 +25,7 @@ namespace OCA\Polaroid\Listeners;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\Node\NodeRenamedEvent;
use OCP\Files\Events\Node\NodeTouchedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\Folder;
@ -42,7 +43,9 @@ class PostWriteListener implements IEventListener {
}
public function handle(Event $event): void {
if (!($event instanceof NodeWrittenEvent) && !($event instanceof NodeTouchedEvent)) {
if (!($event instanceof NodeWrittenEvent) &&
!($event instanceof NodeTouchedEvent) &&
!($event instanceof NodeRenamedEvent)) {
return;
}

View File

@ -47,18 +47,18 @@
$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(['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');
}
if ($schema->hasTable('filecache')) {
$table = $schema->getTable('filecache');
$table->addIndex(['path'], 'polaroid_path_index');
}
return $schema;
}
}