From 13c313352c985ae2f9a59b309f8bdaa13034daa3 Mon Sep 17 00:00:00 2001 From: WLTBAgent Date: Fri, 13 Feb 2026 18:38:35 +0000 Subject: [PATCH] Fix: Add proper Application.php and fix DI - Created appinfo/Application.php (Nextcloud app bootstrap) - Extends OCP\AppFramework\App - Registers proper app ID: analyticshub - Loads CSS and JS files - Removed obsolete lib/App.php file - Updated all AppInfo::APP_NAME references to Application::APP_NAME - AdminController, ApiV1Controller - GoogleAnalyticsService, LLMService - Fixed dependency injection in AdminController - Injected IConfig service properly - Added missing use statements This is the core fix for the app not appearing in Nextcloud. Nextcloud requires appinfo/Application.php to initialize the app. --- analyticshub/appinfo/Application.php | 25 ++++++++++ analyticshub/lib/App.php | 50 ------------------- .../lib/Controller/AdminController.php | 13 +++-- .../lib/Controller/ApiV1Controller.php | 3 +- .../lib/Service/GoogleAnalyticsService.php | 17 ++++--- analyticshub/lib/Service/LLMService.php | 4 +- 6 files changed, 47 insertions(+), 65 deletions(-) create mode 100644 analyticshub/appinfo/Application.php delete mode 100644 analyticshub/lib/App.php diff --git a/analyticshub/appinfo/Application.php b/analyticshub/appinfo/Application.php new file mode 100644 index 0000000..a5cc183 --- /dev/null +++ b/analyticshub/appinfo/Application.php @@ -0,0 +1,25 @@ +registerService('GoogleAnalyticsService', function($c) { - return new GoogleAnalyticsService($c); - }); - - $this->registerService('LLMService', function($c) { - return new LLMService($c); - }); - - $this->registerService('DataProcessor', function($c) { - return new DataProcessor($c); - }); - - // Register controllers - $this->registerService('ApiV1Controller', function($c) { - return new ApiV1Controller($c); - }); - - $this->registerService('ReportController', function($c) { - return new ReportController($c); - }); - - $this->registerService('AdminController', function($c) { - return new AdminController($c); - }); - } - - public function getContainer() { - return $this->getContainer(); - } diff --git a/analyticshub/lib/Controller/AdminController.php b/analyticshub/lib/Controller/AdminController.php index 2484b07..1a63de1 100644 --- a/analyticshub/lib/Controller/AdminController.php +++ b/analyticshub/lib/Controller/AdminController.php @@ -10,10 +10,12 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCA\AnalyticsHub\AppInfo\Application; use OCA\AnalyticsHub\Service\GoogleAnalyticsService; use OCA\AnalyticsHub\Service\LLMService; use OCA\AnalyticsHub\Service\DataProcessor; +use OCP\IConfig; /** * Admin Settings Controller @@ -21,15 +23,18 @@ use OCA\AnalyticsHub\Service\DataProcessor; */ class AdminController { + private IConfig $config; private GoogleAnalyticsService $gaService; private LLMService $llmService; private DataProcessor $dataProcessor; public function __construct( + IConfig $config, GoogleAnalyticsService $gaService, LLMService $llmService, DataProcessor $dataProcessor ) { + $this->config = $config; $this->gaService = $gaService; $this->llmService = $llmService; $this->dataProcessor = $dataProcessor; @@ -41,7 +46,7 @@ class AdminController { */ public function index(): TemplateResponse { return new TemplateResponse('analyticshub', 'admin', [ - 'app_name' => AppInfo::APP_NAME, + 'app_name' => Application::APP_NAME, 'version' => AppInfo::getVersion(), 'status' => $this->gaService->isConfigured() ? 'configured' : 'not_configured', ]); @@ -145,7 +150,7 @@ class AdminController { */ public function getStatus(IRequest $request): DataResponse { $status = [ - 'app_name' => AppInfo::APP_NAME, + 'app_name' => Application::APP_NAME, 'version' => AppInfo::getVersion(), 'status' => 'operational', 'google_analytics' => $this->gaService->isConfigured() ? 'configured' : 'not_configured', @@ -164,10 +169,10 @@ class AdminController { * Helper methods */ private function saveConfigValue(string $key, string $value): void { - $this->getConfig()->setAppValue($key, $value, AppInfo::APP_NAME); + $this->config->setAppValue(Application::APP_NAME, $key, $value); } private function getConfigValue(string $key): ?string { - return $this->getConfig()->getAppValue($key, AppInfo::APP_NAME); + return $this->config->getAppValue(Application::APP_NAME, $key); } } diff --git a/analyticshub/lib/Controller/ApiV1Controller.php b/analyticshub/lib/Controller/ApiV1Controller.php index 19f2455..c4d3112 100644 --- a/analyticshub/lib/Controller/ApiV1Controller.php +++ b/analyticshub/lib/Controller/ApiV1Controller.php @@ -9,6 +9,7 @@ use OCP\IResponse; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; +use OCA\AnalyticsHub\AppInfo\Application; use OCA\AnalyticsHub\Service\GoogleAnalyticsService; use OCA\AnalyticsHub\Service\LLMService; @@ -146,7 +147,7 @@ class ApiV1Controller { $this->validateAgentAccess(); $status = [ - 'app_name' => AppInfo::APP_NAME, + 'app_name' => Application::APP_NAME, 'version' => AppInfo::getVersion(), 'status' => 'operational', 'google_analytics' => $this->gaService->isConfigured() ? 'configured' : 'not_configured', diff --git a/analyticshub/lib/Service/GoogleAnalyticsService.php b/analyticshub/lib/Service/GoogleAnalyticsService.php index 589b4fb..cadbde1 100644 --- a/analyticshub/lib/Service/GoogleAnalyticsService.php +++ b/analyticshub/lib/Service/GoogleAnalyticsService.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace OCA\AnalyticsHub\Service; use OCA\AnalyticsHub\Model\ClientConfig; +use OCA\AnalyticsHub\AppInfo\Application; use OCP\IConfig; use OCP\Util\Logger; use OCP\Util\SimplePDOMapper; @@ -33,9 +34,9 @@ class GoogleAnalyticsService { * Check if Google Analytics is configured */ public function isConfigured(): bool { - $clientId = $this->config->getAppValue('google_client_id', AppInfo::APP_NAME); - $clientSecret = $this->config->getAppValue('google_client_secret', AppInfo::APP_NAME); - $refreshToken = $this->config->getAppValue('google_refresh_token', AppInfo::APP_NAME); + $clientId = $this->config->getAppValue('google_client_id', Application::APP_NAME); + $clientSecret = $this->config->getAppValue('google_client_secret', Application::APP_NAME); + $refreshToken = $this->config->getAppValue('google_refresh_token', Application::APP_NAME); return !empty($clientId) && !empty($clientSecret) && !empty($refreshToken); } @@ -44,7 +45,7 @@ class GoogleAnalyticsService { * Check if LLM service is configured */ public function isLLMConfigured(): bool { - $apiKey = $this->config->getAppValue('anthropic_api_key', AppInfo::APP_NAME); + $apiKey = $this->config->getAppValue('anthropic_api_key', Application::APP_NAME); return !empty($apiKey); } @@ -73,7 +74,7 @@ class GoogleAnalyticsService { * Get all clients */ private function getClients(): array { - $json = $this->config->getAppValue('clients_json', AppInfo::APP_NAME); + $json = $this->config->getAppValue('clients_json', Application::APP_NAME); if (empty($json)) { return []; } @@ -155,7 +156,7 @@ class GoogleAnalyticsService { * Get fresh access token */ private function getFreshAccessToken(): string { - $refreshToken = $this->config->getAppValue('google_refresh_token', AppInfo::APP_NAME); + $refreshToken = $this->config->getAppValue('google_refresh_token', Application::APP_NAME); if (empty($refreshToken)) { throw new \Exception('Refresh token not configured'); @@ -188,8 +189,8 @@ class GoogleAnalyticsService { * Refresh access token using refresh token */ private function refreshAccessToken(string $refreshToken): ?array { - $clientId = $this->config->getAppValue('google_client_id', AppInfo::APP_NAME); - $clientSecret = $this->config->getAppValue('google_client_secret', AppInfo::APP_NAME); + $clientId = $this->config->getAppValue('google_client_id', Application::APP_NAME); + $clientSecret = $this->config->getAppValue('google_client_secret', Application::APP_NAME); $url = self::TOKEN_REFRESH_URL; $data = [ diff --git a/analyticshub/lib/Service/LLMService.php b/analyticshub/lib/Service/LLMService.php index 9f1f928..7b3dbf6 100644 --- a/analyticshub/lib/Service/LLMService.php +++ b/analyticshub/lib/Service/LLMService.php @@ -32,7 +32,7 @@ class LLMService { * Check if LLM service is configured */ public function isConfigured(): bool { - $apiKey = $this->config->getAppValue('anthropic_api_key', AppInfo::APP_NAME); + $apiKey = $this->config->getAppValue('anthropic_api_key', Application::APP_NAME); return !empty($apiKey); } @@ -43,7 +43,7 @@ class LLMService { $this->logger->info("Generating LLM report for: {$client->getName()}"); try { - $apiKey = $this->config->getAppValue('anthropic_api_key', AppInfo::APP_NAME); + $apiKey = $this->config->getAppValue('anthropic_api_key', Application::APP_NAME); if (empty($apiKey)) { throw new \Exception('Anthropic API key not configured');