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
1 change: 1 addition & 0 deletions apps/files_sharing/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Turning the feature off removes shared files and folders on the server for all s
<job>OCA\Files_Sharing\ExpireSharesJob</job>
<job>OCA\Files_Sharing\SharesReminderJob</job>
<job>OCA\Files_Sharing\BackgroundJob\FederatedSharesDiscoverJob</job>
<job>OCA\Files_Sharing\BackgroundJob\ExternalShareScanJob</job>
</background-jobs>

<repair-steps>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'OCA\\Files_Sharing\\Activity\\Settings\\ShareActivitySettings' => $baseDir . '/../lib/Activity/Settings/ShareActivitySettings.php',
'OCA\\Files_Sharing\\Activity\\Settings\\Shared' => $baseDir . '/../lib/Activity/Settings/Shared.php',
'OCA\\Files_Sharing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Files_Sharing\\BackgroundJob\\ExternalShareScanJob' => $baseDir . '/../lib/BackgroundJob/ExternalShareScanJob.php',
'OCA\\Files_Sharing\\BackgroundJob\\FederatedSharesDiscoverJob' => $baseDir . '/../lib/BackgroundJob/FederatedSharesDiscoverJob.php',
'OCA\\Files_Sharing\\Cache' => $baseDir . '/../lib/Cache.php',
'OCA\\Files_Sharing\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ComposerStaticInitFiles_Sharing
'OCA\\Files_Sharing\\Activity\\Settings\\ShareActivitySettings' => __DIR__ . '/..' . '/../lib/Activity/Settings/ShareActivitySettings.php',
'OCA\\Files_Sharing\\Activity\\Settings\\Shared' => __DIR__ . '/..' . '/../lib/Activity/Settings/Shared.php',
'OCA\\Files_Sharing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Files_Sharing\\BackgroundJob\\ExternalShareScanJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/ExternalShareScanJob.php',
'OCA\\Files_Sharing\\BackgroundJob\\FederatedSharesDiscoverJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/FederatedSharesDiscoverJob.php',
'OCA\\Files_Sharing\\Cache' => __DIR__ . '/..' . '/../lib/Cache.php',
'OCA\\Files_Sharing\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
Expand Down
49 changes: 49 additions & 0 deletions apps/files_sharing/lib/BackgroundJob/ExternalShareScanJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OCA\Files_Sharing\BackgroundJob;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use Psr\Log\LoggerInterface;

/**
* Scans an external share with a specific path
*/
class ExternalShareScanJob extends QueuedJob {
public function __construct(
private readonly IConfig $config,
private readonly IRootFolder $rootFolder,
private readonly LoggerInterface $logger,
ITimeFactory $time,
) {
parent::__construct($time);
}

#[\Override]
protected function run($argument): void {
if ($this->config->getSystemValueBool('files_no_background_scan', false)) {
return;
}

[$userId, $path] = $argument;
try {
$this->rootFolder
->getUserFolder($userId)
->get($path)
->getStorage()
->getScanner()
->scan('');
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), [ 'exception' => $e ]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

namespace OCA\Files_Sharing\Controller;

use OCA\Files_Sharing\BackgroundJob\ExternalShareScanJob;
use OCA\Files_Sharing\External\Manager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\BackgroundJob\IJobList;
use OCP\IRequest;

/**
Expand All @@ -24,6 +26,7 @@ public function __construct(
string $appName,
IRequest $request,
private readonly Manager $externalManager,
private IJobList $jobList,
) {
parent::__construct($appName, $request);
}
Expand All @@ -44,6 +47,7 @@ public function create(string $id): JSONResponse {
$externalShare = $this->externalManager->getShare($id);
if ($externalShare !== false) {
$this->externalManager->acceptShare($externalShare);
$this->jobList->add(ExternalShareScanJob::class, [$externalShare->getUser(), $externalShare->getMountpoint()]);
}
return new JSONResponse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\Files_Sharing\External\ExternalShare;
use OCA\Files_Sharing\External\Manager;
use OCP\AppFramework\Http\JSONResponse;
use OCP\BackgroundJob\IJobList;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;

Expand All @@ -23,18 +24,21 @@
class ExternalShareControllerTest extends \Test\TestCase {
private IRequest&MockObject $request;
private Manager&MockObject $externalManager;
private IJobList&MockObject $jobList;

protected function setUp(): void {
parent::setUp();
$this->request = $this->createMock(IRequest::class);
$this->externalManager = $this->createMock(Manager::class);
$this->jobList = $this->createMock(IJobList::class);
}

public function getExternalShareController(): ExternalSharesController {
return new ExternalSharesController(
'files_sharing',
$this->request,
$this->externalManager,
$this->jobList,
);
}

Expand All @@ -58,6 +62,9 @@ public function testCreate(): void {
->expects($this->once())
->method('acceptShare')
->with($share);
$this->jobList
->expects($this->once())
->method('add');

$this->assertEquals(new JSONResponse(), $this->getExternalShareController()->create('4'));
}
Expand Down
Loading