ver. 0.309: ApiloLogger + cache-busting CSS/JS + poprawki UI
- ApiloLogger: logowanie operacji Apilo do pp_log z kontekstem JSON - Cache-busting: ?ver=filemtime() dla CSS i JS w admin main-layout - Fix: inicjalizacja $mdb przed SettingsRepository w admin/index.php - Fix: rzutowanie (string) w ShopProductController::escapeHtml() - UI: text-overflow ellipsis dla kategorii produktow + title tooltip - JS: navigator.clipboard API w copyToClipboard() z fallbackiem - CSS: uproszczenie .site-content, usuniecie .with-menu - Migracja: pp_log + kolumny action, order_id, context Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
30
autoload/Domain/Integrations/ApiloLogger.php
Normal file
30
autoload/Domain/Integrations/ApiloLogger.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Domain\Integrations;
|
||||
|
||||
class ApiloLogger
|
||||
{
|
||||
/**
|
||||
* @param \medoo $db
|
||||
* @param string $action np. 'send_order', 'payment_sync', 'status_sync', 'status_poll'
|
||||
* @param int|null $orderId
|
||||
* @param string $message
|
||||
* @param mixed $context dane do zapisania jako JSON (request/response)
|
||||
*/
|
||||
public static function log($db, string $action, ?int $orderId, string $message, $context = null): void
|
||||
{
|
||||
$contextJson = null;
|
||||
if ($context !== null) {
|
||||
$contextJson = is_string($context)
|
||||
? $context
|
||||
: json_encode($context, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
$db->insert('pp_log', [
|
||||
'action' => $action,
|
||||
'order_id' => $orderId,
|
||||
'message' => $message,
|
||||
'context' => $contextJson,
|
||||
'date' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -425,13 +425,29 @@ class OrderAdminService
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$apiloResultRaw = curl_exec($ch);
|
||||
$http_code = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$apiloResult = json_decode((string)$apiloResultRaw, true);
|
||||
|
||||
if (!is_array($apiloResult) || (int)($apiloResult['updates'] ?? 0) !== 1) {
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$mdb,
|
||||
'resend_order',
|
||||
$orderId,
|
||||
'Błąd ponownego wysyłania zamówienia do Apilo (HTTP: ' . $http_code . ')',
|
||||
['apilo_order_id' => $order['apilo_order_id'], 'http_code' => $http_code, 'response' => $apiloResult]
|
||||
);
|
||||
curl_close($ch);
|
||||
return false;
|
||||
}
|
||||
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$mdb,
|
||||
'resend_order',
|
||||
$orderId,
|
||||
'Zamówienie ponownie wysłane do Apilo (apilo_order_id: ' . $order['apilo_order_id'] . ')',
|
||||
['apilo_order_id' => $order['apilo_order_id'], 'http_code' => $http_code, 'response' => $apiloResult]
|
||||
);
|
||||
|
||||
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'pp_shop_orders' AND COLUMN_NAME != 'id'";
|
||||
$stmt = $mdb->query($query);
|
||||
$columns = $stmt ? $stmt->fetchAll(\PDO::FETCH_COLUMN) : [];
|
||||
@@ -685,6 +701,23 @@ class OrderAdminService
|
||||
self::appendApiloLog("PAYMENT RESPONSE\nHTTP: " . $http_code . "\nCURL: " . $curl_error . "\n" . print_r($apilo_response, true));
|
||||
}
|
||||
|
||||
$success = ($curl_error === '' && $http_code >= 200 && $http_code < 300);
|
||||
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$db,
|
||||
'payment_sync',
|
||||
(int)$order['id'],
|
||||
$success
|
||||
? 'Płatność zsynchronizowana z Apilo (apilo_order_id: ' . $order['apilo_order_id'] . ')'
|
||||
: 'Błąd synchronizacji płatności (HTTP: ' . $http_code . ($curl_error ? ', cURL: ' . $curl_error : '') . ')',
|
||||
[
|
||||
'apilo_order_id' => $order['apilo_order_id'],
|
||||
'http_code' => $http_code,
|
||||
'curl_error' => $curl_error,
|
||||
'response' => json_decode((string)$apilo_response, true),
|
||||
]
|
||||
);
|
||||
|
||||
if ($curl_error !== '') return false;
|
||||
if ($http_code < 200 || $http_code >= 300) return false;
|
||||
|
||||
@@ -729,6 +762,24 @@ class OrderAdminService
|
||||
self::appendApiloLog("STATUS RESPONSE\nHTTP: " . $http_code . "\nCURL: " . $curl_error . "\n" . print_r($apilo_result, true));
|
||||
}
|
||||
|
||||
$success = ($curl_error === '' && $http_code >= 200 && $http_code < 300);
|
||||
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$db,
|
||||
'status_sync',
|
||||
(int)$order['id'],
|
||||
$success
|
||||
? 'Status zsynchronizowany z Apilo (apilo_order_id: ' . $order['apilo_order_id'] . ', status: ' . $status . ')'
|
||||
: 'Błąd synchronizacji statusu (HTTP: ' . $http_code . ($curl_error ? ', cURL: ' . $curl_error : '') . ')',
|
||||
[
|
||||
'apilo_order_id' => $order['apilo_order_id'],
|
||||
'status' => $status,
|
||||
'http_code' => $http_code,
|
||||
'curl_error' => $curl_error,
|
||||
'response' => json_decode((string)$apilo_result, true),
|
||||
]
|
||||
);
|
||||
|
||||
if ($curl_error !== '') return false;
|
||||
if ($http_code < 200 || $http_code >= 300) return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user