diff --git a/lib/Command/Scan.php b/lib/Command/Scan.php index 5be722281..03edab2fc 100644 --- a/lib/Command/Scan.php +++ b/lib/Command/Scan.php @@ -108,9 +108,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($inputPath === '') { $mounts = [ 'files' => $this->mountProvider->getMount($folderWithPermissions, '/' . $folder->mountPoint), - 'trashbin' => $this->mountProvider->getTrashMount($folderWithPermissions, '/' . $folder->mountPoint, $this->storageFactory, null), - 'version' => $this->mountProvider->getVersionsMount($folderWithPermissions, '/' . $folder->mountPoint, $this->storageFactory) ]; + + if (interface_exists(\OCA\Files_Versions\Versions\IVersionBackend::class)) { + $mounts['version'] = $this->mountProvider->getVersionsMount($folderWithPermissions, '/' . $folder->mountPoint, $this->storageFactory); + } + + if (interface_exists(\OCA\Files_Trashbin\Trash\ITrashBackend::class)) { + $mounts['trashbin'] = $this->mountProvider->getTrashMount($folderWithPermissions, '/' . $folder->mountPoint, $this->storageFactory, null); + } } else { $mounts = [ 'files' => $this->mountProvider->getMount($folderWithPermissions, '/' . $folder->mountPoint) diff --git a/lib/Listeners/NodeRenamedListener.php b/lib/Listeners/NodeRenamedListener.php index d20742424..f726aa709 100644 --- a/lib/Listeners/NodeRenamedListener.php +++ b/lib/Listeners/NodeRenamedListener.php @@ -16,14 +16,14 @@ use OCP\EventDispatcher\IEventListener; use OCP\Files\Events\Node\NodeRenamedEvent; use OCP\Files\Folder; +use Psr\Container\ContainerInterface; /** * @template-implements IEventListener */ class NodeRenamedListener implements IEventListener { public function __construct( - private readonly TrashBackend $trashBackend, - private readonly VersionsBackend $versionsBackend, + private readonly ContainerInterface $container, ) { } @@ -34,6 +34,13 @@ public function handle(Event $event): void { return; } + $hasVersionApp = interface_exists(\OCA\Files_Versions\Versions\IVersionBackend::class); + $hasTrashApp = interface_exists(\OCA\Files_Trashbin\Trash\ITrashBackend::class); + + if (!$hasVersionApp && !$hasTrashApp) { + return; // nothing to do + } + $target = $event->getTarget(); $targetStorage = $target->getStorage(); @@ -52,7 +59,7 @@ public function handle(Event $event): void { $sourceFolder = $sourceParentStorage->getFolder(); $targetFolder = $targetStorage->getFolder(); - if ($target instanceof Folder) { + if ($hasTrashApp && $target instanceof Folder) { // Get internal path on parent to avoid NotFoundException $sourceParentPath = $sourceParent->getInternalPath(); if ($sourceParentPath !== '') { @@ -62,11 +69,15 @@ public function handle(Event $event): void { $sourceParentPath .= $source->getName(); $targetPath = $target->getInternalPath(); - $this->trashBackend->updateTrashedChildren($sourceParentStorage, $targetStorage, $sourceParentPath, $targetPath); + /** @var TrashBackend $trashBackend */ + $trashBackend = $this->container->get(TrashBackend::class); + $trashBackend->updateTrashedChildren($sourceParentStorage, $targetStorage, $sourceParentPath, $targetPath); } - if ($sourceFolder->id !== $targetFolder->id) { - $this->versionsBackend->moveVersionsBetweenFolders($target, $sourceFolder, $targetFolder); + if ($hasVersionApp && $sourceFolder->id !== $targetFolder->id) { + /** @var VersionsBackend $versionsBackend */ + $versionsBackend = $this->container->get(VersionsBackend::class); + $versionsBackend->moveVersionsBetweenFolders($target, $sourceFolder, $targetFolder); } } } diff --git a/lib/Migration/RepairMisplacedTrashItemsStep.php b/lib/Migration/RepairMisplacedTrashItemsStep.php index 32c79c2e3..a3f1359bd 100644 --- a/lib/Migration/RepairMisplacedTrashItemsStep.php +++ b/lib/Migration/RepairMisplacedTrashItemsStep.php @@ -33,7 +33,8 @@ public function getName(): string { #[\Override] public function run(IOutput $output): void { - if ($this->appConfig->getAppValueBool('checked_for_incorrect_storage_for_trash_items')) { + if ($this->appConfig->getAppValueBool('checked_for_incorrect_storage_for_trash_items') + || !interface_exists(\OCA\Files_Trashbin\Trash\ITrashBackend::class)) { return; } diff --git a/tests/Listeners/NodeRenamedListenerTest.php b/tests/Listeners/NodeRenamedListenerTest.php index fbb3d550b..55034909a 100644 --- a/tests/Listeners/NodeRenamedListenerTest.php +++ b/tests/Listeners/NodeRenamedListenerTest.php @@ -19,6 +19,7 @@ use OCP\Files\File; use OCP\Files\Folder; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerInterface; use Test\TestCase; class NodeRenamedListenerTest extends TestCase { @@ -40,10 +41,14 @@ protected function setUp(): void { $this->trashBackend = $this->createMock(TrashBackend::class); $this->versionBackend = $this->createMock(VersionsBackend::class); - $this->listener = new NodeRenamedListener( - $this->trashBackend, - $this->versionBackend, - ); + $container = $this->createMock(ContainerInterface::class); + $container->method('get') + ->willReturnMap([ + [TrashBackend::class, $this->trashBackend], + [VersionsBackend::class, $this->versionBackend], + ]); + + $this->listener = new NodeRenamedListener($container); $this->sourceParentStorage = $this->createMock(GroupFolderStorage::class); $this->sourceParentStorage