Import HAL : match des auteurs sur toutes les formes d'idHAL (résolution en fond via cron)

This commit is contained in:
2026-07-07 13:44:08 +02:00
parent c38f8b4d7e
commit f083b36369
5 changed files with 262 additions and 5 deletions

View File

@@ -61,5 +61,42 @@ check('champ etiquettes = 652',Thalim_HAL_Pods_Storage::field_id('etiquettes'),
check('champ axes = 270', Thalim_HAL_Pods_Storage::field_id('axes_thematiques'), 270);
check('champ inconnu = 0', Thalim_HAL_Pods_Storage::field_id('champ_bidon'), 0);
echo "== Thalim_HAL_Forms_Cache::forms_for_user (lecture cache, sans réseau) ==\n";
// Dégradation gracieuse : cache absent -> forme unique.
check('cache absent -> forme unique',
Thalim_HAL_Forms_Cache::forms_for_user(999999999, 'xavier-garnier'),
['xavier-garnier']);
check('idHAL vide -> tableau vide',
Thalim_HAL_Forms_Cache::forms_for_user(999999999, ''),
[]);
// Cache présent et à jour, sur un vrai user (métas écrites puis restaurées).
$real = get_users(['meta_key' => 'identifiant_hal', 'meta_compare' => 'EXISTS',
'fields' => ['ID'], 'number' => 1]);
if (!empty($real)) {
$ruid = (int) $real[0]->ID;
$idhal = strtolower(trim((string) get_user_meta($ruid, 'identifiant_hal', true)));
$bak_forms = get_user_meta($ruid, Thalim_HAL_Forms_Cache::META_FORMS, true);
$bak_src = get_user_meta($ruid, Thalim_HAL_Forms_Cache::META_SOURCE, true);
update_user_meta($ruid, Thalim_HAL_Forms_Cache::META_FORMS,
wp_json_encode([$idhal, $idhal . '-alt']));
update_user_meta($ruid, Thalim_HAL_Forms_Cache::META_SOURCE, $idhal);
$got = Thalim_HAL_Forms_Cache::forms_for_user($ruid, $idhal); sort($got);
$exp = [$idhal, $idhal . '-alt']; sort($exp);
check('cache présent -> formes alternatives incluses', $got, $exp);
// Cache périmé (source != idHAL courant) -> forme unique.
update_user_meta($ruid, Thalim_HAL_Forms_Cache::META_SOURCE, 'obsolete-source');
check('cache périmé -> forme unique',
Thalim_HAL_Forms_Cache::forms_for_user($ruid, $idhal), [$idhal]);
// Restauration de l'état initial.
if ($bak_src === '') { delete_user_meta($ruid, Thalim_HAL_Forms_Cache::META_SOURCE); }
else { update_user_meta($ruid, Thalim_HAL_Forms_Cache::META_SOURCE, $bak_src); }
if ($bak_forms === '') { delete_user_meta($ruid, Thalim_HAL_Forms_Cache::META_FORMS); }
else { update_user_meta($ruid, Thalim_HAL_Forms_Cache::META_FORMS, $bak_forms); }
}
echo "\n$count tests, $failures échec(s)\n";
exit($failures ? 1 : 0);