print "About to create new item at " . $depositlocation . "\n";
$response = $sword->depositAtomEntry($depositlocation, $user, $password, '', $atom, $sac_inprogress = true);
print "Received HTTP status code: " . $response->sac_status . " (" . $response->sac_statusmessage . ")\n";
if ($response->sac_status >= 200 || $response->sac_status < 300) {
    $response->toString();
}
$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);
    }
    $testdr = $testsac->replaceMetadataAndFile($edit_iri, $testuser, $testpw, $testobo, $testmultipart2, $testpackaging, false);
    print "Received HTTP status code: " . $testdr->sac_status . " (" . $testdr->sac_statusmessage . ")\n";
    if ($testdr->sac_status >= 200 || $testdr->sac_status < 300) {
        $testdr->toString();
    }
    print "\n\n";
}
if (false) {
    print "About to add file (" . $testextrafile . ") to " . $edit_media . "\n";
    if (empty($testuser)) {
        print "As: anonymous\n";
    } else {
        print "As: " . $testuser . "\n";
    }
    $testdr = $testsac->addExtraFileToMediaResource($edit_media, $testuser, $testpw, $testobo, $testextrafile, $testextrafiletype, false);
    print "Received HTTP status code: " . $testdr->sac_status . " (" . $testdr->sac_statusmessage . ")\n";
    if ($testdr->sac_status >= 200 || $testdr->sac_status < 300) {
        $testdr->toString();
    }
    print "\n\n";
}
if (false) {
    print "About to add package (" . $testzipcontentfile . ") to " . $edit_iri . "\n";
    if (empty($testuser)) {
        print "As: anonymous\n";
    } else {
        print "As: " . $testuser . "\n";
    }
    $testdr = $testsac->addExtraPackage($edit_iri, $testuser, $testpw, $testobo, $testzipcontentfile, $testpackaging, $testcontenttype, false);
    print "Received HTTP status code: " . $testdr->sac_status . " (" . $testdr->sac_statusmessage . ")\n";
Exemple #3
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);
     }
 }