actor sync

This commit is contained in:
Lars Behrends
2025-11-06 13:08:02 +01:00
parent 3f56625205
commit a44c311e89
14 changed files with 773 additions and 9 deletions

View File

@@ -489,6 +489,90 @@ class ActorController extends Controller
}
}
public function getMissingStashReports(Request $request, Response $response, $args)
{
try {
$logDir = __DIR__ . '/../../storage/logs';
$reports = [];
if (is_dir($logDir)) {
$files = glob($logDir . '/missing_stash_actors_*.json');
foreach ($files as $file) {
$filename = basename($file);
$fileData = json_decode(file_get_contents($file), true);
if ($fileData) {
$reports[] = [
'filename' => $filename,
'generated_at' => $fileData['generated_at'] ?? 'Unknown',
'total_missing' => $fileData['total_missing'] ?? 0,
'description' => $fileData['description'] ?? '',
'file_path' => $file
];
}
}
// Sort by generation date (newest first)
usort($reports, function($a, $b) {
return strtotime($b['generated_at']) <=> strtotime($a['generated_at']);
});
}
return $this->jsonResponse($response, [
'reports' => $reports,
'total_reports' => count($reports)
]);
} catch (\Exception $e) {
return $this->jsonResponse($response->withStatus(500), [
'error' => 'Internal server error: ' . $e->getMessage()
]);
}
}
public function syncExistingPerformers(Request $request, Response $response, $args)
{
// Set PHP timeouts for long-running operations
ini_set('memory_limit', '2G');
ini_set('max_execution_time', 0); // Allow unlimited execution time
ini_set('max_input_time', 3600); // 1 hour for input processing
ini_set('default_socket_timeout', 3600); // 1 hour for socket operations
// Set headers to prevent timeouts
$response = $response->withHeader('X-Accel-Buffering', 'no'); // Disable nginx buffering
try {
// Get Stash configuration from database
$stmt = $this->pdo->prepare('SELECT * FROM sources WHERE name = ?');
$stmt->execute(['stash']);
$stashSource = $stmt->fetch(\PDO::FETCH_ASSOC);
if (!$stashSource) {
return $this->jsonResponse($response->withStatus(500), [
'error' => 'Stash source not configured in database'
]);
}
// Create Stash sync service
$stashSyncService = new \App\Services\StashSyncService($this->pdo, $stashSource);
// Run the existing performers sync
$results = $stashSyncService->syncExistingPerformers();
return $this->jsonResponse($response, [
'success' => true,
'message' => 'Existing performers sync completed',
'results' => $results
]);
} catch (\Exception $e) {
return $this->jsonResponse($response->withStatus(500), [
'error' => 'Internal server error: ' . $e->getMessage()
]);
}
}
public function index(Request $request, Response $response, $args)
{
$queryParams = $request->getQueryParams();