Add $c->auto_refresh_duration option to set a auto refresh on any GET calendar.
[davical.git] / inc / caldav-DELETE.php
blob1029816f4b918e45f2b8f4d642e3234f0152e5b8
1 <?php
2 /**
3 * CalDAV Server - handle DELETE method
5 * @package davical
6 * @subpackage caldav
7 * @author Andrew McMillan <andrew@mcmillan.net.nz>
8 * @copyright Catalyst .Net Ltd, Morphoss Ltd <http://www.morphoss.com/>
9 * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
11 dbg_error_log("delete", "DELETE method handler");
13 require_once('DAVResource.php');
14 $dav_resource = new DAVResource($request->path);
15 $container = $dav_resource->GetParentContainer();
16 $container->NeedPrivilege('DAV::unbind');
18 $lock_opener = $request->FailIfLocked();
20 require_once('schedule-functions.php');
22 function delete_collection( $id ) {
23 $params = array( ':collection_id' => $id );
24 $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 );
25 if ( $qry->Exec('DELETE',__LINE__,__FILE__) && $qry->rows() > 0 ) {
26 while( $row = $qry->Fetch() ) {
27 delete_collection($row->child_id);
31 if ( $qry->QDo("SELECT write_sync_change(collection_id, 404, caldav_data.dav_name) FROM caldav_data WHERE collection_id = :collection_id", $params )
32 && $qry->QDo("DELETE FROM property WHERE dav_name LIKE (SELECT dav_name FROM collection WHERE collection_id = :collection_id) || '%'", $params )
33 && $qry->QDo("DELETE FROM locks WHERE dav_name LIKE (SELECT dav_name FROM collection WHERE collection_id = :collection_id) || '%'", $params )
34 && $qry->QDo("DELETE FROM caldav_data WHERE collection_id = :collection_id", $params )
35 && $qry->QDo("DELETE FROM collection WHERE collection_id = :collection_id", $params ) ) {
36 @dbg_error_log( "DELETE", "DELETE (collection): User: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
37 return true;
39 return false;
43 if ( !$dav_resource->Exists() )$request->DoResponse( 404 );
45 if ( ! ( $dav_resource->resource_id() > 0 ) ) {
46 $request->DoResponse( 403 );
49 $qry = new AwlQuery();
50 $qry->Begin();
52 if ( $dav_resource->IsCollection() ) {
53 if ( $dav_resource->IsBinding() ) {
54 $params = array( ':dav_name' => $dav_resource->dav_name() );
56 if ( $qry->QDo("DELETE FROM dav_binding WHERE dav_name = :dav_name", $params )
57 && $qry->Commit() ) {
58 @dbg_error_log( "DELETE", "DELETE: Binding: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
59 $request->DoResponse( 204 );
62 else {
63 if ( delete_collection( $dav_resource->resource_id() ) && $qry->Commit() ) {
64 // Uncache anything to do with the collection
65 $cache = getCacheInstance();
66 $cache->delete( 'collection-'.$dav_resource->dav_name(), null );
67 $request->DoResponse( 204 );
71 else {
72 if ( (isset($request->etag_if_match) && $request->etag_if_match != $dav_resource->unique_tag() ) ) {
73 $request->DoResponse( 412, translate("Resource has changed on server - not deleted") );
76 // Check to see if we need to do any scheduling transactions for this one.
77 do_scheduling_for_delete($dav_resource);
79 // We need to serialise access to this process just for this collection
80 $cache = getCacheInstance();
81 $myLock = $cache->acquireLock('collection-'.$dav_resource->parent_path());
83 $params = array( ':dav_id' => $dav_resource->resource_id() );
84 if ( $qry->QDo("SELECT write_sync_change(collection_id, 404, caldav_data.dav_name) FROM caldav_data WHERE dav_id = :dav_id", $params )
85 && $qry->QDo("DELETE FROM property WHERE dav_name = (SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id)", $params )
86 && $qry->QDo("DELETE FROM locks WHERE dav_name = (SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id)", $params )
87 && $qry->QDo("DELETE FROM caldav_data WHERE dav_id = :dav_id", $params )
88 && $qry->Commit() ) {
89 @dbg_error_log( "DELETE", "DELETE: User: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path);
90 if ( function_exists('log_caldav_action') ) {
91 log_caldav_action( 'DELETE', $dav_resource->GetProperty('uid'), $dav_resource->GetProperty('user_no'), $dav_resource->GetProperty('collection_id'), $request->path );
93 $cache->delete( 'collection-'.$dav_resource->parent_path(), null );
94 $cache->releaseLock($myLock);
95 $request->DoResponse( 204 );
97 $cache->releaseLock($myLock);
100 $request->DoResponse( 500 );