0, 'updated' => 0, 'skipped' => 0, 'errors' => [] ]; public function __construct(\PDO $pdo, array $source, ?int $existingSyncLogId = null) { parent::__construct($pdo, $source, $existingSyncLogId); $this->importService = new PlayniteImportService($pdo); } /** * Execute the sync process */ protected function executeSync(string $syncType): void { $this->logProgress("Starting Playnite import process"); try { // Get the import data from session if (!isset($_SESSION['playnite_import'])) { $this->logProgress($_SESSION); $this->logProgress("No Playnite import data found in session"); throw new \Exception('No Playnite import data found in session'); } $importData = $_SESSION['playnite_import']; $games = $importData['preview_data']['games'] ?? []; $this->logProgress(sprintf('Found %d games to import', count($games))); $this->totalItems = count($games); // Import the games $this->importResults = $this->importService->importGames( $games, true, // Always update existing function($message) { $this->logProgress($message); } ); $this->logProgress(sprintf( 'Import completed: %d imported, %d updated, %d skipped, %d errors', $this->importResults['imported'] ?? 0, $this->importResults['updated'] ?? 0, $this->importResults['skipped'] ?? 0, count($this->importResults['errors'] ?? []) )); // Log any errors foreach ($this->importResults['errors'] as $error) { $this->logProgress("ERROR: $error"); } } catch (\Exception $e) { $this->logProgress("ERROR: " . $e->getMessage()); throw $e; } } /** * Get the number of processed items */ public function getProcessedCount(): int { return ($this->importResults['imported'] ?? 0) + ($this->importResults['updated'] ?? 0) + ($this->importResults['skipped'] ?? 0); } /** * Get the number of new items */ public function getNewCount(): int { return $this->importResults['imported'] ?? 0; } /** * Get the number of updated items */ public function getUpdatedCount(): int { return $this->importResults['updated'] ?? 0; } /** * Get the number of deleted items */ public function getDeletedCount(): int { return 0; // Playnite import doesn't handle deletions } /** * Get a completion message */ public function getCompletionMessage(): string { return sprintf( 'Playnite import completed: %d imported, %d updated, %d skipped, %d errors', $this->importResults['imported'] ?? 0, $this->importResults['updated'] ?? 0, $this->importResults['skipped'] ?? 0, count($this->importResults['errors'] ?? []) ); } }