Skip to content

Commit

Permalink
Add website ability to delete containers
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartlewis committed Jul 5, 2011
1 parent 625f1d6 commit 1ca9b8a
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 6 deletions.
10 changes: 4 additions & 6 deletions swordappclient.php
Expand Up @@ -2,6 +2,7 @@

require("swordappservicedocument.php");
require("swordappentry.php");
require("swordappresponse.php");
require("swordappstatement.php");
require("swordapperrordocument.php");
require("swordapplibraryuseragent.php");
Expand All @@ -10,7 +11,7 @@

class SWORDAPPClient {

private $debug = false;
private $debug = true;

// Request a Service Document from the specified url, with the specified credentials,
// and on-behalf-of the specified user.
Expand Down Expand Up @@ -453,15 +454,12 @@ function deleteContainer($sac_url, $sac_u, $sac_p, $sac_obo) {
$sac_status = curl_getinfo($sac_curl, CURLINFO_HTTP_CODE);
curl_close($sac_curl);

// Was it a successful result?
if ($sac_status != 204) {
throw new Exception("Error deleting container (HTTP code: " . $sac_status . ")");
}
return new SWORDAPPResponse($sac_status, $sac_resp);
}

// Function to delete the content of a resource
function deleteResourceContent($sac_url, $sac_u, $sac_p, $sac_obo) {
$this->deleteContainer($sac_url, $sac_u, $sac_p, $sac_obo);
return $this->deleteContainer($sac_url, $sac_u, $sac_p, $sac_obo);
}

// Function to retrieve an Atom statement
Expand Down
16 changes: 16 additions & 0 deletions swordappresponse.php
@@ -0,0 +1,16 @@
<?php

require_once("swordappentry.php");

class SWORDAPPResponse extends SWORDAPPEntry {

// Construct a new deposit response by passing in the http status code
function __construct($sac_newstatus, $sac_thexml) {
// Call the super constructor
parent::__construct($sac_newstatus, $sac_thexml);

}

}

?>
47 changes: 47 additions & 0 deletions test/website/delete/container/index.php
@@ -0,0 +1,47 @@
<?php

// Load the PHP library
include_once('../../../../swordappclient.php');
include_once('../../utils.php');

// Store the values
session_start();

// Try and delete the edit-iri package
$client = new SWORDAPPClient();
$response = $client->deleteContainer($_POST['editiri'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo']);

if ($response->sac_status != 204) {
$error = 'Unable to delete container. HTTP response code: ' .
$response->sac_status;
} else {
$_SESSION['error'] = '';
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SWORD v2 exerciser - DELETE a container</title>
<link rel='stylesheet' type='text/css' media='all' href='../../css/style.css' />
</head>
<body>

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

<div class="section">
<h2>Response:</h2>
<pre>Status code: <?php echo $response->sac_status; ?></pre>
<pre><?php
if ($response->sac_status != 204) {
echo htmlentities($response->sac_xml);
}?></pre>
</div>

<div id="footer">
<a href='../../'>Home</a> | Based on the <a href="http://github.com/stuartlewis/swordappv2-php-library/">swordappv2-php-library</a>
</div>
</body>
</html>
47 changes: 47 additions & 0 deletions test/website/delete/media/index.php
@@ -0,0 +1,47 @@
<?php

// Load the PHP library
include_once('../../../../swordappclient.php');
include_once('../../utils.php');

// Store the values
session_start();

// Try and delete the edit-iri package
$client = new SWORDAPPClient();
$response = $client->deleteResourceContent($_POST['editmediairi'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo']);

if ($response->sac_status != 204) {
$error = 'Unable to delete content. HTTP response code: ' .
$response->sac_status;
} else {
$_SESSION['error'] = '';
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SWORD v2 exerciser - DELETE a resource container</title>
<link rel='stylesheet' type='text/css' media='all' href='../../css/style.css' />
</head>
<body>

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

<div class="section">
<h2>Response:</h2>
<pre>Status code: <?php echo $response->sac_status; ?></pre>
<pre><?php
if ($response->sac_status != 204) {
echo htmlentities($response->sac_xml);
}?></pre>
</div>

<div id="footer">
<a href='../../'>Home</a> | Based on the <a href="http://github.com/stuartlewis/swordappv2-php-library/">swordappv2-php-library</a>
</div>
</body>
</html>
21 changes: 21 additions & 0 deletions test/website/post/atomentry/index.php
Expand Up @@ -11,6 +11,7 @@
$client = new SWORDAPPClient();
$response = $client->depositAtomEntry($_SESSION['durl'], $_SESSION['u'], $_SESSION['p'],
$_SESSION['obo'], $_SESSION['filename'], $_SESSION['inprogress']);

if ($response->sac_status != 201) {
$error = 'Unable to deposit package. HTTP response code: ' .
$response->sac_status . ' - ' . $response->sac_statusmessage;
Expand Down Expand Up @@ -38,6 +39,26 @@

<div class="section">

Deposited ID: <?php echo $response->sac_idl ?>;

<ul>
<li>
EDIT-IRI: <?php echo $response->sac_edit_iri; ?>
<form action="../../delete/container/" method="post">
<input type="hidden" name="editiri" value="<?php echo $response->sac_edit_iri; ?>" />
<input type="submit" value="DELETE CONTAINER" />
</form>
</li>
<li>
EDIT-MEDIA: <?php echo $response->sac_edit_media_iri; ?>
<form action="../../delete/media/" method="post">
<input type="hidden" name="editmediairi" value="<?php echo $response->sac_edit_media_iri; ?>" />
<input type="submit" value="DELETE MEDIA" />
</form>
</li>
<li>Statement (Atom):<?php echo $response->sac_state_iri_atom; ?></li>
<li>Statement (OAI-ORE):<?php echo $response->sac_state_iri_ore; ?></li>
</ul>

</div>

Expand Down
20 changes: 20 additions & 0 deletions test/website/post/multipart/index.php
Expand Up @@ -40,6 +40,26 @@

<div class="section">

Deposited ID: <?php echo $response->sac_idl ?>;

<ul>
<li>
EDIT-IRI: <?php echo $response->sac_edit_iri; ?>
<form action="../../delete/container/" method="post">
<input type="hidden" name="editiri" value="<?php echo $response->sac_edit_iri; ?>" />
<input type="submit" value="DELETE CONTAINER" />
</form>
</li>
<li>
EDIT-MEDIA: <?php echo $response->sac_edit_media_iri; ?>
<form action="../../delete/media/" method="post">
<input type="hidden" name="editmediairi" value="<?php echo $response->sac_edit_media_iri; ?>" />
<input type="submit" value="DELETE MEDIA" />
</form>
</li>
<li>Statement (Atom):<?php echo $response->sac_state_iri_atom; ?></li>
<li>Statement (OAI-ORE):<?php echo $response->sac_state_iri_ore; ?></li>
</ul>

</div>

Expand Down

0 comments on commit 1ca9b8a

Please sign in to comment.