From f6bcde7e6d5c3f630d5f8eb162a929497f70276e Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Thu, 10 Apr 2025 10:03:24 +0200 Subject: [PATCH] Move to IBootstrap initialization and remove the deprecated appinfo/app.php --- appinfo/app.php | 31 ----------------------- lib/AppInfo/Application.php | 49 ++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 54 deletions(-) delete mode 100644 appinfo/app.php diff --git a/appinfo/app.php b/appinfo/app.php deleted file mode 100644 index 716393f..0000000 --- a/appinfo/app.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @copyright 2018 Marcin Łojewski - * @author Marcin Łojewski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -use OCA\UserSQL\AppInfo\Application; -use OCP\AppFramework\QueryException; - -try { - $app = new Application(); - $app->registerBackends(); -} catch (QueryException $queryException) { - OC::$server->getLogger()->logException($queryException); -} diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 730b953..c16d2e8 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -4,6 +4,8 @@ * * @copyright 2018 Marcin Łojewski * @author Marcin Łojewski + * @copyright 2025 Claus-Justus Heine + * @author Claus-Justus Heine * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -22,14 +24,20 @@ namespace OCA\UserSQL\AppInfo; use OCP\AppFramework\App; -use OCP\AppFramework\QueryException; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\IGroupManager; +use OCP\IUserManager; + +use OCA\UserSQL\Backend; /** * The application bootstrap class. * * @author Marcin Łojewski */ -class Application extends App +class Application extends App implements IBootstrap { /** * The class constructor. @@ -42,26 +50,21 @@ class Application extends App parent::__construct("user_sql", $urlParams); } - /** - * Register the application backends - * if all necessary configuration is provided. - * - * @throws QueryException If the query container's could not be resolved - */ - public function registerBackends() - { - $userBackend = $this->getContainer()->query( - '\OCA\UserSQL\Backend\UserBackend' - ); - $groupBackend = $this->getContainer()->query( - '\OCA\UserSQL\Backend\GroupBackend' - ); + /** {@inheritdoc} */ + public function register(IRegistrationContext $context): void + {} - if ($userBackend->isConfigured()) { - \OC::$server->getUserManager()->registerBackend($userBackend); - } - if ($groupBackend->isConfigured()) { - \OC::$server->getGroupManager()->addBackend($groupBackend); - } - } + /** {@inheritdoc} */ + public function boot(IBootContext $context): void + { + $context->injectFn(function( + IUserManager $userManager, + Backend\UserBackend $userBackend, + IGroupManager $groupManager, + Backend\GroupBackend $groupBackend, + ) { + $userManager->registerBackend($userBackend); + $groupManager->addBackend($groupBackend); + }); + } }