Skip to content

Commit

Permalink
Fix Trashbin deletion event
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Sep 23, 2022
1 parent 2648f03 commit 05304d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
namespace OCA\Photos\AppInfo;

use OCA\DAV\Connector\Sabre\Principal;
use OCA\Photos\Listener\CacheEntryRemovedListener;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Files\Events\Node\NodeDeletedEvent;
use OCA\Photos\Event\MoveToTrashListener;
use OCP\Files\Cache\CacheEntryRemovedEvent;

class Application extends App implements IBootstrap {
public const APP_ID = 'photos';
Expand Down Expand Up @@ -63,7 +63,7 @@ public function __construct() {
public function register(IRegistrationContext $context): void {
/** Register $principalBackend for the DAV collection */
$context->registerServiceAlias('principalBackend', Principal::class);
$context->registerEventListener(NodeDeletedEvent::class, MoveToTrashListener::class);
$context->registerEventListener(CacheEntryRemovedEvent::class, CacheEntryRemovedListener::class);
}

public function boot(IBootContext $context): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?php

namespace OCA\Photos\Event;
namespace OCA\Photos\Listener;

use OCA\Photos\Album\AlbumMapper;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\Node\NodeDeletedEvent;
use OCA\Photos\Album\AlbumMapper;
use OCP\Files\Cache\CacheEntryRemovedEvent;

class MoveToTrashListener implements IEventListener {
class CacheEntryRemovedListener implements IEventListener {
private AlbumMapper $albumMapper;

public function __construct(AlbumMapper $albumMapper) {
$this->albumMapper = $albumMapper;
}

public function handle(Event $event): void {
if (!($event instanceof NodeDeletedEvent)) {
if (!($event instanceof CacheEntryRemovedEvent)) {
return;
}

// Remove node from all albums containing it.
$albums = $this->albumMapper->getForFile($event->getNode()->getId());
$albums = $this->albumMapper->getForFile($event->getFileId());
foreach ($albums as $album) {
$this->albumMapper->removeFile($album->getId(), $event->getNode()->getId());
$this->albumMapper->removeFile($album->getId(), $event->getFileId());
}
}
}

0 comments on commit 05304d7

Please sign in to comment.