mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-10 09:19:35 +00:00
Extracted logic used by both BackupManager and UpdateExecutor to new service
This commit is contained in:
parent
68ff0721ce
commit
1ccc3ad440
3 changed files with 89 additions and 75 deletions
|
|
@ -46,6 +46,7 @@ class UpdateExecutor
|
|||
private array $steps = [];
|
||||
|
||||
private ?string $currentLogFile = null;
|
||||
private CommandRunHelper $commandRunHelper;
|
||||
|
||||
public function __construct(
|
||||
#[Autowire(param: 'kernel.project_dir')]
|
||||
|
|
@ -58,6 +59,7 @@ class UpdateExecutor
|
|||
#[Autowire(param: 'app.debug_mode')]
|
||||
private readonly bool $debugMode = false,
|
||||
) {
|
||||
$this->commandRunHelper = new CommandRunHelper($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -516,36 +518,7 @@ class UpdateExecutor
|
|||
*/
|
||||
private function runCommand(array $command, string $description, int $timeout = 120): string
|
||||
{
|
||||
$process = new Process($command, $this->project_dir);
|
||||
$process->setTimeout($timeout);
|
||||
|
||||
// Set environment variables needed for Composer and other tools
|
||||
// This is especially important when running as www-data which may not have HOME set
|
||||
// We inherit from current environment and override/add specific variables
|
||||
$currentEnv = getenv();
|
||||
if (!is_array($currentEnv)) {
|
||||
$currentEnv = [];
|
||||
}
|
||||
$env = array_merge($currentEnv, [
|
||||
'HOME' => $this->project_dir,
|
||||
'COMPOSER_HOME' => $this->project_dir . '/var/composer',
|
||||
'PATH' => getenv('PATH') ?: '/usr/local/bin:/usr/bin:/bin',
|
||||
]);
|
||||
$process->setEnv($env);
|
||||
|
||||
$output = '';
|
||||
$process->run(function ($type, $buffer) use (&$output) {
|
||||
$output .= $buffer;
|
||||
});
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
$errorOutput = $process->getErrorOutput() ?: $process->getOutput();
|
||||
throw new \RuntimeException(
|
||||
sprintf('%s failed: %s', $description, trim($errorOutput))
|
||||
);
|
||||
}
|
||||
|
||||
return $output;
|
||||
return $this->commandRunHelper->runCommand($command, $description, $timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue