0.9.7.23: Verbindungsbezogenen Live-Status bereitstellen

This commit is contained in:
Terranom674
2026-08-20 08:32:23 +02:00
parent 26b602783f
commit df9e9e6424

View File

@@ -24,6 +24,7 @@ if (!function_exists('is_admin') || !is_admin())
exit; exit;
} }
$requested_connection_id = isset($_GET['connection_id']) ? max(0, (int)$_GET['connection_id']) : 0;
$dir = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-connector-status'; $dir = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-connector-status';
$latest = array( $latest = array(
'state'=>'idle', 'state'=>'idle',
@@ -41,11 +42,16 @@ $latest = array(
'route_timestamp'=>0, 'route_timestamp'=>0,
'route_time_label'=>'Nicht verfügbar', 'route_time_label'=>'Nicht verfügbar',
'route_detail'=>'', 'route_detail'=>'',
'connection_id'=>$requested_connection_id,
); );
if (is_dir($dir)) if (is_dir($dir))
{ {
foreach (glob($dir.'/connection-*.json') ?: array() as $file) $files = $requested_connection_id > 0
? array($dir.'/connection-'.$requested_connection_id.'.json')
: (glob($dir.'/connection-*.json') ?: array());
foreach ($files as $file)
{ {
if (!is_readable($file)) if (!is_readable($file))
{ {
@@ -63,6 +69,8 @@ if (is_dir($dir))
} }
} }
if ($requested_connection_id === 0)
{
$route_file = $dir.'/route-status.json'; $route_file = $dir.'/route-status.json';
if (is_readable($route_file)) if (is_readable($route_file))
{ {
@@ -111,10 +119,6 @@ if (is_dir($dir))
} }
} }
} }
if ((int)$latest['timestamp'] > 0)
{
$latest['last_run_label'] = date('d.m.Y H:i:s', (int)$latest['timestamp']);
} }
$system_file = BRATONIEN_TOOLS_PATH.'include/nc_connector_system.inc.php'; $system_file = BRATONIEN_TOOLS_PATH.'include/nc_connector_system.inc.php';
@@ -129,4 +133,27 @@ if (is_readable($system_file))
} }
} }
$scheduler_file = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-connector-scheduler/state.json';
if ($requested_connection_id > 0 && is_readable($scheduler_file))
{
$scheduler = json_decode((string)@file_get_contents($scheduler_file), true);
if (
is_array($scheduler)
&& (int)($scheduler['connection_id'] ?? 0) === $requested_connection_id
&& in_array((string)($scheduler['state'] ?? ''), array('queued','running'), true)
&& (int)($scheduler['timestamp'] ?? 0) >= (int)($latest['timestamp'] ?? 0)
)
{
$latest['state'] = (string)$scheduler['state'];
$latest['message'] = (string)($scheduler['message'] ?? 'NC-Abgleich läuft.');
$latest['timestamp'] = (int)($scheduler['timestamp'] ?? time());
$latest['error_detail'] = '';
}
}
if ((int)$latest['timestamp'] > 0)
{
$latest['last_run_label'] = date('d.m.Y H:i:s', (int)$latest['timestamp']);
}
echo json_encode($latest, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); echo json_encode($latest, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);