MSIN-4328 — Introduce verbose logging option in the ChronoTrack API for detailed entry logs. Update push panel UI to include a checkbox for verbose logs and adjust related functions to conditionally log detailed information based on user selection. Increment version code.

This commit is contained in:
2026-07-22 21:49:57 -04:00
parent ab063aeb23
commit 1306770f2e
3 changed files with 42 additions and 9 deletions

View File

@ -460,8 +460,13 @@ function fxChronotrackApiAdminRenderPushPanel($intEveId, $blnClosed = false, $ar
echo '<button type="button" class="btn btn-outline-dark btn-sm" id="ct_api_btn_logs">';
echo '<i class="fa fa-list" aria-hidden="true"></i>&nbsp;Voir les logs</button>';
echo '</div>';
echo '<div class="form-check mb-2">';
echo '<input class="form-check-input" type="checkbox" id="ct_api_verbose_logs" value="1">';
echo '<label class="form-check-label small" for="ct_api_verbose_logs">'
. 'Logs détaillés (1 ligne par participant) — sinon résumé par lot seulement</label>';
echo '</div>';
echo '<p class="small text-muted mb-2"><strong>Envoyer</strong> = nouveaux / modifiés. '
. '<strong>Tout renvoyer</strong> = tous les éligibles (même barre %). Logs à chaque envoi.</p>';
. '<strong>Tout renvoyer</strong> = tous les éligibles (même barre %).</p>';
echo '<div id="ct_api_push_result" class="ct-api-push-result small mb-3"></div>';
echo '<div id="ct_api_logs_wrap" class="mb-3 d-none"></div>';
@ -1971,7 +1976,8 @@ function fxChronotrackApiAdminRenderPageScript($intEveId, $arrConfig, $blnClosed
data: {
a: 'sync_push_prepare',
eve_id: intEveId,
force_full: blnForceFull ? 1 : 0
force_full: blnForceFull ? 1 : 0,
verbose_logs: $('#ct_api_verbose_logs').is(':checked') ? 1 : 0
}
}).done(function (prep) {
if (rejectIfSessionLost(prep)) {

View File

@ -1153,11 +1153,23 @@ function fxChronotrackApiSyncPostEntries($intCtEventId, array $tabEntries) {
}
/**
* MSIN-4328 — log push_entry (succès).
* MSIN-4328 — logs push_entry un-pour-un (défaut = off, résumé lots seulement).
* @param bool|null $blnSet null = lire, bool = fixer pour la requête courante
*/
function fxChronotrackApiSyncVerboseEntryLogs($blnSet = null) {
static $blnVerbose = false;
if ($blnSet !== null) {
$blnVerbose = (bool)$blnSet;
}
return $blnVerbose;
}
/**
* MSIN-4328 — log push_entry (succès). Uniquement si logs détaillés cochés.
*/
function fxChronotrackApiSyncLogPushEntryOk($intEveId, array $arrM, array $arrPayload, $strPrefix = '') {
$intEveId = intval($intEveId);
if ($intEveId <= 0) {
if ($intEveId <= 0 || !fxChronotrackApiSyncVerboseEntryLogs()) {
return;
}
$strBibMs1 = trim((string)($arrM['bib_ms1'] ?? $arrM['bib'] ?? ''));
@ -1175,6 +1187,17 @@ function fxChronotrackApiSyncLogPushEntryOk($intEveId, array $arrM, array $arrPa
fxChronotrackApiSyncLog($intEveId, intval($arrM['par_id'] ?? 0), 'push_entry', 'ok', trim($strMsg));
}
/**
* MSIN-4328 — log push_entry détail (conflit bib, etc.) si mode verbose.
*/
function fxChronotrackApiSyncLogPushEntryDetail($intEveId, $intParId, $strStatus, $strMessage) {
$intEveId = intval($intEveId);
if ($intEveId <= 0 || !fxChronotrackApiSyncVerboseEntryLogs()) {
return;
}
fxChronotrackApiSyncLog($intEveId, intval($intParId), 'push_entry', $strStatus, $strMessage);
}
/**
* MSIN-4328 — 1 entry : tenter avec bib ; si conflit CT → clear + file pour 2e passe.
*
@ -1238,10 +1261,9 @@ function fxChronotrackApiSyncPushOneEntryWithBibConflictHandling(
if ($strEntryId === '') {
fxChronotrackApiSyncApplyEntryIdsFromApiJson($arrClearRes['json'] ?? null, array($arrMeta));
}
fxChronotrackApiSyncLog(
fxChronotrackApiSyncLogPushEntryDetail(
$intEveId,
intval($arrMeta['par_id'] ?? 0),
'push_entry',
'ok',
'conflit_bib → sans dossard (retry plus tard) external_id='
. ($arrMeta['external_id'] ?? '')
@ -1396,10 +1418,9 @@ function fxChronotrackApiSyncPostEntriesAdaptive($intCtEventId, array $tabEntrie
if ($strEntryIdOne === '') {
fxChronotrackApiSyncApplyEntryIdsFromApiJson($arrClearRes['json'] ?? null, array($arrM));
}
fxChronotrackApiSyncLog(
fxChronotrackApiSyncLogPushEntryDetail(
$intEveId,
intval($arrM['par_id'] ?? 0),
'push_entry',
'ok',
'conflit_bib → sans dossard (retry plus tard) external_id='
. ($arrM['external_id'] ?? '')
@ -2243,6 +2264,8 @@ function fxChronotrackApiSyncPushJobClear($intEveId) {
function fxChronotrackApiSyncPushPrepare($intEveId, $arrOptions = array()) {
$intEveId = intval($intEveId);
$blnForceFull = !empty($arrOptions['force_full']);
$blnVerboseLogs = !empty($arrOptions['verbose_logs']);
fxChronotrackApiSyncVerboseEntryLogs($blnVerboseLogs);
$arrConfig = fxChronotrackApiConfigGet($intEveId);
if ($arrConfig === null) {
return array('state' => 'error', 'message' => 'Événement non lié à ChronoTrack');
@ -2331,6 +2354,7 @@ function fxChronotrackApiSyncPushPrepare($intEveId, $arrOptions = array()) {
'meta' => $tabMeta,
'blocked_count' => $arrClass['blocked_count'],
'force_full' => $blnForceFull ? 1 : 0,
'verbose_logs' => $blnVerboseLogs ? 1 : 0,
'ok_sum' => 0,
'err_sum' => 0,
'bib_retry' => array(),
@ -2387,6 +2411,7 @@ function fxChronotrackApiSyncPushEvent($intEveId, $arrOptions = array()) {
$tabMetaAll = $arrJob['meta'];
$intTotal = count($tabBatchAll);
$intSkipped = intval($arrJob['blocked_count'] ?? 0);
fxChronotrackApiSyncVerboseEntryLogs(!empty($arrJob['verbose_logs']));
$tabBatch = array_slice($tabBatchAll, $intOffset, $intLimit);
$tabMeta = array_slice($tabMetaAll, $intOffset, $intLimit);

View File

@ -187,8 +187,10 @@ switch ($strAction) {
}
set_time_limit(180);
$blnForceFull = (intval($_REQUEST['force_full'] ?? 0) === 1);
$blnVerboseLogs = (intval($_REQUEST['verbose_logs'] ?? 0) === 1);
$tabRetour = fxChronotrackApiSyncPushPrepare($intEveId, array(
'force_full' => $blnForceFull,
'force_full' => $blnForceFull,
'verbose_logs' => $blnVerboseLogs,
));
break;