diff --git a/lib/Occ.php b/lib/Occ.php index aaafb55..ad9a59e 100644 --- a/lib/Occ.php +++ b/lib/Occ.php @@ -52,7 +52,8 @@ public function __construct(IRequest $request) { */ public function execute() { $command = $this->request->getParam("command", ""); - $envVariables = $this->request->getParam("env_variables", []); + $reqEnvVars = $this->request->getParam("env_variables", []); + $envVars = array_merge($this->getDefaultEnv(), $reqEnvVars); $args = \preg_split("/[\s]+/", $command); $args = \array_map( @@ -73,7 +74,7 @@ function ($arg) { $descriptor, $pipes, \realpath("../"), - $envVariables + $envVars ); $lastStdOut = \stream_get_contents($pipes[1]); $lastStdErr = \stream_get_contents($pipes[2]); @@ -88,4 +89,21 @@ function ($arg) { return new Result($result, $resultCode); } + + // Taken from https://github.com/symfony/process/blob/master/Process.php + private function getDefaultEnv() + { + $env = array(); + foreach ($_SERVER as $k => $v) { + if (\is_string($v) && false !== $v = getenv($k)) { + $env[$k] = $v; + } + } + foreach ($_ENV as $k => $v) { + if (\is_string($v)) { + $env[$k] = $v; + } + } + return $env; + } }