load(); // Load database configuration $dbConfig = require __DIR__ . '/config/database.php'; \App\Database\Database::setConfig($dbConfig); // Initialize database try { $pdo = \App\Database\Database::getInstance(); echo "āœ… Database connection successful\n"; // Get Stash source $stmt = $pdo->prepare('SELECT * FROM sources WHERE name = ?'); $stmt->execute(['stash']); $stashSource = $stmt->fetch(PDO::FETCH_ASSOC); if (!$stashSource) { echo "āŒ No Stash source found in database\n"; exit(1); } echo "šŸ” Testing Stash server connectivity...\n"; echo " URL: {$stashSource['api_url']}\n"; echo " API Key: " . (empty($stashSource['api_key']) ? 'NOT SET' : 'SET') . "\n\n"; // Test basic connectivity $client = new GuzzleHttp\Client([ 'timeout' => 10, 'verify' => false // Disable SSL verification for testing ]); try { $response = $client->get($stashSource['api_url'], [ 'headers' => [ 'User-Agent' => 'MediaCollector/1.0', 'ApiKey' => $stashSource['api_key'] ?? '' ] ]); echo "āœ… Stash server is reachable\n"; echo " Status: {$response->getStatusCode()}\n"; echo " Response received successfully\n"; // Test GraphQL endpoint echo "\nšŸ” Testing GraphQL endpoint...\n"; $query = ' query FindScenes($filter: FindFilterType) { findScenes(filter: $filter) { count scenes { id title } } } '; $variables = [ 'filter' => [ 'per_page' => 1, 'page' => 1, 'sort' => 'created_at', 'direction' => 'DESC' ] ]; $response = $client->post("{$stashSource['api_url']}/graphql", [ 'json' => [ 'query' => $query, 'variables' => $variables ], 'headers' => [ 'User-Agent' => 'MediaCollector/1.0', 'ApiKey' => $stashSource['api_key'] ?? '', 'Content-Type' => 'application/json' ], 'timeout' => 15 ]); $data = json_decode($response->getBody(), true); if (isset($data['data']['findScenes'])) { $count = $data['data']['findScenes']['count']; echo "āœ… GraphQL endpoint working\n"; echo " Total scenes in Stash: {$count}\n"; if ($count > 0) { $firstScene = $data['data']['findScenes']['scenes'][0] ?? null; if ($firstScene) { echo " First scene: {$firstScene['title']} (ID: {$firstScene['id']})\n"; } } } else { echo "āŒ GraphQL response format unexpected\n"; echo " Response: " . json_encode($data) . "\n"; } } catch (GuzzleHttp\Exception\RequestException $e) { echo "āŒ Failed to connect to Stash server\n"; echo " Error: " . $e->getMessage() . "\n"; if ($e->hasResponse()) { $response = $e->getResponse(); echo " Status: {$response->getStatusCode()}\n"; echo " Response: " . $response->getBody() . "\n"; } echo "\nšŸ’” Troubleshooting tips:\n"; echo " 1. Check if Stash server is running\n"; echo " 2. Verify the API URL is correct\n"; echo " 3. Check if API key is required and correct\n"; echo " 4. Ensure the server is accessible from this machine\n"; } } catch (Exception $e) { echo "āŒ Error: " . $e->getMessage() . "\n"; }