1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Victor Dubiniuk <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Owncloud\Updater\Utils; |
23
|
|
|
|
24
|
|
|
use Symfony\Component\Process\Process; |
25
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException; |
26
|
|
|
use Owncloud\Updater\Utils\Locator; |
27
|
|
|
|
28
|
|
|
class OccRunner { |
29
|
|
|
/** |
30
|
|
|
* @var Locator $locator |
31
|
|
|
*/ |
32
|
|
|
protected $locator; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @param Locator $locator |
37
|
|
|
*/ |
38
|
|
|
public function __construct(Locator $locator){ |
39
|
|
|
$this->locator = $locator; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function run($args){ |
43
|
|
|
$process = new Process($this->locator->getPathToOccFile() . ' ' . $args); |
44
|
|
|
$process->run(); |
45
|
|
|
|
46
|
|
|
if (!$process->isSuccessful()){ |
47
|
|
|
throw new ProcessFailedException($process); |
48
|
|
|
} |
49
|
|
|
return $process->getOutput(); |
50
|
|
|
} |
51
|
|
|
|
52
|
3 |
|
public function runJson($args){ |
53
|
3 |
|
$plain = $this->run($args . ' --output "json"'); |
54
|
3 |
|
$decoded = json_decode($plain, true); |
55
|
3 |
|
if (!is_array($decoded)){ |
56
|
|
|
throw new \UnexpectedValueException('Could not parse a response for ' . $args . '. Please check if the current shell user can run occ command. Raw output: ' . PHP_EOL . $plain); |
57
|
|
|
} |
58
|
3 |
|
return $decoded; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|