Skip to content

Commit 8813df9

Browse files
committed
refactor(dav): Pass UID from UploadHome to UploadFolder and CleanupService
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 7f0953d commit 8813df9

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

apps/dav/lib/Upload/CleanupService.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@
1010

1111
use OCA\DAV\BackgroundJob\UploadCleanup;
1212
use OCP\BackgroundJob\IJobList;
13-
use OCP\IUserSession;
1413

1514
class CleanupService {
1615
public function __construct(
17-
private IUserSession $userSession,
1816
private IJobList $jobList,
1917
) {
2018
}
2119

22-
public function addJob(string $folder) {
23-
$this->jobList->add(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]);
20+
public function addJob(string $uid, string $folder) {
21+
$this->jobList->add(UploadCleanup::class, ['uid' => $uid, 'folder' => $folder]);
2422
}
2523

26-
public function removeJob(string $folder) {
27-
$this->jobList->remove(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]);
24+
public function removeJob(string $uid, string $folder) {
25+
$this->jobList->remove(UploadCleanup::class, ['uid' => $uid, 'folder' => $folder]);
2826
}
2927
}

apps/dav/lib/Upload/UploadFolder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function __construct(
2121
private Directory $node,
2222
private CleanupService $cleanupService,
2323
private IStorage $storage,
24+
private string $uid,
2425
) {
2526
}
2627

@@ -89,7 +90,7 @@ public function delete() {
8990
$this->node->delete();
9091

9192
// Background cleanup job is not needed anymore
92-
$this->cleanupService->removeJob($this->getName());
93+
$this->cleanupService->removeJob($this->uid, $this->getName());
9394
}
9495

9596
public function getName() {

apps/dav/lib/Upload/UploadHome.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Sabre\DAV\ICollection;
1818

1919
class UploadHome implements ICollection {
20+
private string $uid;
2021
private ?Folder $uploadFolder = null;
2122

2223
public function __construct(
@@ -25,6 +26,12 @@ public function __construct(
2526
private readonly IRootFolder $rootFolder,
2627
private readonly IUserSession $userSession,
2728
) {
29+
$user = $this->userSession->getUser();
30+
if (!$user) {
31+
throw new Forbidden('Not logged in');
32+
}
33+
34+
$this->uid = $user->getUID();
2835
}
2936

3037
public function createFile($name, $data = null) {
@@ -35,16 +42,26 @@ public function createDirectory($name) {
3542
$this->impl()->createDirectory($name);
3643

3744
// Add a cleanup job
38-
$this->cleanupService->addJob($name);
45+
$this->cleanupService->addJob($this->uid, $name);
3946
}
4047

4148
public function getChild($name): UploadFolder {
42-
return new UploadFolder($this->impl()->getChild($name), $this->cleanupService, $this->getStorage());
49+
return new UploadFolder(
50+
$this->impl()->getChild($name),
51+
$this->cleanupService,
52+
$this->getStorage(),
53+
$this->uid,
54+
);
4355
}
4456

4557
public function getChildren(): array {
4658
return array_map(function ($node) {
47-
return new UploadFolder($node, $this->cleanupService, $this->getStorage());
59+
return new UploadFolder(
60+
$node,
61+
$this->cleanupService,
62+
$this->getStorage(),
63+
$this->uid,
64+
);
4865
}, $this->impl()->getChildren());
4966
}
5067

@@ -71,11 +88,7 @@ public function getLastModified() {
7188

7289
private function getUploadFolder(): Folder {
7390
if ($this->uploadFolder === null) {
74-
$user = $this->userSession->getUser();
75-
if (!$user) {
76-
throw new Forbidden('Not logged in');
77-
}
78-
$path = '/' . $user->getUID() . '/uploads';
91+
$path = '/' . $this->uid . '/uploads';
7992
try {
8093
$folder = $this->rootFolder->get($path);
8194
if (!$folder instanceof Folder) {

0 commit comments

Comments
 (0)