nhance/app/Helpers/tpa_claim_push_log_helper.php

49 lines
1.4 KiB
PHP

<?php
if (!function_exists('init_tpa_claim_push_logs')) {
/**
* Reset claim push logs for a ticket before a new push attempt.
*/
function init_tpa_claim_push_logs($claimId): void
{
if ($claimId === null || $claimId === '') {
return;
}
$started = date('Y-m-d H:i:s');
\Config\Database::connect()
->table('ticket_master')
->where('id', $claimId)
->update(['tpa_claim_push_logs' => "[{$started}] Claim push started\n"]);
}
}
if (!function_exists('tpa_claim_push_log')) {
/**
* Write to application log and append the same line to ticket_master.tpa_claim_push_logs.
*/
function tpa_claim_push_log($claimId, string $message, string $level = 'error'): void
{
log_message($level, $message);
if ($claimId === null || $claimId === '') {
return;
}
$timestamp = date('Y-m-d H:i:s');
$line = "[{$timestamp}] {$message}\n";
$db = \Config\Database::connect();
$row = $db->table('ticket_master')
->select('tpa_claim_push_logs')
->where('id', $claimId)
->get()
->getRowArray();
$existing = $row['tpa_claim_push_logs'] ?? '';
$db->table('ticket_master')
->where('id', $claimId)
->update(['tpa_claim_push_logs' => $existing . $line]);
}
}