1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OCA\Files\BackgroundJob; |
4
|
|
|
|
5
|
|
|
use OC\BackgroundJob\QueuedJob; |
6
|
|
|
use OCA\Files\Service\TransferOwnership\TransferOwnershipService; |
7
|
|
|
use OCP\ILogger; |
8
|
|
|
use OCP\IUserManager; |
9
|
|
|
|
10
|
|
|
class TransferOwnership extends QueuedJob { |
11
|
|
|
|
12
|
|
|
/** @var ILogger */ |
13
|
|
|
protected $logger; |
14
|
|
|
/** @var TransferOwnershipService */ |
15
|
|
|
protected $service; |
16
|
|
|
/** @var IUserManager */ |
17
|
|
|
protected $userManager; |
18
|
|
|
|
19
|
|
|
public function __construct(TransferOwnershipService $service, IUserManager $userManager) { |
20
|
|
|
$this->service = $service; |
21
|
|
|
$this->userManager = $userManager; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function execute($jobList, ILogger $logger = null) { |
25
|
|
|
$this->logger = $logger; |
26
|
|
|
parent::execute($jobList, $logger); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function run($argument) { |
30
|
|
|
// Get the arguments; |
31
|
|
|
$arguments = json_decode($argument); |
32
|
|
|
if (!isset($arguments['sourceUser'], $arguments['destinationUser'], $arguments['sourcePath'])) { |
33
|
|
|
$this->logger->error(self::class . ' called with invalid argument: '.$argument, ['app' => 'files']); |
34
|
|
|
return; |
35
|
|
|
} |
36
|
|
|
// Call the transfer service |
37
|
|
|
$sourceUser = $this->userManager->get($arguments['sourceUser']); |
38
|
|
|
$destinationUser = $this->userManager->get($arguments['destinationuser']); |
39
|
|
|
|
40
|
|
|
if ($sourceUser === null || $destinationUser === null) { |
41
|
|
|
$this->logger->error("Trasnfer job called with missing users", ['app' => 'files']); |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$sourcePath = $arguments['sourcePath']; |
46
|
|
|
try { |
47
|
|
|
$this->service->transfer($sourceUser, $destinationUser, $sourcePath); |
48
|
|
|
} catch (\Exception $e) { |
49
|
|
|
$this->logger->logException($e, ['app' => 'files']); |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->logger->info("Finished transfer of $sourcePath from {$sourceUser->getUID()} to {$destinationUser->getUID()}"); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
} |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.