Update UpdateSoftwareCommand.php

This commit is contained in:
M011N1N6 2025-03-06 04:13:14 +03:30 committed by GitHub
parent 6de0c1eeb5
commit 86fedf3f35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,5 @@
<?php <?php
namespace App\Command; namespace App\Command;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
@ -291,7 +290,7 @@ class UpdateSoftwareCommand extends Command
private function backupDatabase(): string private function backupDatabase(): string
{ {
$backupFile = $this->backupDir . '/db_backup_' . time() . '.sql'; $backupFile = $this->backupDir . '/db_backup_' . time() . '.sql';
$dbUrl = $this->params->get('DATABASE_URL'); $dbUrl = $this->params->get('database_url');
$urlParts = parse_url($dbUrl); $urlParts = parse_url($dbUrl);
$dbHost = $urlParts['host'] ?? 'localhost'; $dbHost = $urlParts['host'] ?? 'localhost';
@ -304,19 +303,21 @@ class UpdateSoftwareCommand extends Command
'-h', $dbHost, '-h', $dbHost,
'-u', $dbUser, '-u', $dbUser,
'-p' . $dbPass, '-p' . $dbPass,
$dbName, $dbName
'>',
$backupFile
]; ];
$this->runProcess($command, $this->rootDir, new \Symfony\Component\Console\Output\NullOutput()); $process = new Process($command, $this->rootDir);
if (!file_exists($backupFile)) { $process->setTimeout(3600);
$process->mustRun();
file_put_contents($backupFile, $process->getOutput());
if (!file_exists($backupFile) || filesize($backupFile) === 0) {
throw new \RuntimeException('Failed to create database backup.'); throw new \RuntimeException('Failed to create database backup.');
} }
$this->logger->info("Database backup created at: $backupFile");
return $backupFile; return $backupFile;
} }
private function backupArchive(): string private function backupArchive(): string
{ {
$tarFile = $this->backupDir . '/hesabixArchive_backup_' . time() . '.tar'; $tarFile = $this->backupDir . '/hesabixArchive_backup_' . time() . '.tar';