mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
...
This commit is contained in:
136
test_stash.php
Normal file
136
test_stash.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Stash Connectivity Test
|
||||
*
|
||||
* Tests if the Stash server is reachable and responding properly.
|
||||
*/
|
||||
|
||||
// Check if we're in the right directory
|
||||
if (!file_exists('app/Services/StashSyncService.php')) {
|
||||
echo "Error: Please run this script from the project root directory.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
// Load environment variables
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->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";
|
||||
}
|
||||
Reference in New Issue
Block a user