Fix: Rename app folder to match app ID
- Renamed analytics-hub/ → analyticshub/ - App ID in info.xml is 'analyticshub' (no hyphen) - Nextcloud requires folder name to match app ID exactly - Fixes 'Could not download app analyticshub' error during installation Installation: - Upload analyticshub/ folder to /var/www/nextcloud/apps/ - Folder name must match app ID in info.xml
This commit is contained in:
83
analyticshub/lib/Controller/ReportController.php
Normal file
83
analyticshub/lib/Controller/ReportController.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\AnalyticsHub\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http;
|
||||
|
||||
use OCA\AnalyticsHub\Service\GoogleAnalyticsService;
|
||||
use OCA\AnalyticsHub\Service\LLMService;
|
||||
use OCA\AnalyticsHub\Service\DataProcessor;
|
||||
use OCA\AnalyticsHub\Model\ClientConfig;
|
||||
|
||||
/**
|
||||
* Report Controller - Internal report generation logic
|
||||
*/
|
||||
class ReportController {
|
||||
|
||||
private GoogleAnalyticsService $gaService;
|
||||
private LLMService $llmService;
|
||||
private DataProcessor $dataProcessor;
|
||||
|
||||
public function __construct(
|
||||
GoogleAnalyticsService $gaService,
|
||||
LLMService $llmService,
|
||||
DataProcessor $dataProcessor
|
||||
) {
|
||||
$this->gaService = $gaService;
|
||||
$this->llmService = $llmService;
|
||||
$this->dataProcessor = $dataProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate report for a specific client
|
||||
* Called by cron job
|
||||
*/
|
||||
public function generateForClient(ClientConfig $client): ?string {
|
||||
\OCP\Util::writeLog("Generating report for: {$client->getName()}");
|
||||
|
||||
try {
|
||||
// Fetch GA4 data (last 7 days)
|
||||
$rawData = $this->gaService->fetchGA4Data($client, '7d');
|
||||
|
||||
// Process and validate
|
||||
$processed = $this->dataProcessor->process($rawData, $client);
|
||||
|
||||
// Generate report via LLM
|
||||
$markdown = $this->llmService->generate($processed, $client);
|
||||
|
||||
// Save to Nextcloud
|
||||
$report = $this->gaService->saveReport($client, $markdown);
|
||||
|
||||
\OCP\Util::writeLog("Report generated: {$report->getFilePath()}");
|
||||
|
||||
return $markdown;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\OCP\Util::writeLog("Report generation failed for {$client->getName()}: {$e->getMessage()}");
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate reports for all active clients
|
||||
* Called by cron job
|
||||
*/
|
||||
public function generateForAllClients(): array {
|
||||
$clients = $this->gaService->getActiveClients();
|
||||
$results = [];
|
||||
|
||||
foreach ($clients as $client) {
|
||||
try {
|
||||
$this->generateForClient($client);
|
||||
$results[$client->getSlug()] = 'success';
|
||||
} catch (\Exception $e) {
|
||||
$results[$client->getSlug()] = "error: {$e->getMessage()}";
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user