Skip to content
Open
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
10 changes: 8 additions & 2 deletions lib/Command/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 17 additions & 6 deletions lib/Listeners/NodeRenamedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeRenamedEvent>
*/
class NodeRenamedListener implements IEventListener {
public function __construct(
private readonly TrashBackend $trashBackend,
private readonly VersionsBackend $versionsBackend,
private readonly ContainerInterface $container,
) {
}

Expand All @@ -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();
Expand All @@ -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 !== '') {
Expand All @@ -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);
}
}
}
3 changes: 2 additions & 1 deletion lib/Migration/RepairMisplacedTrashItemsStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 9 additions & 4 deletions tests/Listeners/NodeRenamedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Loading