@@ -2636,33 +2636,42 @@ public function searchPrincipalUri(string $principalUri,
26362636 }
26372637
26382638 /**
2639- * Searches through all of a users calendars and calendar objects to find
2640- * an object with a specific UID .
2639+ * Find the path of the calendar object with a given UID in calendars owned by
2640+ * a particular principal (user) .
26412641 *
2642- * This method should return the path to this object, relative to the
2643- * calendar home, so this path usually only contains two parts:
2642+ * When $calendarUri is provided, the lookup is restricted to that calendar.
2643+ * When it is null, all of the principal's calendars are searched. In that
2644+ * case, callers must use both path components returned by this method: the
2645+ * matching object may belong to a different calendar than one the caller
2646+ * currently has selected.
26442647 *
2645- * calendarpath/objectpath.ics
2648+ * Subscription and federated cached objects, deleted objects, and objects in
2649+ * deleted calendars are not considered.
26462650 *
2647- * If the uid is not found, return null.
2648- *
2649- * This method should only consider * objects that the principal owns, so
2650- * any calendars owned by other principals that also appear in this
2651- * collection should be ignored .
2651+ * The returned value is a path relative to the calendar home:
2652+ * "<calendar-uri>/<object-uri>". It is null when no matching object exists.
2653+ * UID uniqueness is guaranteed only within a calendar collection. Therefore,
2654+ * an unrestricted lookup can be ambiguous if multiple owned calendars contain
2655+ * the same UID .
26522656 *
26532657 * @param string $principalUri
26542658 * @param string $uid
2659+ * @param string|null $calendarUri Calendar URI to restrict the lookup to.
26552660 * @return string|null
26562661 */
26572662 #[\Override]
26582663 public function getCalendarObjectByUID ($ principalUri , $ uid , $ calendarUri = null ) {
26592664 $ query = $ this ->db ->getQueryBuilder ();
2660- $ query ->selectAlias ('c.uri ' , 'calendaruri ' )->selectAlias ('co.uri ' , 'objecturi ' )
2665+ $ query ->selectAlias ('c.uri ' , 'calendaruri ' )
2666+ ->selectAlias ('co.uri ' , 'objecturi ' )
26612667 ->from ('calendarobjects ' , 'co ' )
2662- ->leftJoin ('co ' , 'calendars ' , 'c ' , $ query ->expr ()->eq ('co.calendarid ' , 'c.id ' ))
2668+ ->join ('co ' , 'calendars ' , 'c ' , $ query ->expr ()->eq ('co.calendarid ' , 'c.id ' ))
26632669 ->where ($ query ->expr ()->eq ('c.principaluri ' , $ query ->createNamedParameter ($ principalUri )))
26642670 ->andWhere ($ query ->expr ()->eq ('co.uid ' , $ query ->createNamedParameter ($ uid )))
2665- ->andWhere ($ query ->expr ()->isNull ('co.deleted_at ' ));
2671+ ->andWhere ($ query ->expr ()->eq ('co.calendartype ' , $ query ->createNamedParameter (self ::CALENDAR_TYPE_CALENDAR )))
2672+ ->andWhere ($ query ->expr ()->isNull ('co.deleted_at ' ))
2673+ ->andWhere ($ query ->expr ()->isNull ('c.deleted_at ' ))
2674+ ->setMaxResults (1 );
26662675
26672676 if ($ calendarUri !== null ) {
26682677 $ query ->andWhere ($ query ->expr ()->eq ('c.uri ' , $ query ->createNamedParameter ($ calendarUri )));
@@ -2671,6 +2680,7 @@ public function getCalendarObjectByUID($principalUri, $uid, $calendarUri = null)
26712680 $ stmt = $ query ->executeQuery ();
26722681 $ row = $ stmt ->fetchAssociative ();
26732682 $ stmt ->closeCursor ();
2683+
26742684 if ($ row ) {
26752685 return $ row ['calendaruri ' ] . '/ ' . $ row ['objecturi ' ];
26762686 }
0 commit comments