Ejemplo n.º 1
0
 private function _depositatomtwostep()
 {
     $response = '';
     $editmediairi = '';
     try {
         $package = new PackagerAtomTwoStep($this->config->item('easydeposit_uploadfiles_savedir'), $this->userid, $this->config->item('easydeposit_deposit_packages'), $this->userid . '.multipart');
         foreach ($this->easydeposit_steps as $stepname) {
             if ($stepname == 'deposit') {
                 break;
             }
             include_once APPPATH . 'controllers/' . $stepname . '.php';
             $stepclass = ucfirst($stepname);
             call_user_func(array($stepclass, '_packagemultipart'), $package);
         }
         $package->create();
         // Deposit the atom entry, leave 'in progress'
         $sac = new SWORDAPPClient();
         $response = $sac->depositAtomEntry($_SESSION['depositurl'], $_SESSION['sword-username'], $_SESSION['sword-password'], $_SESSION['sword-obo'], $this->config->item('easydeposit_deposit_packages') . $this->userid . '/atom', true);
         if ($response->sac_status >= 200 && $response->sac_status < 300) {
             $_SESSION['deposited-response'] = $response->sac_xml;
             $_SESSION['deposited-url'] = (string) $response->sac_id;
             $editmediairi = $response->sac_edit_media_iri;
         } else {
             $error = 'Server returned status code: ' . $response->sac_status . "\n\n";
             $error .= 'Server provided response: ' . $response->sac_xml;
         }
         echo '3';
         // Deposit each file
         $counter = 0;
         $inprogress = True;
         foreach ($package->getFiles() as $file) {
             echo $counter;
             $counter++;
             if ($counter == count($package->getFiles())) {
                 $inprogress = False;
             }
             $response = $sac->addExtraFileToMediaResource($editmediairi, $_SESSION['sword-username'], $_SESSION['sword-password'], $_SESSION['sword-obo'], $this->config->item('easydeposit_deposit_packages') . $this->userid . '/' . $file, $inprogress);
         }
         $response = $sac->completeIncompleteDeposit($editmediairi, $_SESSION['sword-username'], $_SESSION['sword-password'], $_SESSION['sword-obo']);
         echo '5';
         echo $response;
         die;
     } catch (Exception $e) {
         // Catch the exception for reporting
         $error = 'Error: ' . $e->getMessage() . "\n\n";
         $error .= 'Deposit URL: ' . $_SESSION['depositurl'] . "\n";
         $error .= 'Deposit username: '******'sword-username'] . "\n";
         $error .= 'Package file: ' . $this->config->item('easydeposit_deposit_packages') . $this->userid . '.zip' . "\n";
         if (!empty($response->sac_xml)) {
             $error .= "\n\nResponse:" . $response->sac_xml;
         }
         $_SESSION['deposited-response'] = $error;
     }
     // If there was an error, send it to the administrator
     if (!empty($error)) {
         $to = $this->config->item('easydeposit_supportemail');
         $subject = 'Error with EasyDeposit system';
         $headers = 'From: ' . $to . ' <' . $to . ">\r\n";
         $headers .= "MIME-Version: 1.0\r\n";
         $headers .= "Content-type: text/plain; charset=utf-8\r\n";
         $headers .= "Content-Transfer-Encoding: quoted-printable\r\n";
         mail($to, $subject, $error, $headers);
     }
 }
}
$edit_iri = $response->sac_edit_iri;
$edit_media = $response->sac_edit_media_iri;
$statement_atom = $response->sac_state_iri_atom;
print "Edit IRI: " . $edit_iri . "\n";
print "Edit Media: " . $edit_media . "\n";
print "Statement: " . $statement_atom;
print "\n\n";
// Add the DIP content
print "About to add file (" . $contentzip . ") to " . $edit_media . "\n";
$response = $sword->addExtraFileToMediaResource($edit_media, $user, $password, '', $contentzip, "application/zip", false);
print "Received HTTP status code: " . $response->sac_status . " (" . $response->sac_statusmessage . ")\n";
print "\n\n";
// Complete the deposit
print "About to complete the deposit at " . $edit_iri . "\n";
$response = $sword->completeIncompleteDeposit($edit_iri, $user, $password, '');
print "Received HTTP status code: " . $response->sac_status . " (" . $response->sac_statusmessage . ")\n";
// Fetch the statement
print "About to request Atom serialisation of the deposit statement from " . $statement_atom . "\n";
$atomstatement = @$sword->retrieveAtomStatement($statement_atom, $user, $password, '');
if ($atomstatement->sac_status >= 200 || $atomstatement->sac_status < 300) {
    $atomstatement->toString();
}
print "\n\n";
$handle = $atomstatement->sac_entries[1]->sac_content_source[0];
$handle = substr($handle, strpos($handle, 'bitstream/') + 10);
$handle = substr($handle, 0, strpos($handle, '/', strpos($handle, '/') + 1));
print "Handle of new object is: " . $handle;
print "\n\n";
// Login to DSpace REST interface
$data = array("email" => $user, "password" => $password);
Ejemplo n.º 3
0
<?php

// Load the PHP library
include_once '../../../../swordappclient.php';
include_once '../../utils.php';
// Store the values
session_start();
// Try and complete the incomplete deposit
$client = new SWORDAPPClient();
$response = $client->completeIncompleteDeposit($_SESSION['seiri'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo']);
if ($response->sac_status != 200) {
    $error = 'Unable to deposit package. HTTP response code: ' . $response->sac_status . ' - ' . $response->sac_statusmessage;
    $_SESSION['error'] = $error;
} else {
    $_SESSION['error'] = '';
}
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>SWORD v2 exerciser - Complete an incomplete deposit</title>
        <link rel='stylesheet' type='text/css' media='all' href='../../css/style.css' />
    </head>
    <body>

        <div id="header">
            <h1>SWORD v2 exerciser</h1>
        </div>

        <?php 
if (!empty($errormsg)) {