@@ -2316,6 +2316,11 @@ public function searchPrincipalUri(string $principalUri,
23162316 $ calendarOr = [];
23172317 $ searchOr = [];
23182318
2319+ $ start = null ;
2320+ $ end = null ;
2321+
2322+ // Todo: The retries when $hasLimit && $hasTimeRange from https://github.com/nextcloud/server/pull/45222 should also be applied here to the calendarObjectIdQuery
2323+
23192324 // Fetch calendars and subscription
23202325 $ calendars = $ this ->getCalendarsForUser ($ principalUri );
23212326 $ subscriptions = $ this ->getSubscriptionsForUser ($ principalUri );
@@ -2394,19 +2399,21 @@ public function searchPrincipalUri(string $principalUri,
23942399 if (isset ($ options ['offset ' ])) {
23952400 $ calendarObjectIdQuery ->setFirstResult ($ options ['offset ' ]);
23962401 }
2397- if (isset ($ options ['timerange ' ])) {
2398- if (isset ($ options ['timerange ' ]['start ' ]) && $ options ['timerange ' ]['start ' ] instanceof DateTimeInterface) {
2399- $ calendarObjectIdQuery ->andWhere ($ calendarObjectIdQuery ->expr ()->gt (
2400- 'lastoccurence ' ,
2401- $ calendarObjectIdQuery ->createNamedParameter ($ options ['timerange ' ]['start ' ]->getTimeStamp ()),
2402- ));
2403- }
2404- if (isset ($ options ['timerange ' ]['end ' ]) && $ options ['timerange ' ]['end ' ] instanceof DateTimeInterface) {
2405- $ calendarObjectIdQuery ->andWhere ($ calendarObjectIdQuery ->expr ()->lt (
2406- 'firstoccurence ' ,
2407- $ calendarObjectIdQuery ->createNamedParameter ($ options ['timerange ' ]['end ' ]->getTimeStamp ()),
2408- ));
2409- }
2402+ if (isset ($ options ['timerange ' ]['start ' ]) && $ options ['timerange ' ]['start ' ] instanceof DateTimeInterface) {
2403+ /** @var DateTimeInterface $start */
2404+ $ start = $ options ['timerange ' ]['start ' ];
2405+ $ calendarObjectIdQuery ->andWhere ($ calendarObjectIdQuery ->expr ()->gt (
2406+ 'lastoccurence ' ,
2407+ $ calendarObjectIdQuery ->createNamedParameter ($ start ->getTimestamp ()),
2408+ ));
2409+ }
2410+ if (isset ($ options ['timerange ' ]['end ' ]) && $ options ['timerange ' ]['end ' ] instanceof DateTimeInterface) {
2411+ /** @var DateTimeInterface $end */
2412+ $ end = $ options ['timerange ' ]['end ' ];
2413+ $ calendarObjectIdQuery ->andWhere ($ calendarObjectIdQuery ->expr ()->lt (
2414+ 'firstoccurence ' ,
2415+ $ calendarObjectIdQuery ->createNamedParameter ($ end ->getTimestamp ()),
2416+ ));
24102417 }
24112418
24122419 $ result = $ calendarObjectIdQuery ->executeQuery ();
@@ -2421,17 +2428,22 @@ public function searchPrincipalUri(string $principalUri,
24212428 ->from ('calendarobjects ' )
24222429 ->where ($ query ->expr ()->in ('id ' , $ query ->createNamedParameter ($ matches , IQueryBuilder::PARAM_INT_ARRAY )));
24232430
2424- $ result = $ query ->executeQuery ();
2425- $ calendarObjects = [];
2426- while (($ array = $ result ->fetchAssociative ()) !== false ) {
2427- $ array ['calendarid ' ] = (int )$ array ['calendarid ' ];
2428- $ array ['calendartype ' ] = (int )$ array ['calendartype ' ];
2429- $ array ['calendardata ' ] = $ this ->readBlob ($ array ['calendardata ' ]);
2431+ $ calendarObjects = $ this ->searchCalendarObjects ($ query , $ start , $ end );
24302432
2431- $ calendarObjects [] = $ array ;
2432- }
2433- $ result ->closeCursor ();
2434- return $ calendarObjects ;
2433+ return array_map (function ($ event ) use ($ start , $ end ) {
2434+ $ calendarData = Reader::read ($ event ['calendardata ' ]);
2435+
2436+ // Expand recurrences if an explicit time range is requested
2437+ if ($ calendarData instanceof VCalendar && isset ($ start , $ end )) {
2438+ $ calendarData = $ calendarData ->expand ($ start , $ end );
2439+ }
2440+
2441+ $ event ['calendardata ' ] = $ calendarData ->serialize ();
2442+ $ event ['calendarid ' ] = (int )$ event ['calendarid ' ];
2443+ $ event ['calendartype ' ] = (int )$ event ['calendartype ' ];
2444+
2445+ return $ event ;
2446+ }, $ calendarObjects );
24352447 }, $ this ->db );
24362448 }
24372449
0 commit comments