debug
This commit is contained in:
@@ -291,6 +291,16 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
|
||||
$method = in_array($method, ['GET', 'POST'], true) ? $method : 'POST';
|
||||
|
||||
if ($apiKey === '') {
|
||||
module_debug_push('boersenchecker', [
|
||||
'label' => 'Bavest Request',
|
||||
'type' => 'api:error',
|
||||
'request' => [
|
||||
'method' => $method,
|
||||
'path' => $path,
|
||||
'payload' => $payload,
|
||||
],
|
||||
'message' => 'Bavest-API-Key fehlt. Bitte im Modul-Setup hinterlegen.',
|
||||
]);
|
||||
return [
|
||||
'ok' => false,
|
||||
'message' => 'Bavest-API-Key fehlt. Bitte im Modul-Setup hinterlegen.',
|
||||
@@ -366,6 +376,21 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
|
||||
}
|
||||
|
||||
if (!is_string($responseBody) || $responseBody === '') {
|
||||
module_debug_push('boersenchecker', [
|
||||
'label' => 'Bavest Request',
|
||||
'type' => 'api:error',
|
||||
'request' => [
|
||||
'method' => $method,
|
||||
'url' => $url,
|
||||
'payload' => $payload,
|
||||
],
|
||||
'response' => [
|
||||
'http_code' => $httpCode,
|
||||
'curl_error' => $curlError,
|
||||
'body' => null,
|
||||
],
|
||||
'message' => 'Bavest Anfrage fehlgeschlagen.',
|
||||
]);
|
||||
return [
|
||||
'ok' => false,
|
||||
'message' => 'Bavest Anfrage fehlgeschlagen.'
|
||||
@@ -376,6 +401,20 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
|
||||
|
||||
$decoded = json_decode($responseBody, true);
|
||||
if (!is_array($decoded)) {
|
||||
module_debug_push('boersenchecker', [
|
||||
'label' => 'Bavest Request',
|
||||
'type' => 'api:error',
|
||||
'request' => [
|
||||
'method' => $method,
|
||||
'url' => $url,
|
||||
'payload' => $payload,
|
||||
],
|
||||
'response' => [
|
||||
'http_code' => $httpCode,
|
||||
'body_preview' => substr($responseBody, 0, 4000),
|
||||
],
|
||||
'message' => 'Bavest Antwort ist kein gueltiges JSON.',
|
||||
]);
|
||||
return [
|
||||
'ok' => false,
|
||||
'message' => 'Bavest Antwort ist kein gueltiges JSON.',
|
||||
@@ -385,6 +424,20 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
|
||||
|
||||
foreach (['error', 'message', 'detail'] as $errorKey) {
|
||||
if (isset($decoded[$errorKey]) && is_string($decoded[$errorKey]) && trim($decoded[$errorKey]) !== '') {
|
||||
module_debug_push('boersenchecker', [
|
||||
'label' => 'Bavest Request',
|
||||
'type' => 'api:error',
|
||||
'request' => [
|
||||
'method' => $method,
|
||||
'url' => $url,
|
||||
'payload' => $payload,
|
||||
],
|
||||
'response' => [
|
||||
'http_code' => $httpCode,
|
||||
'body' => $decoded,
|
||||
],
|
||||
'message' => trim((string) $decoded[$errorKey]),
|
||||
]);
|
||||
return [
|
||||
'ok' => false,
|
||||
'message' => trim((string) $decoded[$errorKey]),
|
||||
@@ -393,6 +446,20 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
|
||||
}
|
||||
}
|
||||
|
||||
module_debug_push('boersenchecker', [
|
||||
'label' => 'Bavest Request',
|
||||
'type' => 'api:response',
|
||||
'request' => [
|
||||
'method' => $method,
|
||||
'url' => $url,
|
||||
'payload' => $payload,
|
||||
],
|
||||
'response' => [
|
||||
'http_code' => $httpCode,
|
||||
'body' => $decoded,
|
||||
],
|
||||
]);
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'data' => $decoded,
|
||||
@@ -769,3 +836,77 @@ $mm->registerFunction($moduleName, 'bavest_fetch_chart_series', static function
|
||||
'source' => 'bavest:timeseries/history',
|
||||
];
|
||||
});
|
||||
|
||||
$mm->registerFunction($moduleName, 'store_market_quote', static function (
|
||||
int $instrumentId,
|
||||
float $price,
|
||||
string $currency,
|
||||
string $quotedAt,
|
||||
string $source
|
||||
): array {
|
||||
$pdo = module_fn('boersenchecker', 'pdo');
|
||||
$quoteTable = module_fn('boersenchecker', 'table', 'quotes');
|
||||
|
||||
$quotedAt = trim($quotedAt);
|
||||
$currency = strtoupper(trim($currency)) ?: 'EUR';
|
||||
$source = trim($source) !== '' ? trim($source) : 'bavest:quote';
|
||||
|
||||
$checkStmt = $pdo->prepare(
|
||||
'SELECT id
|
||||
FROM ' . $quoteTable . '
|
||||
WHERE instrument_id = :instrument_id
|
||||
AND price = :price
|
||||
AND currency = :currency
|
||||
AND quoted_at = :quoted_at
|
||||
AND source = :source
|
||||
LIMIT 1'
|
||||
);
|
||||
$checkStmt->execute([
|
||||
'instrument_id' => $instrumentId,
|
||||
'price' => $price,
|
||||
'currency' => $currency,
|
||||
'quoted_at' => $quotedAt,
|
||||
'source' => $source,
|
||||
]);
|
||||
$existingId = (int) $checkStmt->fetchColumn();
|
||||
if ($existingId > 0) {
|
||||
module_debug_push('boersenchecker', [
|
||||
'label' => 'Quote Store',
|
||||
'type' => 'quote:reuse',
|
||||
'instrument_id' => $instrumentId,
|
||||
'price' => $price,
|
||||
'currency' => $currency,
|
||||
'quoted_at' => $quotedAt,
|
||||
'source' => $source,
|
||||
'message' => 'Identischer Snapshot bereits vorhanden.',
|
||||
]);
|
||||
return ['ok' => true, 'inserted' => false, 'id' => $existingId];
|
||||
}
|
||||
|
||||
$insertStmt = $pdo->prepare(
|
||||
'INSERT INTO ' . $quoteTable . ' (instrument_id, price, currency, quoted_at, source)
|
||||
VALUES (:instrument_id, :price, :currency, :quoted_at, :source)'
|
||||
);
|
||||
$insertStmt->execute([
|
||||
'instrument_id' => $instrumentId,
|
||||
'price' => $price,
|
||||
'currency' => $currency,
|
||||
'quoted_at' => $quotedAt,
|
||||
'source' => $source,
|
||||
]);
|
||||
|
||||
$insertedId = (int) $pdo->lastInsertId();
|
||||
module_debug_push('boersenchecker', [
|
||||
'label' => 'Quote Store',
|
||||
'type' => 'quote:insert',
|
||||
'instrument_id' => $instrumentId,
|
||||
'price' => $price,
|
||||
'currency' => $currency,
|
||||
'quoted_at' => $quotedAt,
|
||||
'source' => $source,
|
||||
'inserted_id' => $insertedId,
|
||||
'message' => 'Neuer Snapshot gespeichert.',
|
||||
]);
|
||||
|
||||
return ['ok' => true, 'inserted' => true, 'id' => $insertedId];
|
||||
});
|
||||
|
||||
@@ -427,14 +427,19 @@ final class DashboardPage
|
||||
throw new RuntimeException((string) ($apiResult['message'] ?? 'API-Abruf fehlgeschlagen.'));
|
||||
}
|
||||
|
||||
$this->storeQuote(
|
||||
$storeResult = \module_fn(
|
||||
'boersenchecker',
|
||||
'store_market_quote',
|
||||
$instrumentId,
|
||||
(float) $apiResult['price'],
|
||||
$quoteCurrency,
|
||||
(string) $apiResult['fetched_at'],
|
||||
(string) $apiResult['source']
|
||||
);
|
||||
return 'Bavest-Kurs fuer ' . (string) $row['instrument_name'] . ' gespeichert.';
|
||||
if (!empty($storeResult['inserted'])) {
|
||||
return 'Bavest-Kurs fuer ' . (string) $row['instrument_name'] . ' gespeichert.';
|
||||
}
|
||||
return 'Vorhandener Bavest-Snapshot fuer ' . (string) $row['instrument_name'] . ' wiederverwendet.';
|
||||
}
|
||||
|
||||
private function refreshMarketDataAll(): string
|
||||
@@ -499,14 +504,20 @@ final class DashboardPage
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->storeQuote(
|
||||
$storeResult = \module_fn(
|
||||
'boersenchecker',
|
||||
'store_market_quote',
|
||||
$instrumentId,
|
||||
(float) $apiResult['price'],
|
||||
$quoteCurrency,
|
||||
(string) $apiResult['fetched_at'],
|
||||
(string) $apiResult['source']
|
||||
);
|
||||
$fetched++;
|
||||
if (!empty($storeResult['inserted'])) {
|
||||
$fetched++;
|
||||
} else {
|
||||
$reused++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -157,25 +157,26 @@ final class HomePage
|
||||
if ($bulkCandidates !== []) {
|
||||
$bulkResult = \module_fn('boersenchecker', 'bavest_fetch_bulk_quotes', $bulkCandidates);
|
||||
$quotes = is_array($bulkResult['quotes'] ?? null) ? $bulkResult['quotes'] : [];
|
||||
$stmtInsert = $this->pdo->prepare(
|
||||
'INSERT INTO ' . $this->quoteTable . ' (instrument_id, price, currency, quoted_at, source)
|
||||
VALUES (:instrument_id, :price, :currency, :quoted_at, :source)'
|
||||
);
|
||||
|
||||
foreach ($bulkCandidates as $row) {
|
||||
$instrumentId = (int) ($row['id'] ?? 0);
|
||||
$quote = $quotes[$instrumentId] ?? null;
|
||||
if (!is_array($quote) || !is_numeric($quote['price'] ?? null)) {
|
||||
continue;
|
||||
}
|
||||
$stmtInsert->execute([
|
||||
'instrument_id' => $instrumentId,
|
||||
'price' => (float) $quote['price'],
|
||||
'currency' => strtoupper(trim((string) ($quote['currency'] ?? $row['quote_currency'] ?? $this->defaultReportCurrency))) ?: $this->defaultReportCurrency,
|
||||
'quoted_at' => (string) ($quote['fetched_at'] ?? date('Y-m-d H:i:s')),
|
||||
'source' => (string) ($quote['source'] ?? 'bavest:quote'),
|
||||
]);
|
||||
$updated++;
|
||||
$storeResult = \module_fn(
|
||||
'boersenchecker',
|
||||
'store_market_quote',
|
||||
$instrumentId,
|
||||
(float) $quote['price'],
|
||||
strtoupper(trim((string) ($quote['currency'] ?? $row['quote_currency'] ?? $this->defaultReportCurrency))) ?: $this->defaultReportCurrency,
|
||||
(string) ($quote['fetched_at'] ?? gmdate('Y-m-d H:i:s')),
|
||||
(string) ($quote['source'] ?? 'bavest:quote')
|
||||
);
|
||||
if (!empty($storeResult['inserted'])) {
|
||||
$updated++;
|
||||
} else {
|
||||
$reused++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -224,19 +224,19 @@ final class InstrumentPage
|
||||
throw new RuntimeException((string) ($apiResult['message'] ?? 'API-Abruf fehlgeschlagen.'));
|
||||
}
|
||||
|
||||
$stmtInsert = $this->pdo->prepare(
|
||||
'INSERT INTO ' . $this->quoteTable . ' (instrument_id, price, currency, quoted_at, source)
|
||||
VALUES (:instrument_id, :price, :currency, :quoted_at, :source)'
|
||||
$storeResult = \module_fn(
|
||||
'boersenchecker',
|
||||
'store_market_quote',
|
||||
$instrumentId,
|
||||
(float) $apiResult['price'],
|
||||
strtoupper(trim((string) ($instrument['quote_currency'] ?? $this->defaultReportCurrency))) ?: $this->defaultReportCurrency,
|
||||
(string) $apiResult['fetched_at'],
|
||||
(string) $apiResult['source']
|
||||
);
|
||||
$stmtInsert->execute([
|
||||
'instrument_id' => $instrumentId,
|
||||
'price' => (float) $apiResult['price'],
|
||||
'currency' => strtoupper(trim((string) ($instrument['quote_currency'] ?? $this->defaultReportCurrency))) ?: $this->defaultReportCurrency,
|
||||
'quoted_at' => (string) $apiResult['fetched_at'],
|
||||
'source' => (string) $apiResult['source'],
|
||||
]);
|
||||
|
||||
return 'Bavest-Kurs gespeichert.';
|
||||
return !empty($storeResult['inserted'])
|
||||
? 'Bavest-Kurs gespeichert.'
|
||||
: 'Vorhandener Bavest-Snapshot wiederverwendet.';
|
||||
}
|
||||
|
||||
private function searchSymbol(): string
|
||||
|
||||
Reference in New Issue
Block a user