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.
This commit is contained in:
25
analyticshub/appinfo/Application.php
Normal file
25
analyticshub/appinfo/Application.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\AnalyticsHub\AppInfo;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\Util;
|
||||
|
||||
/**
|
||||
* Application class for Mini-CMO Analytics Hub
|
||||
*/
|
||||
class Application extends App {
|
||||
|
||||
public const APP_NAME = 'analyticshub';
|
||||
public const APP_ID = 'analyticshub';
|
||||
|
||||
public function __construct(array $urlParams = []) {
|
||||
parent::__construct(self::APP_ID, $urlParams);
|
||||
|
||||
// Load scripts and styles
|
||||
Util::addStyle(self::APP_ID, 'admin');
|
||||
Util::addScript(self::APP_ID, 'admin');
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\AnalyticsHub;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
use OCA\AnalyticsHub\Controller\ApiV1Controller;
|
||||
use OCP\AnalyticsHub\Controller\ReportController;
|
||||
use OCP\AnalyticsHub\Service\GoogleAnalyticsService;
|
||||
use OCP\AnalyticsHub\Service\LLMService;
|
||||
use OCP\AnalyticsHub\Service\DataProcessor;
|
||||
|
||||
class App extends App {
|
||||
|
||||
public const APP_NAME = 'analytics_hub';
|
||||
|
||||
public function __construct(array $urlParams = []) {
|
||||
parent::__construct(self::APP_NAME, $urlParams);
|
||||
|
||||
// Register services
|
||||
$this->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();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user