Correct response code for normal behaviour per RFC2518. Write handling for

collections, since we now actually have such beasts.
This commit is contained in:
Andrew McMillan 2006-12-06 21:50:12 +13:00
parent 5e580d5e2a
commit ed65ec1294

View File

@ -29,26 +29,58 @@ if ( ! $request->AllowedTo('delete') ) {
$request->DoResponse( 403, translate("You may not delete entries from this calendar.") );
}
/**
* We read the resource first, so we can check if it matches (or does not match)
*/
$qry = new PgQuery( "SELECT * FROM caldav_data WHERE user_no = ? AND dav_name = ?;", (isset($request->user_no)?$request->user_no:$session->user_no), $request->path );
if ( $qry->Exec("DELETE") && $qry->rows == 1 ) {
$delete_row = $qry->Fetch();
if ( (isset($request->etag_if_match) && $request->etag_if_match != $delete_row->dav_etag) ) {
$request->DoResponse( 412, translate("Resource does not match 'If-Match' header - not deleted") );
}
$qry = new PgQuery( "DELETE FROM caldav_data WHERE user_no = ? AND dav_name = ?;", (isset($request->user_no)?$request->user_no:$session->user_no), $request->path );
if ( $qry->Exec("DELETE") ) {
@dbg_error_log( "DELETE", "DELETE: User: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
$request->DoResponse( 200, "" );
if ( $request->IsCollection() ) {
/**
* We read the collection first, so we can check if it matches (or does not match)
*/
$qry = new PgQuery( "SELECT * FROM collection WHERE user_no = ? AND dav_name = ?;", (isset($request->user_no)?$request->user_no:$session->user_no), $request->path );
if ( $qry->Exec("DELETE") && $qry->rows == 1 ) {
$delete_row = $qry->Fetch();
if ( (isset($request->etag_if_match) && $request->etag_if_match != $delete_row->dav_etag) ) {
$request->DoResponse( 412, translate("Resource does not match 'If-Match' header - not deleted") );
}
$user_no = intval(isset($request->user_no)?$request->user_no:$session->user_no);
$sql = "BEGIN;";
$sql .= "DELETE FROM collection WHERE user_no = $user_no AND dav_name = ". qpg($request->path).";";
$sql .= "DELETE FROM caldav_data WHERE user_no = $user_no AND dav_name LIKE ?;";
$sql .= "COMMIT;";
$qry = new PgQuery( $sql, $request->path.'%' );
if ( $qry->Exec("DELETE") ) {
@dbg_error_log( "DELETE", "DELETE (collection): User: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
$request->DoResponse( 204 );
}
else {
$request->DoResponse( 500, translate("Error querying database.") );
}
}
else {
$request->DoResponse( 500, translate("Error querying database.") );
$request->DoResponse( 404, "");
}
}
else {
$request->DoResponse( 404, "");
/**
* We read the resource first, so we can check if it matches (or does not match)
*/
$qry = new PgQuery( "SELECT * FROM caldav_data WHERE user_no = ? AND dav_name = ?;", (isset($request->user_no)?$request->user_no:$session->user_no), $request->path );
if ( $qry->Exec("DELETE") && $qry->rows == 1 ) {
$delete_row = $qry->Fetch();
if ( (isset($request->etag_if_match) && $request->etag_if_match != $delete_row->dav_etag) ) {
$request->DoResponse( 412, translate("Resource does not match 'If-Match' header - not deleted") );
}
$qry = new PgQuery( "DELETE FROM caldav_data WHERE user_no = ? AND dav_name = ?;", (isset($request->user_no)?$request->user_no:$session->user_no), $request->path );
if ( $qry->Exec("DELETE") ) {
@dbg_error_log( "DELETE", "DELETE: User: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
$request->DoResponse( 204 );
}
else {
$request->DoResponse( 500, translate("Error querying database.") );
}
}
else {
$request->DoResponse( 404, "");
}
}
?>