Open Journal Systems  3.3.0
archivematica.php
1 <?php
2 
3 require_once('../../swordappclient.php');
4 
5 // Settings
6 $atom = 'atom.xml';
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';
13 $password = 'dspace';
14 
15 // Initiatiate the SWORD client
16 $sword = new SWORDAPPClient();
17 
18 // Get the service document
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) {
23  $sd->toString();
24 }
25 print "\n\n";
26 
27 // Create the item by depositing an atom document
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();
33 }
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;
40 print "\n\n";
41 
42 // Add the DIP content
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";
46 print "\n\n";
47 
48 // Complete the deposit
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";
52 
53 // Fetch the statement
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();
58 }
59 print "\n\n";
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;
64 print "\n\n";
65 
66 
67 // Login to DSpace REST interface
68 $data = array("email" => $user, "password" => $password);
69 $data_string = json_encode($data);
70 // https://groups.google.com/forum/m/#!topic/dspace-tech/s7SQGhgDUPI
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))
81 );
82 $token = curl_exec($curl);
83 print 'DSpace login token is: ' . $token . "\n\n";
84 
85 // Get the item ID for the item we created
86 $url = $dspacerest . '/handle/' . $handle;
87 $curl = curl_init($url);
88 $headers = array();
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);
93 //curl_setopt($curl, CURLOPT_VERBOSE, true);
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";
100 
101 ?>
SWORDAPPClient
Definition: swordappclient.php:12
GuzzleHttp\json_encode
json_encode($value, $options=0, $depth=512)
Definition: guzzlehttp/guzzle/src/functions.php:324