From 8f38332fce27132818b8870260704ca35b1fc0b4 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Mon, 27 Jan 2025 22:57:05 +1300 Subject: [PATCH] Set DAVResource type correctly when restoring from memcache Assuming we're always dealing with a Principal isn't correct. --- inc/DAVResource.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/inc/DAVResource.php b/inc/DAVResource.php index f88b16e5..dcb45078 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -575,29 +575,34 @@ EOSQL; $cache_ns = 'collection-'.preg_replace( '{/[^/]*$}', '/', $this->dav_name); $cache_key = 'dav_resource'.$session->user_no; $this->collection = $cache->get( $cache_ns, $cache_key ); + if ( $this->collection === false ) { $this->ReadCollectionFromDatabase(); + if ( $this->collection->type != 'principal' && $this->_collection_is_cacheable ) { $cache_ns = 'collection-'.$this->collection->dav_name; @dbg_error_log( 'Cache', ':FetchCollection: Setting cache ns "%s" key "%s". Type: %s', $cache_ns, $cache_key, $this->collection->type ); $cache->set( $cache_ns, $cache_key, $this->collection ); } + @dbg_error_log( 'DAVResource', ':FetchCollection: Found collection named "%s" of type "%s".', $this->collection->dav_name, $this->collection->type ); } else { - @dbg_error_log( 'Cache', ':FetchCollection: Got cache ns "%s" key "%s". Type: %s', $cache_ns, $cache_key, $this->collection->type ); - if ( preg_match( '#^(/[^/]+)/?$#', $this->dav_name, $matches) - || preg_match( '#^((/principals/[^/]+/)[^/]+)/?$#', $this->dav_name, $matches) ) { + @dbg_error_log( 'Cache', ':FetchCollection: Got cache ns "%s" key "%s". dav_name: "%s", Type: %s', $cache_ns, $cache_key, $this->collection->dav_name, $this->collection->type ); + + if ($this->collection->type == 'principal') { $this->_is_principal = true; $this->FetchPrincipal(); $this->collection->is_principal = true; - $this->collection->type = 'principal'; - } else { - if ($this->collection->type == 'proxy') { - $this->_is_proxy_resource = true; - $this->proxy_type = $this->collection->proxy_type; - } + + } else if ($this->collection->type == 'calendar') { + $this->_is_calendar = true; + + } else if ($this->collection->type == 'proxy') { + $this->_is_proxy_resource = true; + $this->proxy_type = $this->collection->proxy_type; } + @dbg_error_log( 'DAVResource', ':FetchCollection: Read cached collection named "%s" of type "%s".', $this->collection->dav_name, $this->collection->type ); }