3 require_once(
'../../swordappclient.php');
7 $contentzip =
'content.zip';
8 $metadatazip =
'metadata.zip';
9 $servicedocument =
'http://demo.dspace.org/swordv2/servicedocument';
10 $depositlocation =
'http://demo.dspace.org/swordv2/collection/10673/11';
11 $dspacerest =
'https://demo.dspace.org/rest';
12 $user =
'dspacedemo+admin@gmail.com';
19 print
"About to request servicedocument from " . $servicedocument .
"\n";
20 $sd = $sword->servicedocument($servicedocument, $user, $password,
'');
21 print
"Received HTTP status code: " . $sd->sac_status .
" (" . $sd->sac_statusmessage .
")\n";
22 if ($sd->sac_status == 200) {
28 print
"About to create new item at " . $depositlocation .
"\n";
29 $response = $sword->depositAtomEntry($depositlocation, $user, $password,
'', $atom, $sac_inprogress =
true);
30 print
"Received HTTP status code: " . $response->sac_status .
" (" . $response->sac_statusmessage .
")\n";
31 if (($response->sac_status >= 200) || ($response->sac_status < 300)) {
32 $response->toString();
34 $edit_iri = $response->sac_edit_iri;
35 $edit_media = $response->sac_edit_media_iri;
36 $statement_atom = $response->sac_state_iri_atom;
37 print
"Edit IRI: " . $edit_iri .
"\n";
38 print
"Edit Media: " . $edit_media .
"\n";
39 print
"Statement: " . $statement_atom;
43 print
"About to add file (" . $contentzip .
") to " . $edit_media .
"\n";
44 $response = $sword->addExtraFileToMediaResource($edit_media, $user, $password,
'', $contentzip,
"application/zip",
false);
45 print
"Received HTTP status code: " . $response->sac_status .
" (" . $response->sac_statusmessage .
")\n";
49 print
"About to complete the deposit at " . $edit_iri .
"\n";
50 $response = $sword->completeIncompleteDeposit($edit_iri, $user, $password,
'');
51 print
"Received HTTP status code: " . $response->sac_status .
" (" . $response->sac_statusmessage .
")\n";
54 print
"About to request Atom serialisation of the deposit statement from " . $statement_atom .
"\n";
55 $atomstatement = @$sword->retrieveAtomStatement($statement_atom, $user, $password,
'');
56 if (($atomstatement->sac_status >= 200) || ($atomstatement->sac_status < 300)) {
57 $atomstatement->toString();
60 $handle = $atomstatement->sac_entries[1]->sac_content_source[0];
61 $handle = substr($handle, strpos($handle,
'bitstream/') + 10);
62 $handle = substr($handle, 0, strpos($handle,
'/', strpos($handle,
'/') + 1));
63 print
"Handle of new object is: " . $handle;
68 $data = array(
"email" => $user,
"password" => $password);
71 $url = $dspacerest .
'/login';
72 $curl = curl_init($url);
73 curl_setopt($curl, CURLOPT_CUSTOMREQUEST,
"POST");
74 curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
75 curl_setopt($curl, CURLOPT_RETURNTRANSFER,
true);
76 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
77 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
78 curl_setopt($curl, CURLOPT_HTTPHEADER, array(
79 'Content-Type: application/json',
80 'Content-Length: ' . strlen($data_string))
82 $token = curl_exec($curl);
83 print
'DSpace login token is: ' . $token .
"\n\n";
86 $url = $dspacerest .
'/handle/' . $handle;
87 $curl = curl_init($url);
89 array_push($headers,
"rest-dspace-token: " . $token);
90 array_push($headers,
"Content-Type: application/json");
91 array_push($headers,
"Accept: application/json");
92 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
94 curl_setopt($curl, CURLOPT_CUSTOMREQUEST,
"GET");
95 curl_setopt($curl, CURLOPT_RETURNTRANSFER,
true);
96 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
97 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
98 $response = curl_exec($curl);
99 print
'DSpace item ID: ' . $response .
"\n\n";