Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
use OCA\DAV\Events\SabrePluginAuthInitEvent;
use OCA\Photos\Listener\SabrePluginAuthInitListener;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\Photos\Listener\CacheEntryRemovedListener;
use OCA\Photos\Listener\NodeDeletedListener;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Files\Cache\CacheEntryRemovedEvent;
use OCP\Files\Events\Node\NodeDeletedEvent;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
use OCA\Photos\Album\AlbumMapper;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Cache\CacheEntryRemovedEvent;
use OCP\Files\Events\Node\NodeDeletedEvent;

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

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

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

try {
// Remove node from all albums containing it.
$albums = $this->albumMapper->getForFile($event->getFileId());
$albums = $this->albumMapper->getForFile($event->getNode()->getId());

foreach ($albums as $album) {
$this->albumMapper->removeFile($album->getId(), $event->getFileId());
$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.
Expand Down