Skip to content

Commit 9992743

Browse files
Merge pull request #412 from JLG-WOCFR-DEV/codex/implement-manual-reset-detection-and-ui-updates
Highlight manual resets in scan history
2 parents eded55b + 7c91943 commit 9992743

File tree

5 files changed

+233
-0
lines changed

5 files changed

+233
-0
lines changed

docs/ameliorations-et-tests.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
## Améliorations réalisées
2121

22+
- **Historique des analyses** – Les remises à zéro manuelles sont désormais signalées dans le tableau avec l'utilisateur à l'origine de l'action, l'horodatage formaté et une alerte accessible dédiée, ce qui facilite l'audit des interventions humaines. 【F:liens-morts-detector-jlg/includes/blc-admin-pages.php†L2478-L2542】【F:liens-morts-detector-jlg/assets/css/blc-admin-styles.css†L112-L146】
2223
- **`blc_get_link_scan_status_payload`** calcule désormais des métriques opérationnelles (pourcentage d'avancement, éléments restants, durée, débit par minute, estimation d'achèvement) et les expose à l'interface et à l'API REST pour un suivi plus transparent. 【F:liens-morts-detector-jlg/includes/blc-scanner.php†L10-L102】【F:liens-morts-detector-jlg/includes/blc-scanner.php†L366-L408】
2324
- **`blc_get_link_scan_status`** et **`blc_get_image_scan_status`** utilisent un cache mémoire par requête pour limiter les lectures répétitives de la base de données lors d'appels successifs, améliorant la charge serveur pendant les écrans de suivi. 【F:liens-morts-detector-jlg/includes/blc-scanner.php†L10-L102】【F:liens-morts-detector-jlg/includes/blc-scanner.php†L446-L544】
2425
- **Exports automatisés** : une nouvelle planification `blc_generate_report_exports` sérialise les résultats du dernier scan en CSV dans `wp-content/uploads/blc-report-exports`, mémorise les tentatives et évite les re-générations inutiles. 【F:liens-morts-detector-jlg/includes/blc-reports.php†L1-L330】【F:liens-morts-detector-jlg/includes/blc-cron.php†L626-L742】【F:liens-morts-detector-jlg/includes/blc-activation.php†L81-L118】

liens-morts-detector-jlg/assets/css/blc-admin-styles.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,43 @@
11271127
margin-top: 12px;
11281128
}
11291129

1130+
.blc-history-reset-row td {
1131+
padding: 0;
1132+
border-top: none;
1133+
border-bottom: none;
1134+
}
1135+
1136+
.blc-history-reset {
1137+
display: flex;
1138+
flex-direction: column;
1139+
gap: 4px;
1140+
padding: 16px 20px;
1141+
background: var(--blc-history-reset-background, #fff7ed);
1142+
color: var(--blc-history-reset-color, #7c2d12);
1143+
border-left: 4px solid var(--blc-history-reset-accent, #d97706);
1144+
border-radius: 6px;
1145+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
1146+
}
1147+
1148+
.blc-history-reset__title {
1149+
font-size: 12px;
1150+
font-weight: 700;
1151+
letter-spacing: 0.08em;
1152+
text-transform: uppercase;
1153+
color: inherit;
1154+
}
1155+
1156+
.blc-history-reset__meta {
1157+
font-size: 14px;
1158+
font-weight: 500;
1159+
}
1160+
1161+
.blc-history-reset__note {
1162+
font-size: 13px;
1163+
color: inherit;
1164+
opacity: 0.85;
1165+
}
1166+
11301167
.blc-history-table-section {
11311168
margin-bottom: 32px;
11321169
}

liens-morts-detector-jlg/includes/blc-admin-pages.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,30 @@ function blc_get_history_state_class($state) {
24672467
}
24682468
}
24692469

2470+
/**
2471+
* Retrieve a localized label for a dataset displayed in the history page.
2472+
*
2473+
* @param string $dataset_type Dataset slug.
2474+
*
2475+
* @return string
2476+
*/
2477+
function blc_get_history_dataset_label($dataset_type) {
2478+
$dataset_type = is_string($dataset_type) ? $dataset_type : '';
2479+
2480+
if ($dataset_type !== '' && function_exists('sanitize_key')) {
2481+
$dataset_type = sanitize_key($dataset_type);
2482+
}
2483+
2484+
switch ($dataset_type) {
2485+
case 'link':
2486+
return __('Liens', 'liens-morts-detector-jlg');
2487+
case 'image':
2488+
return __('Images', 'liens-morts-detector-jlg');
2489+
default:
2490+
return '';
2491+
}
2492+
}
2493+
24702494
/**
24712495
* Render the scan history dashboard and metrics explorer.
24722496
*/
@@ -2575,6 +2599,66 @@ function blc_scan_history_page() {
25752599
continue;
25762600
}
25772601

2602+
$event = isset($entry['event']) ? (string) $entry['event'] : '';
2603+
if ($event === 'reset') {
2604+
$timestamp = isset($entry['timestamp']) ? (int) $entry['timestamp'] : 0;
2605+
$timestamp_display = blc_format_scan_history_datetime($timestamp);
2606+
2607+
$user_data = isset($entry['user']) && is_array($entry['user']) ? $entry['user'] : [];
2608+
$user_name = '';
2609+
if (isset($user_data['display_name'])) {
2610+
$user_name = trim((string) $user_data['display_name']);
2611+
}
2612+
if ($user_name === '' && isset($user_data['login'])) {
2613+
$user_name = trim((string) $user_data['login']);
2614+
}
2615+
if ($user_name === '') {
2616+
$user_name = __('Utilisateur inconnu', 'liens-morts-detector-jlg');
2617+
}
2618+
2619+
$dataset_label = blc_get_history_dataset_label($entry['dataset_type'] ?? '');
2620+
2621+
$description = sprintf(
2622+
/* translators: 1: user display name, 2: formatted date. */
2623+
__('Déclenchée par %1$s le %2$s', 'liens-morts-detector-jlg'),
2624+
$user_name,
2625+
$timestamp_display
2626+
);
2627+
2628+
$announcement = ($dataset_label !== '')
2629+
? sprintf(
2630+
/* translators: 1: user display name, 2: formatted date, 3: dataset label. */
2631+
__('Remise à zéro manuelle déclenchée par %1$s le %2$s pour le jeu de données %3$s.', 'liens-morts-detector-jlg'),
2632+
$user_name,
2633+
$timestamp_display,
2634+
$dataset_label
2635+
)
2636+
: sprintf(
2637+
/* translators: 1: user display name, 2: formatted date. */
2638+
__('Remise à zéro manuelle déclenchée par %1$s le %2$s.', 'liens-morts-detector-jlg'),
2639+
$user_name,
2640+
$timestamp_display
2641+
);
2642+
2643+
$dataset_note = ($dataset_label !== '')
2644+
? sprintf(
2645+
/* translators: %s: dataset label. */
2646+
__('Jeu de données : %s', 'liens-morts-detector-jlg'),
2647+
$dataset_label
2648+
)
2649+
: '';
2650+
2651+
$job_rows[] = [
2652+
'type' => 'reset',
2653+
'timestamp' => $timestamp_display,
2654+
'description' => $description,
2655+
'dataset_note' => $dataset_note,
2656+
'announcement' => $announcement,
2657+
];
2658+
2659+
continue;
2660+
}
2661+
25782662
$job_id = isset($entry['job_id']) ? (string) $entry['job_id'] : '';
25792663
$state_raw = isset($entry['state']) ? (string) $entry['state'] : '';
25802664
$state = sanitize_key($state_raw);
@@ -2779,6 +2863,22 @@ function blc_scan_history_page() {
27792863
</tr>
27802864
<?php else : ?>
27812865
<?php foreach ($job_rows as $row) :
2866+
if (($row['type'] ?? '') === 'reset') :
2867+
?>
2868+
<tr class="blc-history-reset-row">
2869+
<td colspan="5">
2870+
<div class="blc-history-reset" role="status" aria-live="polite" aria-label="<?php echo esc_attr($row['announcement']); ?>">
2871+
<span class="blc-history-reset__title"><?php esc_html_e('Remise à zéro manuelle', 'liens-morts-detector-jlg'); ?></span>
2872+
<span class="blc-history-reset__meta"><?php echo esc_html($row['description']); ?></span>
2873+
<?php if (!empty($row['dataset_note'])) : ?>
2874+
<span class="blc-history-reset__note"><?php echo esc_html($row['dataset_note']); ?></span>
2875+
<?php endif; ?>
2876+
</div>
2877+
</td>
2878+
</tr>
2879+
<?php
2880+
continue;
2881+
endif;
27822882
$job_id_display = $row['job_id'] !== '' ? $row['job_id'] : __('(inconnu)', 'liens-morts-detector-jlg');
27832883
?>
27842884
<tr>

tests/BlcAdminHistoryPageTest.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
namespace {
4+
require_once __DIR__ . '/translation-stubs.php';
5+
require_once __DIR__ . '/wp-option-stubs.php';
6+
7+
if (!function_exists('sanitize_key')) {
8+
function sanitize_key($key)
9+
{
10+
$key = strtolower((string) $key);
11+
12+
return preg_replace('/[^a-z0-9_\-]/', '', $key);
13+
}
14+
}
15+
}
16+
17+
namespace Tests {
18+
19+
use Brain\Monkey;
20+
use Brain\Monkey\Functions;
21+
use PHPUnit\Framework\TestCase;
22+
use Tests\Stubs\OptionsStore;
23+
24+
class BlcAdminHistoryPageTest extends TestCase
25+
{
26+
protected function setUp(): void
27+
{
28+
parent::setUp();
29+
require_once __DIR__ . '/../vendor/autoload.php';
30+
Monkey\setUp();
31+
32+
if (!defined('ABSPATH')) {
33+
define('ABSPATH', __DIR__ . '/../');
34+
}
35+
36+
OptionsStore::reset();
37+
38+
require_once __DIR__ . '/../liens-morts-detector-jlg/includes/blc-scanner.php';
39+
require_once __DIR__ . '/../liens-morts-detector-jlg/includes/blc-admin-pages.php';
40+
41+
Functions\when('admin_url')->alias(static function ($path = '') {
42+
return 'admin.php?page=' . ltrim((string) $path, '?');
43+
});
44+
45+
Functions\when('number_format_i18n')->alias(static function ($number, $decimals = 0) {
46+
return number_format((float) $number, (int) $decimals, ',', ' ');
47+
});
48+
49+
Functions\when('wp_date')->alias(static function ($format, $timestamp = null) {
50+
$timestamp = $timestamp ?? time();
51+
52+
return gmdate($format, $timestamp);
53+
});
54+
55+
Functions\when('blc_current_user_can_view_reports')->justReturn(true);
56+
Functions\when('current_user_can')->justReturn(true);
57+
}
58+
59+
protected function tearDown(): void
60+
{
61+
Monkey\tearDown();
62+
parent::tearDown();
63+
}
64+
65+
public function test_history_page_renders_manual_reset_entry(): void
66+
{
67+
OptionsStore::$options['blc_link_scan_history'] = [
68+
[
69+
'event' => 'reset',
70+
'dataset_type' => 'link',
71+
'timestamp' => 1700000000,
72+
'user' => [
73+
'id' => 42,
74+
'login' => 'editor',
75+
'display_name' => 'Éditeur Test',
76+
],
77+
],
78+
];
79+
80+
OptionsStore::$options['blc_link_scan_metrics_history'] = [];
81+
82+
ob_start();
83+
blc_scan_history_page();
84+
$output = (string) ob_get_clean();
85+
86+
$this->assertStringContainsString('Remise à zéro manuelle', $output);
87+
$this->assertStringContainsString('Déclenchée par Éditeur Test', $output);
88+
$this->assertStringContainsString('role="status"', $output);
89+
}
90+
}
91+
92+
}

tests/BlcScanHistoryPageTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ protected function setUp(): void
5151

5252
return gmdate($format, $timestamp);
5353
});
54+
55+
Functions\when('blc_current_user_can_view_reports')->justReturn(true);
56+
Functions\when('current_user_can')->justReturn(true);
5457
}
5558

5659
protected function tearDown(): void

0 commit comments

Comments
 (0)