gaService = $gaService; } protected function run($argument) { $dayOfWeek = date('N'); // Only run Mon-Fri (1-5) if ($dayOfWeek < 1 || $dayOfWeek > 5) { Util::writeLog('Skipping daily report (weekend)'); return; } Util::writeLog('Starting daily report generation'); try { // Generate reports for all active clients $results = $this->gaService->generateForAllClients(); // Log summary $success = count(array_filter($results, fn($r) => $r === 'success')); $total = count($results); Util::writeLog("Daily reports complete: {$success}/{$total} successful"); if ($success === $total) { Util::writeLog('All reports generated successfully'); } else { Util::writeLog('Some reports failed', LogLevel::WARN); } } catch (TokenExpiredException $e) { Util::writeLog('❌ CRITICAL: Refresh token expired - re-run OAuth setup', LogLevel::ERROR); } catch (RateLimitException $e) { Util::writeLog('⚠️ WARNING: Rate limit exceeded', LogLevel::WARN); } catch (\Exception $e) { Util::writeLog("Daily report generation failed: {$e->getMessage()}", LogLevel::ERROR); } } protected function getScheduledTime(): string { // Mon-Fri at 7:00 AM return '07:00'; } protected function getInterval(): int { // Daily return 86400; // 24 hours in seconds } } /** * Register cron jobs */ return [ 'app_id' => AppInfo::APP_NAME, 'jobs' => [ [ 'class' => DailyReportJob::class, 'name' => 'OCA\AnalyticsHub\Cron\DailyReportJob', ], ], ];