From 6a51e569611a2a3306615efe42c09446fd91a975 Mon Sep 17 00:00:00 2001 From: ralf Date: Mon, 7 Nov 2022 20:50:45 +0100 Subject: [PATCH] allow to paginate through CalDAV/CardDAV autoindex start-page with accounts --- api/src/CalDAV.php | 39 ++++++++++++++++++++++++++++++++++++-- api/src/CalDAV/Handler.php | 4 ++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/api/src/CalDAV.php b/api/src/CalDAV.php index 2130dbbcd1..34f6b88ba6 100644 --- a/api/src/CalDAV.php +++ b/api/src/CalDAV.php @@ -387,6 +387,15 @@ class CalDAV extends HTTP_WebDAV_Server // make options (readonly) available to all class methods, eg. prop_requested $this->propfind_options = $options; + $nresults = null; + foreach($options['other'] ?? [] as $option) + { + if ($option['name'] === 'nresults' && (int)$option['data'] > 0) + { + $nresults = (int)$option['data']; + } + } + // parse path in form [/account_lid]/app[/more] $id = $app = $user = $user_prefix = null; if (!self::_parse_path($options['path'],$id,$app,$user,$user_prefix) && $app && !$user && $user !== 0) @@ -421,10 +430,24 @@ class CalDAV extends HTTP_WebDAV_Server $files['files'][] = $this->add_collection('/principals/', array( 'displayname' => lang('Accounts'), )); - foreach($this->accounts->search(array('type' => 'both','order'=>'account_lid')) as $account) + foreach($this->accounts->search([ + 'type' => 'both', + 'order' =>'account_lid', + 'start' => $_GET['start'] ?? 0, + 'offset' => $nresults, + ]) as $account) { $this->add_home($files, $path.$account['account_lid'].'/', $account['account_id'], $options['depth'] == 'infinity' ? 'infinity' : $options['depth']-1); } + + // if nresults-limit is set respond correct + if (isset($nresults) && $this->accounts->total > ($_GET['start'] ?? 0)+$nresults) + { + $handler = new CalDAV\Principals('calendar', $this); + $handler->sync_collection_toke = '?start='.(($_GET['start'] ?? 0)+$nresults); + $files['sync-token'] = [$handler, 'get_sync_collection_token']; + $files['sync-token-parameters'] = ['/', '', true]; + } } return true; } @@ -1239,9 +1262,11 @@ class CalDAV extends HTTP_WebDAV_Server */ protected function autoindex($options) { + $chunk_size = 500; $propfind_options = array( 'path' => $options['path'], 'depth' => 1, + 'other' => [['name' => 'nresults', 'data' => $chunk_size]], ); $files = array(); if (($ret = $this->PROPFIND($propfind_options,$files)) !== true) @@ -1328,6 +1353,16 @@ class CalDAV extends HTTP_WebDAV_Server } else { + if (!empty($files['sync-token-parameters'][2]) || !empty($_GET['start'])) + { + echo "\t". + (empty($_GET['start']) ? '' : + Html::a_href('<<< '.lang('Previous %1 accounts', $chunk_size), '/groupdav.php'.$options['path'].'?start='.max(0, $_GET['start']-$chunk_size))). + (!empty($_GET['start']) && !empty($files['sync-token-parameters'][2]) ? ' | ' : ''). + (empty($files['sync-token-parameters'][2]) ? '' : + Html::a_href(lang('Next %1 accounts', $chunk_size).' >>>', '/groupdav.php'.$options['path'].'?start='.(($_GET['start'] ?? 0)+$chunk_size))). + "\n"; + } echo "\n"; } echo '

'.lang('Properties')."

\n"; @@ -2531,4 +2566,4 @@ class CalDAV extends HTTP_WebDAV_Server return $_appName.'-'.$_eventID.'-'.$GLOBALS['egw_info']['server']['install_id']; } -} +} \ No newline at end of file diff --git a/api/src/CalDAV/Handler.php b/api/src/CalDAV/Handler.php index 79380364cd..b7cf467caa 100644 --- a/api/src/CalDAV/Handler.php +++ b/api/src/CalDAV/Handler.php @@ -754,10 +754,10 @@ abstract class Handler if (!isset($token)) $token = $this->getctag($path, $user); // never return current time, as more modifications might happen due to second granularity --> return 1sec less - if ($token >= (int)$GLOBALS['egw_info']['flags']['page_start_time']) + if (is_numeric($token) && $token >= (int)$GLOBALS['egw_info']['flags']['page_start_time']) { $token = (int)$GLOBALS['egw_info']['flags']['page_start_time'] - 1; } return $this->base_uri().$path.$token; } -} +} \ No newline at end of file