Import unitaire, statut publié/pending et validation des idHAL
This commit is contained in:
@@ -61,6 +61,49 @@ class Thalim_HAL_API {
|
||||
return $docs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check which HAL IDs exist in HAL's author referential (ref/author).
|
||||
* Returns map [normalized_hal_id => bool|null] — null when the API errored
|
||||
* (treated as "unknown", not "invalid").
|
||||
*/
|
||||
public function validate_hal_ids(array $hal_ids) {
|
||||
$result = [];
|
||||
$clean = [];
|
||||
foreach ($hal_ids as $id) {
|
||||
$id = trim((string) $id);
|
||||
if ($id !== '') $clean[strtolower($id)] = $id;
|
||||
}
|
||||
if (empty($clean)) return $result;
|
||||
|
||||
// Default all to false; flip to true when found
|
||||
foreach ($clean as $norm => $_) $result[$norm] = false;
|
||||
|
||||
$endpoint = 'https://api.archives-ouvertes.fr/ref/author/';
|
||||
$chunks = array_chunk(array_values($clean), 100);
|
||||
foreach ($chunks as $chunk) {
|
||||
// Solr OR with quoted values to tolerate dashes/dots in slugs
|
||||
$quoted = array_map(fn($id) => '"' . str_replace('"', '', $id) . '"', $chunk);
|
||||
$params = [
|
||||
'q=' . urlencode('idHal_s:(' . implode(' OR ', $quoted) . ')'),
|
||||
'fl=' . urlencode('idHal_s'),
|
||||
'rows=' . count($chunk),
|
||||
'wt=json',
|
||||
];
|
||||
$data = $this->request($endpoint . '?' . implode('&', $params));
|
||||
if (is_wp_error($data)) {
|
||||
foreach ($chunk as $id) $result[strtolower($id)] = null;
|
||||
continue;
|
||||
}
|
||||
foreach ($data['response']['docs'] ?? [] as $doc) {
|
||||
if (!empty($doc['idHal_s'])) {
|
||||
$result[strtolower($doc['idHal_s'])] = true;
|
||||
}
|
||||
}
|
||||
if (count($chunks) > 1) usleep(250000);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test API connection
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user