1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OCA\Testing\Commands; |
4
|
|
|
|
5
|
|
|
use OC\Core\Command\Base; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class AddShare extends Base { |
11
|
|
|
protected function configure() { |
12
|
|
|
$this |
13
|
|
|
->setName('testing:add-share') |
14
|
|
|
->setDescription('Creates a share.') |
15
|
|
|
->addArgument('owner', |
16
|
|
|
InputArgument::REQUIRED, |
17
|
|
|
'Owner of the resource to be shared') |
18
|
|
|
->addArgument('path', |
19
|
|
|
InputArgument::REQUIRED, |
20
|
|
|
'Path to the resource to be shared') |
21
|
|
|
->addArgument('shareWith', |
22
|
|
|
InputArgument::REQUIRED, |
23
|
|
|
'User which receives the shared resource'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
27
|
|
|
$owner = $input->getArgument('owner'); |
28
|
|
|
$path = $input->getArgument('path'); |
29
|
|
|
$shareWith = $input->getArgument('shareWith'); |
30
|
|
|
|
31
|
|
|
$ownerFolder = \OC::$server->getUserFolder($owner); |
32
|
|
|
$resource = $ownerFolder->get($path); |
33
|
|
|
|
34
|
|
|
$shareManager = \OC::$server->getShareManager(); |
35
|
|
|
$share = $shareManager->newShare(); |
36
|
|
|
$share->setNode($resource); |
37
|
|
|
$share->setShareType(\OCP\Share::SHARE_TYPE_USER); |
38
|
|
|
$share->setSharedWith($shareWith); |
39
|
|
|
$share->setState(\OCP\Share::STATE_ACCEPTED); |
40
|
|
|
|
41
|
|
|
$share = $shareManager->createShare($share); |
42
|
|
|
$output->writeln("Share created with id: {$share->getId()}"); |
43
|
|
|
} |
44
|
|
|
} |