fall back to the single stored form. return [$base]; } /** * Cron worker: resolve forms for a batch of members whose cache is missing * or stale. Runs in the background; safe to be interrupted (idempotent). */ public static function run_batch() { $users = get_users([ 'meta_key' => 'identifiant_hal', 'meta_compare' => 'EXISTS', 'fields' => ['ID'], 'number' => 500, ]); // Select those needing (re)resolution: stored form != cached source. $todo = []; foreach ($users as $u) { $idhal = strtolower(trim((string) get_user_meta($u->ID, 'identifiant_hal', true))); if ($idhal === '') continue; $src = get_user_meta($u->ID, self::META_SOURCE, true); if ($src !== $idhal) { $todo[$idhal][] = (int) $u->ID; // group users sharing a slug } if (count($todo) >= self::BATCH_SIZE) break; } if (empty($todo)) return; $api = new Thalim_HAL_API(); $expanded = $api->expand_hal_id_forms(array_keys($todo)); foreach ($todo as $idhal => $user_ids) { $forms = $expanded[$idhal] ?? [$idhal]; foreach ($user_ids as $uid) { update_user_meta($uid, self::META_FORMS, wp_json_encode(array_values($forms))); update_user_meta($uid, self::META_SOURCE, $idhal); } } } }