Skip to content

Commit

Permalink
Use new metadata API
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Oct 26, 2023
1 parent e7243b2 commit 2919715
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 285 deletions.
3 changes: 1 addition & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

<commands>
<command>OCA\Photos\Command\UpdateReverseGeocodingFilesCommand</command>
<command>OCA\Photos\Command\MapMediaToPlaceCommand</command>
</commands>

<sabre>
Expand All @@ -48,4 +47,4 @@
<background-jobs>
<job>OCA\Photos\Jobs\AutomaticPlaceMapperJob</job>
</background-jobs>
</info>
</info>
16 changes: 12 additions & 4 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@
use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\Events\SabrePluginAuthInitEvent;
use OCA\Photos\Listener\AlbumsManagementEventListener;
use OCA\Photos\Listener\PlaceManagerEventListener;
use OCA\Photos\Listener\SabrePluginAuthInitListener;
use OCA\Photos\Listener\TagListener;
use OCA\Photos\MetadataProvider\ExifMetadataProvider;
use OCA\Photos\MetadataProvider\OriginalDateTimeMetadataProvider;
use OCA\Photos\MetadataProvider\PlaceMetadataProvider;
use OCA\Photos\MetadataProvider\SizeMetadataProvider;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Files\Events\Node\NodeDeletedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;
use OCP\FilesMetadata\Event\MetadataLiveEvent;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\Share\Events\ShareDeletedEvent;
Expand Down Expand Up @@ -75,8 +79,12 @@ public function register(IRegistrationContext $context): void {
/** Register $principalBackend for the DAV collection */
$context->registerServiceAlias('principalBackend', Principal::class);

// Priority of -1 to be triggered after event listeners populating metadata.
$context->registerEventListener(NodeWrittenEvent::class, PlaceManagerEventListener::class, -1);
// Metadata
$context->registerEventListener(MetadataLiveEvent::class, ExifMetadataProvider::class);
$context->registerEventListener(MetadataLiveEvent::class, SizeMetadataProvider::class);
$context->registerEventListener(MetadataLiveEvent::class, OriginalDateTimeMetadataProvider::class);
$context->registerEventListener(MetadataLiveEvent::class, PlaceMetadataProvider::class);
$context->registerEventListener(MetadataBackgroundEvent::class, PlaceMetadataProvider::class);

$context->registerEventListener(NodeDeletedEvent::class, AlbumsManagementEventListener::class);
$context->registerEventListener(UserRemovedEvent::class, AlbumsManagementEventListener::class);
Expand Down
116 changes: 0 additions & 116 deletions lib/Command/MapMediaToPlaceCommand.php

This file was deleted.

30 changes: 4 additions & 26 deletions lib/DB/Place/PlaceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

namespace OCA\Photos\DB\Place;

use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IDBConnection;

class PlaceMapper {
Expand All @@ -39,6 +39,7 @@ public function __construct(
private IDBConnection $connection,
private IMimeTypeLoader $mimeTypeLoader,
private IRootFolder $rootFolder,
private IFilesMetadataManager $filesMetadataManager,
) {
}

Expand Down Expand Up @@ -166,30 +167,7 @@ public function findFileForUserAndPlace(string $userId, string $place, string $f
}

public function setPlaceForFile(string $place, int $fileId): void {
try {
$query = $this->connection->getQueryBuilder();
$query->insert('file_metadata')
->values([
"id" => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
"group_name" => $query->createNamedParameter(self::METADATA_GROUP),
"value" => $query->createNamedParameter($place),
])
->executeStatement();
} catch (\Exception $ex) {
if ($ex->getPrevious() instanceof UniqueConstraintViolationException) {
$this->updatePlaceForFile($place, $fileId);
} else {
throw $ex;
}
}
}

public function updatePlaceForFile(string $place, int $fileId): void {
$query = $this->connection->getQueryBuilder();
$query->update('file_metadata')
->set("value", $query->createNamedParameter($place))
->where($query->expr()->eq('id', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('group_name', $query->createNamedParameter(self::METADATA_GROUP)))
->executeStatement();
$metadata = $this->filesMetadataManager->getMetadata($fileId, true);
$metadata->set('gps', $place, true);
}
}
48 changes: 0 additions & 48 deletions lib/Jobs/MapMediaToPlaceJob.php

This file was deleted.

71 changes: 0 additions & 71 deletions lib/Listener/PlaceManagerEventListener.php

This file was deleted.

Loading

0 comments on commit 2919715

Please sign in to comment.