-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-doi-from-repository.php
150 lines (118 loc) · 4.55 KB
/
load-doi-from-repository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* Script para recuperar doi, url y condiciones de acceso de
* los registros de un repositorio compatible con las directrices
* de OpenAire a través de su servidor OAI
*
* Genera un archivo en dois-repositorio.txt con la información
* descargada
*
* @author Toni Prieto
* @date 2018-09-18
*/
require __DIR__ . '/vendor/autoload.php';
require_once("function.php");
// Opciones de aplicación
$options=getopt('o:I');
if(@$options['o'])
{
// Archivo de configuració como parametro
// http://example.com/oai/openaire
$oaiendpoint = $options['o'];
}
else
{
die("Falta el parámetro o: \n" .
"USO: php load-doi-from-repositori.php -o <oai_endpoint>\n");
}
// Muestra más información
$verbose = true;
// Incluir registros sin doi
$includeAll = true;
//Creamos l'arxiu
$file = fopen("./dois-repositorio.txt", "w");
$client = new \Phpoaipmh\Client($oaiendpoint);
$myEndpoint = new \Phpoaipmh\Endpoint($client);
echo "Obteniendo registros del servidor OAI: " . $oaiendpoint . "\n";
try {
// Recs will be an iterator of SimpleXMLElement objects
$recs = $myEndpoint->listRecords("oai_dc", null, null, null);
// The iterator will continue retrieving items across multiple HTTP requests.
// You can keep running this loop through the *entire* collection you
// are harvesting. All OAI-PMH and HTTP pagination logic is hidden neatly
// behind the iterator API.
$num = 0;
foreach ($recs as $rec) {
if ($verbose) {
echo "Procesando registro " . ($num + 1) . " (ID: " . $rec->header->identifier . ")\n";
}
$deleted = false;
if (isset($rec->header->attributes()["status"]) && (string)$rec->header->attributes()["status"] == "deleted") {
$deleted = true;
} else {
$deleted = false;
}
if (!$deleted) {
$data = $rec->metadata->children('http://www.openarchives.org/OAI/2.0/oai_dc/');
$rows = $data->children('http://purl.org/dc/elements/1.1/');
$doi = null;
$identifiers = array();
$rights = null;
$embargodate = null;
foreach ($rows as $dc => $value) {
//echo $dc . ":" . $value . "\n";
if (!strcmp($dc, "identifier")) {
if (isDoiExtended($value)) {
$doi = getDOIValue($value);
} else {
if (startsWith($value,"http")) {
$identifiers[] = $value;
}
}
}
if (!strcmp($dc, "rights")) {
if (startsWith($value, "info:eu-repo/semantics/")) {
if (!strcmp($value, "info:eu-repo/semantics/closedAccess")) {
$rights = "CLOSED";
} else if (!strcmp($value, "info:eu-repo/semantics/restrictedAccess")) {
$rights = "CLOSED";
} else if (!strcmp($value, "info:eu-repo/semantics/embargoedAccess")) {
$rights = "EMBARGO";
} else if (!strcmp($value, "info:eu-repo/semantics/openAccess")) {
$rights = "OPEN";
}
}
}
if (!strcmp($dc, "date")) {
if (startsWith($value, "info:eu-repo/semantics/embargoedAccess")) {
$embargodate = str_replace("info:eu-repo/semantics/embargoedAccess", "", $value);
}
}
}
//Escribir resultado en el fichero
if ($includeAll) {
fwrite($file,$doi . "\t" . implode(";", $identifiers) . "\t" . $rights . "\t" . $embargodate . "\n");
}
else if ($doi != null) {
if ($verbose) {
echo "\t" . "DOI encontrado: " . $doi . "\n";
}
fwrite($file,$doi . "\t" . implode(";", $identifiers) . "\t" . $rights . "\t" . $embargodate . "\n");
}
}
$num++;
}
echo "Creado archivo local dois-repositorio.txt con los datos de las publicaciones descargades del OAI\n";
} catch (\Phpoaipmh\Exception\OaipmhException $exception) {
if ($exception->getOaiErrorCode() == "noRecordsMatch") {
echo "\nRESULTADO: La consulta no ha devuelto registros\n";
} else {
echo "Se ha producido un error descargando los registros del servidor OAI\n";
echo $exception->getMessage() . "\n";
}
}
finally
{
fclose($file);
}
?>