@@ -249,11 +249,11 @@ private function getLastAdded(int $albumId): int {
249249
250250 /**
251251 * @param int $albumId
252- * @return array<array{'id': string, 'label': string, 'source ': int}>
252+ * @return array<array{'id': string, 'label': string, 'type ': int}>
253253 */
254254 public function getCollaborators (int $ albumId ): array {
255255 $ query = $ this ->connection ->getQueryBuilder ();
256- $ query ->select ("collaborator_id " , "collaborator_source " )
256+ $ query ->select ("collaborator_id " , "collaborator_type " )
257257 ->from ("photos_collaborators " )
258258 ->where ($ query ->expr ()->eq ('album_id ' , $ query ->createNamedParameter ($ albumId , IQueryBuilder::PARAM_INT )));
259259
@@ -263,15 +263,15 @@ public function getCollaborators(int $albumId): array {
263263 /** @var IUser|IGroup|null */
264264 $ collaborator = null ;
265265
266- switch ($ row ['collaborator_source ' ]) {
266+ switch ($ row ['collaborator_type ' ]) {
267267 case self ::TYPE_USER :
268268 $ collaborator = $ this ->userManager ->get ($ row ['collaborator_id ' ]);
269269 break ;
270270 case self ::TYPE_GROUP :
271271 $ collaborator = $ this ->groupManager ->get ($ row ['collaborator_id ' ]);
272272 break ;
273273 default :
274- throw new \Exception ('Invalid collaborator source : ' . $ row ['collaborator_source ' ]);
274+ throw new \Exception ('Invalid collaborator type : ' . $ row ['collaborator_type ' ]);
275275 }
276276
277277 if (is_null ($ collaborator )) {
@@ -281,7 +281,7 @@ public function getCollaborators(int $albumId): array {
281281 return [
282282 'id ' => $ row ['collaborator_id ' ],
283283 'label ' => $ collaborator ->getDisplayName (),
284- 'source ' => ( int ) $ row ['collaborator_source ' ],
284+ 'type ' => $ row ['collaborator_type ' ],
285285 ];
286286 }, $ rows );
287287
@@ -290,16 +290,18 @@ public function getCollaborators(int $albumId): array {
290290
291291 /**
292292 * @param int $albumId
293- * @param array{'id': string, 'label': string, 'source ': int} $newCollaborators
293+ * @param array{'id': string, 'label': string, 'type ': int} $collaborators
294294 */
295- public function setCollaborators (int $ albumId , array $ newCollaborators ): void {
295+ public function setCollaborators (int $ albumId , array $ collaborators ): void {
296296 $ existingCollaborators = $ this ->getCollaborators ($ albumId );
297297
298- $ collaboratorsToAdd = array_udiff ($ newCollaborators , $ existingCollaborators , fn ($ a , $ b ) => strcmp ($ a ['id ' ].$ a ['source ' ], $ b ['id ' ].$ b ['source ' ]));
299- $ collaboratorsToRemove = array_udiff ($ existingCollaborators , $ newCollaborators , fn ($ a , $ b ) => strcmp ($ a ['id ' ].$ a ['source ' ], $ b ['id ' ].$ b ['source ' ]));
298+ $ collaboratorsToAdd = array_udiff ($ collaborators , $ existingCollaborators , fn ($ a , $ b ) => strcmp ($ a ['id ' ].$ a ['type ' ], $ b ['id ' ].$ b ['type ' ]));
299+ $ collaboratorsToRemove = array_udiff ($ existingCollaborators , $ collaborators , fn ($ a , $ b ) => strcmp ($ a ['id ' ].$ a ['type ' ], $ b ['id ' ].$ b ['type ' ]));
300+
301+ $ this ->connection ->beginTransaction ();
300302
301303 foreach ($ collaboratorsToAdd as $ collaborator ) {
302- switch ($ collaborator ['source ' ]) {
304+ switch ($ collaborator ['type ' ]) {
303305 case self ::TYPE_USER :
304306 if (is_null ($ this ->userManager ->get ($ collaborator ['id ' ]))) {
305307 throw new \Exception ('Unknown collaborator: ' . $ collaborator ['id ' ]);
@@ -311,14 +313,14 @@ public function setCollaborators(int $albumId, array $newCollaborators): void {
311313 }
312314 break ;
313315 default :
314- throw new \Exception ('Invalid collaborator source : ' . $ collaborator ['source ' ]);
316+ throw new \Exception ('Invalid collaborator type : ' . $ collaborator ['type ' ]);
315317 }
316318
317319 $ query = $ this ->connection ->getQueryBuilder ();
318320 $ query ->insert ('photos_collaborators ' )
319321 ->setValue ('album_id ' , $ query ->createNamedParameter ($ albumId , IQueryBuilder::PARAM_INT ))
320322 ->setValue ('collaborator_id ' , $ query ->createNamedParameter ($ collaborator ['id ' ]))
321- ->setValue ('collaborator_source ' , $ query ->createNamedParameter ($ collaborator ['source ' ], IQueryBuilder::PARAM_INT ))
323+ ->setValue ('collaborator_type ' , $ query ->createNamedParameter ($ collaborator ['type ' ], IQueryBuilder::PARAM_INT ))
322324 ->executeStatement ();
323325 }
324326
@@ -327,16 +329,19 @@ public function setCollaborators(int $albumId, array $newCollaborators): void {
327329 $ query ->delete ('photos_collaborators ' )
328330 ->where ($ query ->expr ()->eq ('album_id ' , $ query ->createNamedParameter ($ albumId , IQueryBuilder::PARAM_INT )))
329331 ->andWhere ($ query ->expr ()->eq ('collaborator_id ' , $ query ->createNamedParameter ($ collaborator ['id ' ])))
330- ->andWhere ($ query ->expr ()->eq ('collaborator_source ' , $ query ->createNamedParameter ($ collaborator ['source ' ], IQueryBuilder::PARAM_INT )))
332+ ->andWhere ($ query ->expr ()->eq ('collaborator_type ' , $ query ->createNamedParameter ($ collaborator ['type ' ], IQueryBuilder::PARAM_INT )))
331333 ->executeStatement ();
332334 }
335+
336+ $ this ->connection ->commit ();
333337 }
334338
335339 /**
336- * @param string $userId
340+ * @param string $collaboratorId
341+ * @param string $collaboratorsType - The type of the collaborator, either a user or a group.
337342 * @return AlbumWithFiles[]
338343 */
339- public function getSharedAlbumsForCollaboratorWithFiles (string $ collaboratorId , int $ collaboratorSource ): array {
344+ public function getSharedAlbumsForCollaboratorWithFiles (string $ collaboratorId , int $ collaboratorType ): array {
340345 $ query = $ this ->connection ->getQueryBuilder ();
341346 $ rows = $ query
342347 ->select ("fileid " , "mimetype " , "a.album_id " , "size " , "mtime " , "etag " , "location " , "created " , "last_added_photo " , "added " , 'owner ' )
@@ -348,7 +353,7 @@ public function getSharedAlbumsForCollaboratorWithFiles(string $collaboratorId,
348353 ->leftJoin ("a " , "photos_albums_files " , "p " , $ query ->expr ()->eq ("a.album_id " , "p.album_id " ))
349354 ->leftJoin ("p " , "filecache " , "f " , $ query ->expr ()->eq ("p.file_id " , "f.fileid " ))
350355 ->where ($ query ->expr ()->eq ('collaborator_id ' , $ query ->createNamedParameter ($ collaboratorId )))
351- ->andWhere ($ query ->expr ()->eq ('collaborator_source ' , $ query ->createNamedParameter ($ collaboratorSource , IQueryBuilder::PARAM_INT )))
356+ ->andWhere ($ query ->expr ()->eq ('collaborator_type ' , $ query ->createNamedParameter ($ collaboratorType , IQueryBuilder::PARAM_INT )))
352357 ->executeQuery ()
353358 ->fetchAll ();
354359
@@ -379,31 +384,31 @@ public function getSharedAlbumsForCollaboratorWithFiles(string $collaboratorId,
379384 * @param int $albumId
380385 * @return void
381386 */
382- public function deleteCollaboratorFromAlbum (string $ userId , int $ albumId ): void {
387+ public function deleteUserFromAlbumCollaboratorsList (string $ userId , int $ albumId ): void {
383388 // TODO: only delete if this was not a group share
384389 $ query = $ this ->connection ->getQueryBuilder ();
385390 $ query ->delete ('photos_collaborators ' )
386391 ->where ($ query ->expr ()->eq ('album_id ' , $ query ->createNamedParameter ($ albumId , IQueryBuilder::PARAM_INT )))
387392 ->andWhere ($ query ->expr ()->eq ('collaborator_id ' , $ query ->createNamedParameter ($ userId )))
388- ->andWhere ($ query ->expr ()->eq ('collaborator_source ' , $ query ->createNamedParameter (self ::TYPE_USER , IQueryBuilder::PARAM_INT )))
393+ ->andWhere ($ query ->expr ()->eq ('collaborator_type ' , $ query ->createNamedParameter (self ::TYPE_USER , IQueryBuilder::PARAM_INT )))
389394 ->executeStatement ();
390395 }
391396
392397 /**
393398 * @param string $collaboratorId
394- * @param int $collaboratorSource
399+ * @param int $collaboratorType
395400 * @param int $fileId
396401 * @return AlbumInfo[]
397402 */
398- public function getAlbumForCollaboratorIdAndFileId (string $ collaboratorId , int $ collaboratorSource , int $ fileId ): array {
403+ public function getAlbumForCollaboratorIdAndFileId (string $ collaboratorId , int $ collaboratorType , int $ fileId ): array {
399404 $ query = $ this ->connection ->getQueryBuilder ();
400405 $ rows = $ query
401406 ->select ("a.album_id " , "name " , "user " , "location " , "created " , "last_added_photo " )
402407 ->from ("photos_collaborators " , "c " )
403408 ->leftJoin ("c " , "photos_albums " , "a " , $ query ->expr ()->eq ("a.album_id " , "c.album_id " ))
404409 ->leftJoin ("a " , "photos_albums_files " , "p " , $ query ->expr ()->eq ("a.album_id " , "p.album_id " ))
405410 ->where ($ query ->expr ()->eq ('collaborator_id ' , $ query ->createNamedParameter ($ collaboratorId )))
406- ->andWhere ($ query ->expr ()->eq ('collaborator_source ' , $ query ->createNamedParameter ($ collaboratorSource , IQueryBuilder::PARAM_INT )))
411+ ->andWhere ($ query ->expr ()->eq ('collaborator_type ' , $ query ->createNamedParameter ($ collaboratorType , IQueryBuilder::PARAM_INT )))
407412 ->andWhere ($ query ->expr ()->eq ('file_id ' , $ query ->createNamedParameter ($ fileId )))
408413 ->groupBy ('album_id ' )
409414 ->executeQuery ()
0 commit comments