pdo = $pdo; } public function index(Request $request, Response $response, $args) { $sourceModel = new Source($this->pdo); $sources = $sourceModel->findAll(); $syncLogModel = new SyncLog($this->pdo); $recentSyncs = SyncLog::getRecent($this->pdo, 10); return $this->view->render($response, 'admin/index.twig', [ 'title' => 'Admin Dashboard', 'sources' => $sources, 'recent_syncs' => $recentSyncs ]); } public function syncSource(Request $request, Response $response, $args) { $sourceId = $args['id']; $syncType = $request->getQueryParams()['type'] ?? 'full'; $sourceModel = new Source($this->pdo); $source = $sourceModel->find($sourceId); if (!$source) { return $response->withStatus(404)->withHeader('Content-Type', 'application/json'); } // Start sync in background (simplified - in production you'd use queues) $syncLogId = $this->startSync($source, $syncType); return $this->json($response, [ 'success' => true, 'sync_log_id' => $syncLogId, 'message' => 'Sync started successfully' ]); } public function syncStatus(Request $request, Response $response, $args) { $syncLogId = $args['id']; $syncLogModel = new SyncLog($this->pdo); $syncLog = $syncLogModel->find($syncLogId); if (!$syncLog) { return $response->withStatus(404)->withHeader('Content-Type', 'application/json'); } return $this->json($response, [ 'id' => $syncLog['id'], 'status' => $syncLog['status'], 'sync_type' => $syncLog['sync_type'], 'total_items' => $syncLog['total_items'], 'processed_items' => $syncLog['processed_items'], 'new_items' => $syncLog['new_items'], 'updated_items' => $syncLog['updated_items'], 'deleted_items' => $syncLog['deleted_items'], 'started_at' => $syncLog['started_at'], 'completed_at' => $syncLog['completed_at'], 'message' => $syncLog['message'], 'errors' => $syncLog['errors'] ? json_decode($syncLog['errors'], true) : [] ]); } public function sources(Request $request, Response $response, $args) { $sourceModel = new Source($this->pdo); $sources = $sourceModel->findAll(); return $this->view->render($response, 'admin/sources.twig', [ 'title' => 'Source Management', 'sources' => $sources ]); } private function startSync(array $source, string $syncType): int { // Create appropriate sync service based on source type switch ($source['name']) { case 'steam': $syncService = new SteamSyncService($this->pdo, $source); break; case 'jellyfin': $syncService = new JellyfinSyncService($this->pdo, $source); break; case 'stash': $syncService = new StashSyncService($this->pdo, $source); break; case 'adult': $syncService = new AdultSyncService($this->pdo, $source); break; case 'exophase': $syncService = new ExophaseSyncService($this->pdo, $source); break; default: throw new \Exception('Unsupported source type: ' . $source['name']); } // Start sync (this would typically be queued in production) return $syncService->startSync($syncType); } }