Fixes: Simplify PageController, fix config API, update deployment package (2026-02-17)

- Removed service dependencies from PageController constructor
- Fixed AdminController config API signatures
- Cleaned up Application.php resource loading
- Updated template with proper resource includes
- Simplified routes.php
- Reduced analyticshub.zip from 50KB to 27KB
- Status: Fixed and ready for redeployment
This commit is contained in:
WLTBAgent
2026-02-22 06:56:57 +00:00
parent 69dfdc5f87
commit 49b6b37277
8 changed files with 94 additions and 59 deletions

View File

@@ -7,81 +7,77 @@ namespace OCA\AnalyticsHub\Controller;
use OCP\IRequest;
use OCP\IConfig;
use OCP\AppFramework\Http\TemplateResponse;
use OCA\AnalyticsHub\Service\GoogleAnalyticsService;
use OCA\AnalyticsHub\Service\LLMService;
/**
* Admin Settings Controller
*
* @NoAdminRequired
* @AdminRequired
* @NoCSRFRequired
*/
class PageController extends \OCP\AppFramework\Controller {
protected $appName;
protected $config;
protected $gaService;
protected $llmService;
public function __construct(
string $appName,
IRequest $request,
IConfig $config,
GoogleAnalyticsService $gaService,
LLMService $llmService
IConfig $config
) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->config = $config;
$this->gaService = $gaService;
$this->llmService = $llmService;
}
/**
* Index page - render admin UI
*
* @NoAdminRequired
* @AdminRequired
* @NoCSRFRequired
*/
public function index(): TemplateResponse {
// Check configuration status gracefully
$isConfigured = false;
$isGAConfigured = false;
$isLLMConfigured = false;
// Get configuration values directly from config service
$clientId = $this->config->getAppValue('analyticshub', 'google_client_id', '');
$clientSecret = $this->config->getAppValue('analyticshub', 'google_client_secret', '');
$refreshToken = $this->config->getAppValue('analyticshub', 'google_refresh_token', '');
$apiKey = $this->config->getAppValue('analyticshub', 'anthropic_api_key', '');
$llmEndpoint = $this->config->getAppValue('analyticshub', 'llm_api_endpoint', '');
$llmModel = $this->config->getAppValue('analyticshub', 'llm_model', '');
try {
$isGAConfigured = $this->gaService->isConfigured();
$isLLMConfigured = $this->llmService->isConfigured();
$isConfigured = $isGAConfigured && $isLLMConfigured;
} catch (\Exception $e) {
// If service initialization fails, app is not configured
$isConfigured = false;
// Check if configured
$isConfigured = !empty($clientId) && !empty($clientSecret) && !empty($refreshToken) && !empty($apiKey);
$isGAConfigured = !empty($clientId) && !empty($clientSecret) && !empty($refreshToken);
$isLLMConfigured = !empty($apiKey);
// Mask secrets for display
$maskedClientSecret = '';
if (!empty($clientSecret)) {
$maskedClientSecret = '••••••••••••••••';
}
// Get configuration values (masked for secrets)
$clientId = $this->config->getAppValue('google_client_id', 'analyticshub', '');
$apiKey = $this->config->getAppValue('anthropic_api_key', 'analyticshub', '');
$llmEndpoint = $this->config->getAppValue('llm_api_endpoint', 'analyticshub', '');
$llmModel = $this->config->getAppValue('llm_model', 'analyticshub', '');
$maskedRefreshToken = '';
if (!empty($refreshToken)) {
$maskedRefreshToken = substr($refreshToken, 0, 8) . '...' . substr($refreshToken, -4);
}
// Mask API key for display
$maskedApiKey = '';
if (!empty($apiKey)) {
$maskedApiKey = substr($apiKey, 0, 8) . '...' . substr($apiKey, -4);
}
return new TemplateResponse($this->appName, 'admin', [
'app_name' => $this->appName,
return new TemplateResponse('analyticshub', 'admin', [
'app_name' => 'Mini-CMO Analytics Hub',
'version' => '1.0.0',
'status' => 'Ready for development',
'status' => $isConfigured ? 'Ready' : 'Configuration Required',
'is_configured' => $isConfigured,
'is_ga_configured' => $isGAConfigured,
'is_llm_configured' => $isLLMConfigured,
'google_client_id' => $clientId,
'google_client_secret_masked' => $maskedClientSecret,
'google_refresh_token_masked' => $maskedRefreshToken,
'llm_api_endpoint' => $llmEndpoint,
'llm_model' => $llmModel,
'anthropic_api_key_masked' => $maskedApiKey,
'request' => $this->request,
]);
], 'blank'); // Use 'blank' rendering mode for admin pages
}
}