11dbg_error_log(
"delete",
"DELETE method handler");
13require_once(
'DAVResource.php');
15$container = $dav_resource->GetParentContainer();
16$container->NeedPrivilege(
'DAV::unbind');
18$lock_opener = $request->FailIfLocked();
20require_once(
'schedule-functions.php');
22function delete_collection( $id ) {
23 global $session, $request;
25 $params = array(
':collection_id' => $id );
26 $qry =
new AwlQuery(
'SELECT child.collection_id AS child_id FROM collection child JOIN collection parent ON (parent.dav_name = child.parent_container) WHERE parent.collection_id = :collection_id', $params );
27 if ( $qry->Exec(
'DELETE',__LINE__,__FILE__) && $qry->rows() > 0 ) {
28 while( $row = $qry->Fetch() ) {
29 delete_collection($row->child_id);
33 if ( $qry->QDo(
"SELECT write_sync_change(collection_id, 404, caldav_data.dav_name) FROM caldav_data WHERE collection_id = :collection_id", $params )
34 && $qry->QDo(
"DELETE FROM property WHERE dav_name LIKE (SELECT dav_name FROM collection WHERE collection_id = :collection_id) || '%'", $params )
35 && $qry->QDo(
"DELETE FROM locks WHERE dav_name LIKE (SELECT dav_name FROM collection WHERE collection_id = :collection_id) || '%'", $params )
36 && $qry->QDo(
"DELETE FROM caldav_data WHERE collection_id = :collection_id", $params )
37 && $qry->QDo(
"DELETE FROM collection WHERE collection_id = :collection_id", $params ) ) {
38 @dbg_error_log(
"DELETE",
"DELETE (collection): User: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
45if ( !$dav_resource->Exists() )$request->DoResponse( 404 );
47if ( ! ( $dav_resource->resource_id() > 0 ) ) {
48 @dbg_error_log(
"DELETE",
": failed: User: %d, ETag: %s, Path: %s, ResourceID: %d", $session->user_no, $request->etag_if_match, $request->path, $dav_resource->resource_id());
49 $request->DoResponse( 403 );
55if ( $dav_resource->IsCollection() ) {
56 $cache = getCacheInstance();
57 $myLock = $cache->acquireLock(
'collection-'.$dav_resource->parent_path());
58 if ( $dav_resource->IsBinding() ) {
59 $params = array(
':dav_name' => $dav_resource->dav_name() );
61 if ( $qry->QDo(
"DELETE FROM dav_binding WHERE dav_name = :dav_name", $params )
63 $cache->delete(
'collection-'.$dav_resource->dav_name(),
null );
64 $cache->delete(
'collection-'.$dav_resource->parent_path(),
null );
65 $cache->releaseLock($myLock);
66 @dbg_error_log(
"DELETE",
"DELETE: Binding: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
67 $request->DoResponse( 204 );
71 if ( delete_collection( $dav_resource->resource_id() ) && $qry->Commit() ) {
73 $cache->delete(
'collection-'.$dav_resource->dav_name(),
null );
74 $cache->delete(
'collection-'.$dav_resource->parent_path(),
null );
75 $cache->releaseLock($myLock);
76 $request->DoResponse( 204 );
79 $cache->releaseLock($myLock);
82 $request->CheckEtagMatch( $dav_resource->Exists(), $dav_resource->unique_tag() );
85 do_scheduling_for_delete($dav_resource);
88 $cache = getCacheInstance();
89 $myLock = $cache->acquireLock(
'collection-'.$dav_resource->parent_path());
91 $collection_id = $dav_resource->GetProperty(
'collection_id');
92 if ( function_exists(
'log_caldav_action') ) {
93 log_caldav_action(
'DELETE', $dav_resource->GetProperty(
'uid'), $dav_resource->GetProperty(
'user_no'), $collection_id, $request->path );
95 $params = array(
':dav_id' => $dav_resource->resource_id() );
96 if ( $qry->QDo(
"DELETE FROM property WHERE dav_name = (SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id)", $params )
97 && $qry->QDo(
"DELETE FROM locks WHERE dav_name = (SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id)", $params )
98 && $qry->QDo(
"SELECT write_sync_change(collection_id, 404, caldav_data.dav_name) FROM caldav_data WHERE dav_id = :dav_id", $params )
99 && $qry->QDo(
"DELETE FROM caldav_data WHERE dav_id = :dav_id", $params ) ) {
102 @dbg_error_log(
"DELETE",
"DELETE: User: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
104 if ( function_exists(
'post_commit_action') ) {
105 post_commit_action(
'DELETE', $dav_resource->GetProperty(
'uid'), $dav_resource->GetProperty(
'user_no'), $collection_id, $request->path );
108 $cache->delete(
'collection-'.$dav_resource->parent_path(),
null );
109 $cache->releaseLock($myLock);
110 $request->DoResponse( 204 );
112 $cache->releaseLock($myLock);
115$request->DoResponse( 500 );