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

AddShare   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 14 1
A execute() 0 18 1
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
}