1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: dbg_error_log("delete", "DELETE method handler");
12:
13: require_once('DAVResource.php');
14: $dav_resource = new DAVResource($request->path);
15: $container = $dav_resource->GetParentContainer();
16: $container->NeedPrivilege('DAV::unbind');
17:
18: $lock_opener = $request->FailIfLocked();
19:
20: require_once('schedule-functions.php');
21:
22: function delete_collection( $id ) {
23: global $session, $request;
24:
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);
30: }
31: }
32:
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);
39: return true;
40: }
41: return false;
42: }
43:
44:
45: if ( !$dav_resource->Exists() )$request->DoResponse( 404 );
46:
47: if ( ! ( $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 );
50: }
51:
52: $qry = new AwlQuery();
53: $qry->Begin();
54:
55: if ( $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() );
60:
61: if ( $qry->QDo("DELETE FROM dav_binding WHERE dav_name = :dav_name", $params )
62: && $qry->Commit() ) {
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 );
68: }
69: }
70: else {
71: if ( delete_collection( $dav_resource->resource_id() ) && $qry->Commit() ) {
72:
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 );
77: }
78: }
79: $cache->releaseLock($myLock);
80: }
81: else {
82: if ( isset($request->etag_if_match) && $request->etag_if_match != $dav_resource->unique_tag() && $request->etag_if_match != "*" ) {
83: $request->DoResponse( 412, translate("Resource has changed on server - not deleted") );
84: }
85:
86:
87: do_scheduling_for_delete($dav_resource);
88:
89:
90: $cache = getCacheInstance();
91: $myLock = $cache->acquireLock('collection-'.$dav_resource->parent_path());
92:
93: $collection_id = $dav_resource->GetProperty('collection_id');
94: $params = array( ':dav_id' => $dav_resource->resource_id() );
95: if ( $qry->QDo("DELETE FROM property WHERE dav_name = (SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id)", $params )
96: && $qry->QDo("DELETE FROM locks WHERE dav_name = (SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id)", $params )
97: && $qry->QDo("SELECT write_sync_change(collection_id, 404, caldav_data.dav_name) FROM caldav_data WHERE dav_id = :dav_id", $params )
98: && $qry->QDo("DELETE FROM caldav_data WHERE dav_id = :dav_id", $params ) ) {
99: if ( function_exists('log_caldav_action') ) {
100: log_caldav_action( 'DELETE', $dav_resource->GetProperty('uid'), $dav_resource->GetProperty('user_no'), $collection_id, $request->path );
101: }
102:
103: $qry->Commit();
104: @dbg_error_log( "DELETE", "DELETE: User: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
105:
106: if ( function_exists('post_commit_action') ) {
107: post_commit_action( 'DELETE', $dav_resource->GetProperty('uid'), $dav_resource->GetProperty('user_no'), $collection_id, $request->path );
108: }
109:
110: $cache->delete( 'collection-'.$dav_resource->parent_path(), null );
111: $cache->releaseLock($myLock);
112: $request->DoResponse( 204 );
113: }
114: $cache->releaseLock($myLock);
115: }
116:
117: $request->DoResponse( 500 );
118: