From c867cc68ed2e827ac03324222816db45d889d64d Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 23 Mar 2023 21:57:54 -0700 Subject: [PATCH] More refactor Signed-off-by: Varun Patil --- lib/AppInfo/Application.php | 11 +++++------ .../Manager.php} | 5 ++--- lib/Controller/ClustersController.php | 7 +++---- lib/Controller/DaysController.php | 5 +++-- lib/Controller/GenericApiController.php | 2 +- lib/Controller/PublicController.php | 3 ++- lib/{Manager => Db}/FsManager.php | 4 +--- lib/Db/TimelineQuery.php | 3 +-- lib/Db/TimelineQueryDays.php | 4 ++-- 9 files changed, 20 insertions(+), 24 deletions(-) rename lib/{Manager/ClustersBackendManager.php => ClustersBackend/Manager.php} (96%) rename lib/{Manager => Db}/FsManager.php (99%) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index bf6f40a1..5bd8dd0e 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -26,7 +26,6 @@ namespace OCA\Memories\AppInfo; use OCA\Memories\ClustersBackend; use OCA\Memories\Listeners\PostDeleteListener; use OCA\Memories\Listeners\PostWriteListener; -use OCA\Memories\Manager\ClustersBackendManager; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -76,11 +75,11 @@ class Application extends App implements IBootstrap $context->registerEventListener(NodeDeletedEvent::class, PostDeleteListener::class); // Register clusters backends - ClustersBackendManager::register('albums', ClustersBackend\AlbumsBackend::class); - ClustersBackendManager::register('tags', ClustersBackend\TagsBackend::class); - ClustersBackendManager::register('places', ClustersBackend\PlacesBackend::class); - ClustersBackendManager::register('recognize', ClustersBackend\RecognizeBackend::class); - ClustersBackendManager::register('facerecognition', ClustersBackend\FaceRecognitionBackend::class); + ClustersBackend\Manager::register('albums', ClustersBackend\AlbumsBackend::class); + ClustersBackend\Manager::register('tags', ClustersBackend\TagsBackend::class); + ClustersBackend\Manager::register('places', ClustersBackend\PlacesBackend::class); + ClustersBackend\Manager::register('recognize', ClustersBackend\RecognizeBackend::class); + ClustersBackend\Manager::register('facerecognition', ClustersBackend\FaceRecognitionBackend::class); } public function boot(IBootContext $context): void diff --git a/lib/Manager/ClustersBackendManager.php b/lib/ClustersBackend/Manager.php similarity index 96% rename from lib/Manager/ClustersBackendManager.php rename to lib/ClustersBackend/Manager.php index 343b47ca..aec74324 100644 --- a/lib/Manager/ClustersBackendManager.php +++ b/lib/ClustersBackend/Manager.php @@ -21,12 +21,11 @@ declare(strict_types=1); * along with this program. If not, see . */ -namespace OCA\Memories\Manager; +namespace OCA\Memories\ClustersBackend; -use OCA\Memories\ClustersBackend\Backend; use OCP\IRequest; -class ClustersBackendManager +class Manager { /** Mapping of backend name to className */ public static array $backends = []; diff --git a/lib/Controller/ClustersController.php b/lib/Controller/ClustersController.php index 1b59a348..cb6f6592 100644 --- a/lib/Controller/ClustersController.php +++ b/lib/Controller/ClustersController.php @@ -23,9 +23,8 @@ declare(strict_types=1); namespace OCA\Memories\Controller; -use OCA\Memories\ClustersBackend\Backend; +use OCA\Memories\ClustersBackend; use OCA\Memories\Exceptions; -use OCA\Memories\Manager\ClustersBackendManager; use OCA\Memories\Util; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataDisplayResponse; @@ -34,7 +33,7 @@ use OCP\AppFramework\Http\JSONResponse; class ClustersController extends GenericApiController { /** Current backend for this instance */ - protected Backend $backend; + protected ClustersBackend\Backend $backend; /** * @NoAdminRequired @@ -112,7 +111,7 @@ class ClustersController extends GenericApiController { Util::getUser(); - $this->backend = ClustersBackendManager::get($backend); + $this->backend = ClustersBackend\Manager::get($backend); if (!$this->backend->isEnabled()) { throw Exceptions::NotEnabled($this->backend->appName()); diff --git a/lib/Controller/DaysController.php b/lib/Controller/DaysController.php index 561ab7bc..0ae9d1ab 100644 --- a/lib/Controller/DaysController.php +++ b/lib/Controller/DaysController.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace OCA\Memories\Controller; +use OCA\Memories\ClustersBackend; use OCA\Memories\Exceptions; -use OCA\Memories\Manager\ClustersBackendManager; use OCA\Memories\Util; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; @@ -146,7 +146,8 @@ class DaysController extends GenericApiController $transforms = []; // Add clustering transforms - $transforms = array_merge($transforms, ClustersBackendManager::getTransforms($this->request)); + $clusterTs = ClustersBackend\Manager::getTransforms($this->request); + $transforms = array_merge($transforms, $clusterTs); // Other transforms not allowed for public shares if (!Util::isLoggedIn()) { diff --git a/lib/Controller/GenericApiController.php b/lib/Controller/GenericApiController.php index db67d3b3..464b986a 100644 --- a/lib/Controller/GenericApiController.php +++ b/lib/Controller/GenericApiController.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace OCA\Memories\Controller; use OCA\Memories\AppInfo\Application; +use OCA\Memories\Db\FsManager; use OCA\Memories\Db\TimelineQuery; -use OCA\Memories\Manager\FsManager; use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\Files\IRootFolder; diff --git a/lib/Controller/PublicController.php b/lib/Controller/PublicController.php index 9caedc5a..54d1b3fa 100644 --- a/lib/Controller/PublicController.php +++ b/lib/Controller/PublicController.php @@ -3,6 +3,7 @@ namespace OCA\Memories\Controller; use OCA\Memories\AppInfo\Application; +use OCA\Memories\Db\FsManager; use OCA\Memories\Db\TimelineQuery; use OCP\AppFramework\AuthPublicShareController; use OCP\AppFramework\Http\Template\PublicTemplateResponse; @@ -98,7 +99,7 @@ class PublicController extends AuthPublicShareController throw new NotFoundException(); } - if (!\OCA\Memories\Manager\FsManager::validateShare($share)) { + if (!FsManager::validateShare($share)) { throw new NotFoundException(); } diff --git a/lib/Manager/FsManager.php b/lib/Db/FsManager.php similarity index 99% rename from lib/Manager/FsManager.php rename to lib/Db/FsManager.php index d8567546..d00464e1 100644 --- a/lib/Manager/FsManager.php +++ b/lib/Db/FsManager.php @@ -21,10 +21,8 @@ declare(strict_types=1); * along with this program. If not, see . */ -namespace OCA\Memories\Manager; +namespace OCA\Memories\Db; -use OCA\Memories\Db\AlbumsQuery; -use OCA\Memories\Db\TimelineRoot; use OCA\Memories\Exceptions; use OCA\Memories\Exif; use OCA\Memories\Util; diff --git a/lib/Db/TimelineQuery.php b/lib/Db/TimelineQuery.php index 2e80e71f..3be7939c 100644 --- a/lib/Db/TimelineQuery.php +++ b/lib/Db/TimelineQuery.php @@ -36,8 +36,7 @@ class TimelineQuery { if (null === $this->_root) { $this->_root = new TimelineRoot(); - $fsManager = \OC::$server->get(\OCA\Memories\Manager\FsManager::class); - $fsManager->populateRoot($this->_root); + \OC::$server->get(FsManager::class)->populateRoot($this->_root); } return $this->_root; diff --git a/lib/Db/TimelineQueryDays.php b/lib/Db/TimelineQueryDays.php index 39680d00..96e51448 100644 --- a/lib/Db/TimelineQueryDays.php +++ b/lib/Db/TimelineQueryDays.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace OCA\Memories\Db; -use OCA\Memories\Manager\ClustersBackendManager; +use OCA\Memories\ClustersBackend; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; @@ -275,7 +275,7 @@ trait TimelineQueryDays } // All cluster transformations - ClustersBackendManager::applyDayPostTransforms($this->request, $row); + ClustersBackend\Manager::applyDayPostTransforms($this->request, $row); // We don't need these fields unset($row['datetaken']);