From db5030c18bd4407bfa955719a4b53685ee95c39f Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 3 Aug 2023 18:56:51 -0700 Subject: [PATCH] clusters: make fileid filter generic Signed-off-by: Varun Patil --- lib/ClustersBackend/AlbumsBackend.php | 6 +----- lib/ClustersBackend/Backend.php | 4 +++- lib/ClustersBackend/FaceRecognitionBackend.php | 6 +++++- lib/ClustersBackend/PlacesBackend.php | 6 +++++- lib/ClustersBackend/RecognizeBackend.php | 6 +----- lib/ClustersBackend/TagsBackend.php | 6 +++++- lib/Controller/ClustersController.php | 6 +++--- lib/Db/AlbumsQuery.php | 4 ++-- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/ClustersBackend/AlbumsBackend.php b/lib/ClustersBackend/AlbumsBackend.php index a1812132..95db0738 100644 --- a/lib/ClustersBackend/AlbumsBackend.php +++ b/lib/ClustersBackend/AlbumsBackend.php @@ -87,12 +87,8 @@ class AlbumsBackend extends Backend $this->tq->allowEmptyRoot(); } - public function getClusters(): array + public function getClusters(int $fileid = 0): array { - /** @var \OCP\IRequest $request */ - $request = \OC::$server->get(\OCP\IRequest::class); - $fileid = (int) $request->getParam('fileid', -1); - // Run actual queries $list = []; diff --git a/lib/ClustersBackend/Backend.php b/lib/ClustersBackend/Backend.php index 27f406d4..c324fc68 100644 --- a/lib/ClustersBackend/Backend.php +++ b/lib/ClustersBackend/Backend.php @@ -60,8 +60,10 @@ abstract class Backend /** * Get the cluster list for the current user. + * + * @param int $fileid Filter clusters by file ID (optional) */ - abstract public function getClusters(): array; + abstract public function getClusters(int $fileid = 0): array; /** * Get a cluster ID for the given cluster. diff --git a/lib/ClustersBackend/FaceRecognitionBackend.php b/lib/ClustersBackend/FaceRecognitionBackend.php index 7003becc..04df7fc8 100644 --- a/lib/ClustersBackend/FaceRecognitionBackend.php +++ b/lib/ClustersBackend/FaceRecognitionBackend.php @@ -123,8 +123,12 @@ class FaceRecognitionBackend extends Backend unset($row['face_x'], $row['face_y'], $row['face_w'], $row['face_h'], $row['image_height'], $row['image_width']); } - public function getClusters(): array + public function getClusters(int $fileid = 0): array { + if ($fileid) { + throw new \Exception('FaceRecognitionBackend: fileid filter not implemented'); + } + $faces = array_merge( $this->getFaceRecognitionPersons(), $this->getFaceRecognitionClusters() diff --git a/lib/ClustersBackend/PlacesBackend.php b/lib/ClustersBackend/PlacesBackend.php index 51ec11ad..91afa2f9 100644 --- a/lib/ClustersBackend/PlacesBackend.php +++ b/lib/ClustersBackend/PlacesBackend.php @@ -63,8 +63,12 @@ class PlacesBackend extends Backend )); } - public function getClusters(): array + public function getClusters(int $fileid = 0): array { + if ($fileid) { + throw new \Exception('PlacesBackend: fileid filter not implemented'); + } + $inside = (int) $this->request->getParam('inside', 0); $marked = (int) $this->request->getParam('mark', 1); diff --git a/lib/ClustersBackend/RecognizeBackend.php b/lib/ClustersBackend/RecognizeBackend.php index f17dec03..f053ecb6 100644 --- a/lib/ClustersBackend/RecognizeBackend.php +++ b/lib/ClustersBackend/RecognizeBackend.php @@ -129,12 +129,8 @@ class RecognizeBackend extends Backend unset($row['face_w'], $row['face_h'], $row['face_x'], $row['face_y']); } - public function getClusters(): array + public function getClusters(int $fileid = 0): array { - /** @var \OCP\IRequest $request */ - $request = \OC::$server->get(\OCP\IRequest::class); - $fileid = (int) $request->getParam('fileid', -1); - $query = $this->tq->getBuilder(); // SELECT all face clusters diff --git a/lib/ClustersBackend/TagsBackend.php b/lib/ClustersBackend/TagsBackend.php index a228436f..0d02feb7 100644 --- a/lib/ClustersBackend/TagsBackend.php +++ b/lib/ClustersBackend/TagsBackend.php @@ -67,8 +67,12 @@ class TagsBackend extends Backend )); } - public function getClusters(): array + public function getClusters(int $fileid = 0): array { + if ($fileid) { + throw new \Exception('TagsBackend: fileid filter not implemented'); + } + $query = $this->tq->getBuilder(); // SELECT visible tag name and count of photos diff --git a/lib/Controller/ClustersController.php b/lib/Controller/ClustersController.php index b3dd6a2d..b7fe935d 100644 --- a/lib/Controller/ClustersController.php +++ b/lib/Controller/ClustersController.php @@ -40,12 +40,12 @@ class ClustersController extends GenericApiController * * Get list of clusters */ - public function list(string $backend): Http\Response + public function list(string $backend, int $fileid = 0): Http\Response { - return Util::guardEx(function () use ($backend) { + return Util::guardEx(function () use ($backend, $fileid) { $this->init($backend); - $list = $this->backend->getClusters(); + $list = $this->backend->getClusters($fileid); // Set cluster_id and cluster_type for each cluster foreach ($list as &$cluster) { diff --git a/lib/Db/AlbumsQuery.php b/lib/Db/AlbumsQuery.php index 934a2fc7..1e84d0d2 100644 --- a/lib/Db/AlbumsQuery.php +++ b/lib/Db/AlbumsQuery.php @@ -22,7 +22,7 @@ class AlbumsQuery * @param bool $shared Whether to get shared albums * @param int $fileid File to filter by */ - public function getList(string $uid, bool $shared = false, int $fileid = -1) + public function getList(string $uid, bool $shared = false, int $fileid = 0) { $query = $this->connection->getQueryBuilder(); @@ -68,7 +68,7 @@ class AlbumsQuery $query->addOrderBy('pa.album_id', 'DESC'); // tie-breaker // WHERE these albums contain fileid if specified - if ($fileid > 0) { + if ($fileid) { $fSq = $this->connection->getQueryBuilder() ->select('paf.file_id') ->from('photos_albums_files', 'paf')