Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge listeners related to albums
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge authored and backportbot-nextcloud[bot] committed May 9, 2023
commit 1aea92914ca9ff1a572269405c99e6a7b8a5a933
1 change: 0 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use OCA\DAV\Events\SabrePluginAuthInitEvent;
use OCA\Photos\Listener\SabrePluginAuthInitListener;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\Photos\Listener\NodeDeletedListener;
use OCA\Photos\Listener\TagListener;
use OCA\Photos\Listener\GroupUserRemovedListener;
use OCA\Photos\Listener\GroupDeletedListener;
Expand Down
59 changes: 53 additions & 6 deletions lib/Listener/AlbumsManagementEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use OCP\Files\Node;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Cache\CacheEntryRemovedEvent;
use OCP\Files\Events\Node\NodeDeletedEvent;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\Share\Events\ShareDeletedEvent;
use OCP\User\Events\UserDeletedEvent;

Expand All @@ -20,11 +22,17 @@ public function __construct(AlbumMapper $albumMapper) {
}

public function handle(Event $event): void {
if ($event instanceof CacheEntryRemovedEvent) {
// Remove node from all albums containing it.
$albums = $this->albumMapper->getForFile($event->getFileId());
foreach ($albums as $album) {
$this->albumMapper->removeFile($album->getId(), $event->getFileId());
if ($event instanceof NodeDeletedEvent) {
try {
// Remove node from all albums containing it.
$albums = $this->albumMapper->getForFile($event->getNode()->getId());

foreach ($albums as $album) {
$this->albumMapper->removeFile($album->getId(), $event->getNode()->getId());
}
} catch(\Throwable $ex) {
// If an error occur, return silently as we don't want to block the rest of the deletion process.
// It happened already during migrations when the albums table is not yet created, but a folder is deleted by the theming app.
}
}

Expand All @@ -44,6 +52,45 @@ public function handle(Event $event): void {
fn ($node) => $this->albumMapper->removeFileWithOwner($node->getId(), $receiverId),
);
}

if ($event instanceof UserRemovedEvent) {
// Get all shared albums for this group:
$albums_group = $this->albumMapper->getSharedAlbumsForCollaborator($event->getGroup()->getGID(), AlbumMapper::TYPE_GROUP);
// Get all albums shared with this specific 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->getId() - $b->getId()));

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

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

// Get all users of this group:
$users = $event->getGroup()->getUsers();

foreach ($users as $user) {
// Get all albums shared with this specific 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->getId() - $b->getId()));

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

foreach ($albums_group as $album) {
$this->albumMapper->deleteGroupFromAlbumCollaboratorsList($event->getGroup()->getGID(), $album->getId());
}
}
}

private function forEachSubNode(Node $node, callable $callback): void {
Expand Down
47 changes: 0 additions & 47 deletions lib/Listener/GroupDeletedListener.php

This file was deleted.

34 changes: 0 additions & 34 deletions lib/Listener/GroupUserRemovedListener.php

This file was deleted.

34 changes: 0 additions & 34 deletions lib/Listener/NodeDeletedListener.php

This file was deleted.