Completed
Pull Request — master (#217)
by Victor
18:53 queued 15s
created

IndexController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 48
ccs 0
cts 31
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
B ajaxAction() 0 29 2
1
<?php
2
3
/**
4
 * @author Victor Dubiniuk <[email protected]>
5
 *
6
 * @copyright Copyright (c) 2015, ownCloud, Inc.
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace Owncloud\Updater\Controller;
24
25
use Symfony\Component\Console\Input\StringInput;
26
use Symfony\Component\Console\Output\BufferedOutput;
27
use Owncloud\Updater\Formatter\HtmlOutputFormatter;
28
use Owncloud\Updater\Http\Request;
29
30
class IndexController {
31
32
	/** @var \Pimple\Container */
33
	protected $container;
34
	
35
	/** @var Request */
36
	protected $request;
37
38
	public function __construct(\Pimple\Container $container, $request = null){
39
		$this->container = $container;
40
		if (is_null($request)){
41
			$this->request = new Request(['post' => $_POST]);
42
		}else {
43
			$this->request = $request;
44
		}
45
	}
46
47
	public function ajaxAction(){
48
		$application = $this->container['application'];
49
50
		$command = $this->request->postParameter('command');
51
52
		$input = new StringInput($command);
53
		$input->setInteractive(false);
54
55
		$output = new BufferedOutput();
56
		$formatter = $output->getFormatter();
57
		$formatter->setDecorated(true);
58
		$output->setFormatter(new HtmlOutputFormatter($formatter));
59
60
		$application->setAutoExit(false);
61
// Some commands  dump things out instead of returning a value
62
		ob_start();
63
		$errorCode = $application->run($input, $output);
64
		if (!$result = $output->fetch()){
65
			$result = ob_get_contents(); // If empty, replace it by the catched output
66
		}
67
		ob_end_clean();
68
69
		return [
70
			'input' => $command,
71
			'output' => $result,
72
			'environment' => '',
73
			'error_code' => $errorCode
74
		];
75
	}
76
77
}
78