mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
sync logs :D
This commit is contained in:
@@ -16,9 +16,9 @@ class AdultSyncService extends BaseSyncService
|
||||
private int $newCount = 0;
|
||||
private int $updatedCount = 0;
|
||||
|
||||
public function __construct(PDO $pdo, array $source)
|
||||
public function __construct(PDO $pdo, array $source, ?int $existingSyncLogId = null)
|
||||
{
|
||||
parent::__construct($pdo, $source);
|
||||
parent::__construct($pdo, $source, $existingSyncLogId);
|
||||
|
||||
// Find XBVR and Stash sources
|
||||
$this->xbvrSource = $this->findSourceByName('xbvr');
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\SyncLog;
|
||||
use Exception;
|
||||
|
||||
abstract class BaseSyncService
|
||||
{
|
||||
protected \PDO $pdo;
|
||||
protected array $source;
|
||||
protected SyncLog $syncLog;
|
||||
protected int $sourceId;
|
||||
|
||||
protected $logFileHandle;
|
||||
protected $logFilePath;
|
||||
|
||||
public function __construct(\PDO $pdo, array $source)
|
||||
public function __construct(\PDO $pdo, array $source, ?int $existingSyncLogId = null)
|
||||
{
|
||||
$this->pdo = $pdo;
|
||||
$this->source = $source;
|
||||
@@ -25,6 +23,7 @@ abstract class BaseSyncService
|
||||
}
|
||||
|
||||
$this->sourceId = (int) $source['id'];
|
||||
$this->currentSyncLogId = $existingSyncLogId;
|
||||
|
||||
// Create log file for this sync operation
|
||||
$this->initializeLogFile();
|
||||
@@ -62,8 +61,19 @@ abstract class BaseSyncService
|
||||
ini_set('max_execution_time', 3600); // 1 hour
|
||||
ini_set('memory_limit', '512M');
|
||||
|
||||
// Create sync log entry
|
||||
$syncLogId = $this->createSyncLog($syncType, 'started');
|
||||
// Use existing sync log ID if provided, otherwise create a new one
|
||||
if ($this->currentSyncLogId) {
|
||||
$syncLogId = $this->currentSyncLogId;
|
||||
// Update the existing log to 'started' status
|
||||
$this->updateSyncLog($syncLogId, 'started', [
|
||||
'sync_type' => $syncType,
|
||||
'started_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
} else {
|
||||
// Create sync log entry
|
||||
$syncLogId = $this->createSyncLog($syncType, 'started');
|
||||
}
|
||||
|
||||
$this->currentSyncLogId = $syncLogId;
|
||||
|
||||
try {
|
||||
|
||||
@@ -15,9 +15,9 @@ class ExophaseSyncService extends BaseSyncService
|
||||
private int $newCount = 0;
|
||||
private int $updatedCount = 0;
|
||||
|
||||
public function __construct(\PDO $pdo, array $source)
|
||||
public function __construct(\PDO $pdo, array $source, ?int $existingSyncLogId = null)
|
||||
{
|
||||
parent::__construct($pdo, $source);
|
||||
parent::__construct($pdo, $source, $existingSyncLogId);
|
||||
$this->httpClient = new Client([
|
||||
'timeout' => 30,
|
||||
'headers' => [
|
||||
|
||||
@@ -18,9 +18,9 @@ class JellyfinSyncService extends BaseSyncService
|
||||
private int $newCount = 0;
|
||||
private int $updatedCount = 0;
|
||||
|
||||
public function __construct(\PDO $pdo, array $source)
|
||||
public function __construct(\PDO $pdo, array $source, ?int $existingSyncLogId = null)
|
||||
{
|
||||
parent::__construct($pdo, $source);
|
||||
parent::__construct($pdo, $source, $existingSyncLogId);
|
||||
$this->httpClient = new Client([
|
||||
'timeout' => 30,
|
||||
'headers' => [
|
||||
|
||||
@@ -18,9 +18,9 @@ class StashSyncService extends BaseSyncService
|
||||
private int $newCount = 0;
|
||||
private int $updatedCount = 0;
|
||||
|
||||
public function __construct(PDO $pdo, array $source)
|
||||
public function __construct(PDO $pdo, array $source, ?int $existingSyncLogId = null)
|
||||
{
|
||||
parent::__construct($pdo, $source);
|
||||
parent::__construct($pdo, $source, $existingSyncLogId);
|
||||
|
||||
// Initialize properties first before using them
|
||||
$this->apiKey = $source['api_key'];
|
||||
|
||||
@@ -15,9 +15,9 @@ class SteamSyncService extends BaseSyncService
|
||||
private int $newCount = 0;
|
||||
private int $updatedCount = 0;
|
||||
|
||||
public function __construct(\PDO $pdo, array $source)
|
||||
public function __construct(\PDO $pdo, array $source, ?int $existingSyncLogId = null)
|
||||
{
|
||||
parent::__construct($pdo, $source);
|
||||
parent::__construct($pdo, $source, $existingSyncLogId);
|
||||
$this->httpClient = new Client([
|
||||
'timeout' => 30,
|
||||
'headers' => [
|
||||
|
||||
@@ -16,9 +16,9 @@ class XbvrSyncService extends BaseSyncService
|
||||
private int $newCount = 0;
|
||||
private int $updatedCount = 0;
|
||||
|
||||
public function __construct(\PDO $pdo, array $source)
|
||||
public function __construct(\PDO $pdo, array $source, ?int $existingSyncLogId = null)
|
||||
{
|
||||
parent::__construct($pdo, $source);
|
||||
parent::__construct($pdo, $source, $existingSyncLogId);
|
||||
|
||||
// Initialize properties first before using them
|
||||
$this->baseUrl = rtrim($source['api_url'], '/');
|
||||
|
||||
Reference in New Issue
Block a user