@@ -1201,16 +1201,18 @@ public function getDeletedCalendarObjects(int $deletedBefore): array {
12011201 * @throws Exception
12021202 */
12031203 public function getDeletedCalendarObjectsByPrincipal (string $ principalUri ): array {
1204- $ result = $ this ->collectDeletedCalendarObjectsForPrincipal ($ principalUri , null );
1204+ $ result = [];
1205+ $ this ->collectDeletedCalendarObjectsForPrincipal ($ principalUri , $ result , null );
12051206 foreach ($ this ->getProxyDelegators ($ principalUri ) as $ delegator => $ hasProxyWrite ) {
12061207 $ overlay = $ hasProxyWrite ? Backend::ACCESS_READ_WRITE : Backend::ACCESS_READ ;
1207- $ result = array_merge ( $ result , $ this ->collectDeletedCalendarObjectsForPrincipal ($ delegator , $ overlay) );
1208+ $ this ->collectDeletedCalendarObjectsForPrincipal ($ delegator , $ result , $ overlay );
12081209 }
1209- return $ result ;
1210+ return array_values ( $ result) ;
12101211 }
12111212
12121213 /**
1213- * Run the owned + shared trashbin queries for $principalUri and merge into $result.
1214+ * Run the owned + shared trashbin queries for $principalUri and merge the
1215+ * results into $result, keyed by calendar object id.
12141216 *
12151217 * @param string $principalUri principal whose calendars to scan.
12161218 * @param array $result accumulator keyed by calendar object id; merged in-place.
@@ -1219,11 +1221,9 @@ public function getDeletedCalendarObjectsByPrincipal(string $principalUri): arra
12191221 * effective share access for that accessor (READ_WRITE for proxy-write,
12201222 * READ for proxy-read). null means $principalUri is the accessor itself.
12211223 */
1222- private function collectDeletedCalendarObjectsForPrincipal (string $ principalUri , ?int $ proxyOverlay ): array {
1224+ private function collectDeletedCalendarObjectsForPrincipal (string $ principalUri , array & $ result , ?int $ proxyOverlay ): void {
12231225 [$ principalUri , $ principals ] = $ this ->resolvePrincipal ($ principalUri );
12241226
1225- $ result = [];
1226-
12271227 // Owned calendars
12281228 $ query = $ this ->db ->getQueryBuilder ();
12291229 $ query ->select (['co.id ' , 'co.uri ' , 'co.lastmodified ' , 'co.etag ' , 'co.calendarid ' , 'co.size ' , 'co.componenttype ' , 'co.classification ' , 'co.deleted_at ' ])
@@ -1240,8 +1240,9 @@ private function collectDeletedCalendarObjectsForPrincipal(string $principalUri,
12401240 continue ;
12411241 }
12421242 [, $ ownerName ] = Uri \split ($ row ['calendarprincipaluri ' ]);
1243- $ calendarUri = $ proxyOverlay !== null ? $ row ['calendaruri ' ] . '_delegated_by_ ' . $ ownerName : $ row ['calendaruri ' ];
1244- $ result [$ row ['id ' ]] = $ this ->rowToDeletedCalendarObject ($ row , $ calendarUri , false , $ proxyOverlay );
1243+ $ isDelegated = $ proxyOverlay !== null ;
1244+ $ calendarUri = $ isDelegated ? $ row ['calendaruri ' ] . '_delegated_by_ ' . $ ownerName : $ row ['calendaruri ' ];
1245+ $ result [$ row ['id ' ]] = $ this ->rowToDeletedCalendarObject ($ row , $ calendarUri , false , $ proxyOverlay , $ isDelegated ? $ principalUri : null );
12451246 }
12461247 $ stmt ->closeCursor ();
12471248
@@ -1265,10 +1266,9 @@ private function collectDeletedCalendarObjectsForPrincipal(string $principalUri,
12651266 continue ;
12661267 }
12671268 [, $ ownerName ] = Uri \split ($ row ['calendarprincipaluri ' ]);
1268- $ result [$ row ['id ' ]] = $ this ->rowToDeletedCalendarObject ($ row , $ row ['calendaruri ' ] . '_shared_by_ ' . $ ownerName , false , $ effective );
1269+ $ result [$ row ['id ' ]] = $ this ->rowToDeletedCalendarObject ($ row , $ row ['calendaruri ' ] . '_shared_by_ ' . $ ownerName , false , $ effective, null );
12691270 }
12701271 $ stmt ->closeCursor ();
1271- return array_values ($ result );
12721272 }
12731273
12741274 /**
@@ -1327,7 +1327,7 @@ private function getProxyDelegators(string $principalUri): array {
13271327 return $ delegators ;
13281328 }
13291329
1330- private function rowToDeletedCalendarObject (array $ row , string $ calendarUri , bool $ includeData = false , ?int $ sharedAccess = null ): array {
1330+ private function rowToDeletedCalendarObject (array $ row , string $ calendarUri , bool $ includeData = false , ?int $ sharedAccess = null , ? string $ delegator = null ): array {
13311331 $ deletedAt = isset ($ row ['deleted_at ' ]) ? (int )$ row ['deleted_at ' ] : null ;
13321332 $ result = [
13331333 'id ' => $ row ['id ' ],
@@ -1342,6 +1342,7 @@ private function rowToDeletedCalendarObject(array $row, string $calendarUri, boo
13421342 'component ' => strtolower ($ row ['componenttype ' ]),
13431343 'classification ' => (int )$ row ['classification ' ],
13441344 'deleted_at ' => $ deletedAt ,
1345+ 'delegator ' => $ delegator ,
13451346 '{ ' . \OCA \DAV \DAV \Sharing \Plugin::NS_NEXTCLOUD . '}deleted-at ' => $ deletedAt ,
13461347 ];
13471348 if ($ sharedAccess !== null ) {
@@ -2704,6 +2705,7 @@ public function getDeletedCalendarObjectByIdForPrincipal(int $id, string $princi
27042705 * @param int $id
27052706 * @param string $principalUri
27062707 * @param int|null $proxyOverlay see collectDeletedCalendarObjectsForPrincipal.
2708+ * @return array|null
27072709 */
27082710 private function findDeletedCalendarObjectForPrincipal (int $ id , string $ principalUri , ?int $ proxyOverlay ): ?array {
27092711 [$ principalUri , $ principals ] = $ this ->resolvePrincipal ($ principalUri );
@@ -2724,8 +2726,9 @@ private function findDeletedCalendarObjectForPrincipal(int $id, string $principa
27242726
27252727 if ($ row ) {
27262728 [, $ ownerName ] = Uri \split ($ row ['calendarprincipaluri ' ]);
2727- $ calendarUri = $ proxyOverlay !== null ? $ row ['calendaruri ' ] . '_delegated_by_ ' . $ ownerName : $ row ['calendaruri ' ];
2728- return $ this ->rowToDeletedCalendarObject ($ row , $ calendarUri , true , $ proxyOverlay );
2729+ $ isDelegated = $ proxyOverlay !== null ;
2730+ $ calendarUri = $ isDelegated ? $ row ['calendaruri ' ] . '_delegated_by_ ' . $ ownerName : $ row ['calendaruri ' ];
2731+ return $ this ->rowToDeletedCalendarObject ($ row , $ calendarUri , true , $ proxyOverlay , $ isDelegated ? $ principalUri : null );
27292732 }
27302733
27312734 // Check shared calendars; order by access ASC so the most permissive
@@ -2752,7 +2755,7 @@ private function findDeletedCalendarObjectForPrincipal(int $id, string $principa
27522755
27532756 $ effective = $ this ->effectiveAccess ((int )$ row ['shareaccess ' ], $ proxyOverlay );
27542757 [, $ ownerName ] = Uri \split ($ row ['calendarprincipaluri ' ]);
2755- return $ this ->rowToDeletedCalendarObject ($ row , $ row ['calendaruri ' ] . '_shared_by_ ' . $ ownerName , true , $ effective );
2758+ return $ this ->rowToDeletedCalendarObject ($ row , $ row ['calendaruri ' ] . '_shared_by_ ' . $ ownerName , true , $ effective, null );
27562759 }
27572760
27582761 /**
0 commit comments