mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
118 lines
3.4 KiB
PHP
118 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
class PlayniteSyncService extends BaseSyncService
|
|
{
|
|
private PlayniteImportService $importService;
|
|
private array $importResults = [
|
|
'imported' => 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'] ?? [])
|
|
);
|
|
}
|
|
}
|