From a34203a7b85a859f98ea1039e46a68d782940e1b Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Tue, 10 Apr 2012 23:30:07 +1200 Subject: [PATCH] Sometimes we want the action hook to be post commit. This adds another hook, and makes log_caldav_action() regular across both PUT and DELETE (in a transaction), adding post_commit_hook() as a method with the same signature which is called after the actual commit, and also matches in both cases. --- inc/caldav-DELETE.php | 14 ++++++++++---- inc/caldav-PUT-functions.php | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/inc/caldav-DELETE.php b/inc/caldav-DELETE.php index 1029816f..db1be0bf 100644 --- a/inc/caldav-DELETE.php +++ b/inc/caldav-DELETE.php @@ -84,12 +84,18 @@ else { if ( $qry->QDo("SELECT write_sync_change(collection_id, 404, caldav_data.dav_name) FROM caldav_data WHERE dav_id = :dav_id", $params ) && $qry->QDo("DELETE FROM property WHERE dav_name = (SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id)", $params ) && $qry->QDo("DELETE FROM locks WHERE dav_name = (SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id)", $params ) - && $qry->QDo("DELETE FROM caldav_data WHERE dav_id = :dav_id", $params ) - && $qry->Commit() ) { + && $qry->QDo("DELETE FROM caldav_data WHERE dav_id = :dav_id", $params ) ) { + if ( function_exists('log_caldav_action') ) { + log_caldav_action( 'DELETE', $dav_resource->GetProperty('uid'), $dav_resource->GetProperty('user_no'), $dav_resource->GetProperty('collection_id'), $request->path ); + } + + $qry->Commit(); @dbg_error_log( "DELETE", "DELETE: User: %d, ETag: %s, Path: %s", $session->user_no, $request->etag_if_match, $request->path); - if ( function_exists('log_caldav_action') ) { - log_caldav_action( 'DELETE', $dav_resource->GetProperty('uid'), $dav_resource->GetProperty('user_no'), $dav_resource->GetProperty('collection_id'), $request->path ); + + if ( function_exists('post_commit_action') ) { + post_commit_action( 'DELETE', $dav_resource->GetProperty('uid'), $dav_resource->GetProperty('user_no'), $dav_resource->GetProperty('collection_id'), $request->path ); } + $cache->delete( 'collection-'.$dav_resource->parent_path(), null ); $cache->releaseLock($myLock); $request->DoResponse( 204 ); diff --git a/inc/caldav-PUT-functions.php b/inc/caldav-PUT-functions.php index fb7cebe7..3e824695 100644 --- a/inc/caldav-PUT-functions.php +++ b/inc/caldav-PUT-functions.php @@ -1358,6 +1358,10 @@ EOSQL; $qry->QDo("SELECT write_sync_change( $collection_id, $sync_change, :dav_name)", array(':dav_name' => $path ) ); $qry->Commit(); + if ( function_exists('post_commit_action') ) { + post_commit_action( $put_action_type, $first->GetPValue('UID'), $user_no, $collection_id, $path ); + } + // Uncache anything to do with the collection $cache = getCacheInstance(); $cache_ns = 'collection-'.preg_replace( '{/[^/]*$}', '/', $path);