Completed
Pull Request — master (#32311)
by Thomas
10:49
created

AddShare::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
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
}