Skip to content

Commit

Permalink
Group deletion listener: use new mapper method
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Spannagel <simonspa@kth.se>
  • Loading branch information
Simon Spannagel committed Jan 24, 2023
1 parent 7027273 commit c2ac203
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 5 additions & 6 deletions lib/Listener/GroupDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function handle(Event $event): void {
}

// Get all shared albums for this group:
$albums_group = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($event->getGroup()->getGID(), AlbumMapper::TYPE_GROUP);
$albums_group = $this->albumMapper->getSharedAlbumsForCollaborator($event->getGroup()->getGID(), AlbumMapper::TYPE_GROUP);

// Get all users of this group:
$users = $event->getGroup()->getUsers();
Expand All @@ -29,20 +29,19 @@ public function handle(Event $event): void {
$uid = $user->getUID();

// Get all albums shared with this specific user:
$albums_user = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($user->getUID(), AlbumMapper::TYPE_USER);
$albums_user = $this->albumMapper->getSharedAlbumsForCollaborator($user->getUID(), AlbumMapper::TYPE_USER);

// Get all group-shared albums that are not directly shared with the removed user in addition
$albums = array_udiff($albums_group, $albums_user, fn ($a, $b) => ($a->getAlbum()->getId() - $b->getAlbum()->getId()));

$albums = array_udiff($albums_group, $albums_user, fn ($a, $b) => ($a->getId() - $b->getId()));

// Remove their photos from theses albums:
foreach ($albums as $album) {
$this->albumMapper->removeFilesForUser($album->getAlbum()->getId(), $user->getUID());
$this->albumMapper->removeFilesForUser($album->getId(), $user->getUID());
}
}

foreach ($albums_group as $album) {
$this->albumMapper->deleteGroupFromAlbumCollaboratorsList($event->getGroup()->getGID(), $album->getAlbum()->getId());
$this->albumMapper->deleteGroupFromAlbumCollaboratorsList($event->getGroup()->getGID(), $album->getId());
}
}
}
8 changes: 4 additions & 4 deletions lib/Listener/GroupUserRemovedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public function handle(Event $event): void {
}

// Get all shared albums for this group:
$albums_group = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($event->getGroup()->getGID(), AlbumMapper::TYPE_GROUP);
$albums_group = $this->albumMapper->getSharedAlbumsForCollaborator($event->getGroup()->getGID(), AlbumMapper::TYPE_GROUP);
// Get all albums shared with this specific user:
$albums_user = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($event->getUser()->getUID(), AlbumMapper::TYPE_USER);
$albums_user = $this->albumMapper->getSharedAlbumsForCollaborator($event->getUser()->getUID(), AlbumMapper::TYPE_USER);
// Get all group-shared albums that are not directly shared with the removed user in addition
$albums = array_udiff($albums_group, $albums_user, fn ($a, $b) => ($a->getAlbum()->getId() - $b->getAlbum()->getId()));
$albums = array_udiff($albums_group, $albums_user, fn ($a, $b) => ($a->getId() - $b->getId()));

// Remove their photos from theses albums:
foreach ($albums as $album) {
$this->albumMapper->removeFilesForUser($album->getAlbum()->getId(), $event->getUser()->getUID());
$this->albumMapper->removeFilesForUser($album->getId(), $event->getUser()->getUID());
}
}
}

0 comments on commit c2ac203

Please sign in to comment.