v7.0.0-beta.2 release
This commit is contained in:
1 parent
6595fd0eb5
commit
fa8eba7a0d
1165 files changed
+107118
-762127
No files matched your search
@@ -2,20 +2,30 @@
|
||||
|
||||
namespace App\Console\Commands\Core;
|
||||
|
||||
use App\Console\Commands\Core\Concerns\BundledExtensionUpdatePrompt;
|
||||
use App\Extension\CoreVersionChecker;
|
||||
use App\Extension\Helpers\CoreBackupHelper;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Extension\TemplateManager;
|
||||
use App\Extension\Vendor\Exceptions\VendorInstallException;
|
||||
use App\Extension\Vendor\VendorMode;
|
||||
use App\Services\CoreUpdateService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CoreUpdateCommand extends Command
|
||||
{
|
||||
use BundledExtensionUpdatePrompt;
|
||||
|
||||
protected $signature = 'core:update
|
||||
{--force : 버전 비교 없이 강제 업데이트}
|
||||
{--no-backup : 백업 생성 건너뛰기}
|
||||
{--no-maintenance : 유지보수 모드 활성화 건너뛰기}
|
||||
{--local : 로컬 코드베이스를 업데이트 소스로 사용 (GitHub 스킵)}
|
||||
{--source= : 수동 업데이트용 소스 디렉토리 경로 (GitHub 다운로드 대신 지정 디렉토리 사용)}';
|
||||
{--source= : 수동 업데이트용 소스 디렉토리 경로 (GitHub 다운로드 대신 지정 디렉토리 사용)}
|
||||
{--zip= : 수동 업데이트용 ZIP 파일 경로 (GitHub 다운로드 대신 지정 ZIP 추출 사용)}
|
||||
{--vendor-mode=auto : vendor 설치 모드 (auto|composer|bundled)}';
|
||||
|
||||
protected $description = '그누보드7 코어를 최신 버전으로 업데이트합니다';
|
||||
|
||||
@@ -29,21 +39,56 @@ class CoreUpdateCommand extends Command
|
||||
*/
|
||||
public function handle(CoreUpdateService $service): int
|
||||
{
|
||||
// 코어 업데이트 진행 플래그: 업데이트 중에는 일시적 버전 불일치로 인한 자동 비활성화를
|
||||
// 차단해야 한다 (CoreServiceProvider::validateAndDeactivateIncompatibleExtensions 및
|
||||
// spawn 자식이 모두 이 플래그를 감지). 커맨드 종료 시 프로세스 env 도 함께 소멸하므로
|
||||
// 정리 로직 불필요.
|
||||
$_ENV['G7_UPDATE_IN_PROGRESS'] = '1';
|
||||
$_SERVER['G7_UPDATE_IN_PROGRESS'] = '1';
|
||||
putenv('G7_UPDATE_IN_PROGRESS=1');
|
||||
|
||||
$backupPath = null;
|
||||
$maintenanceEnabled = false;
|
||||
$fromVersion = CoreVersionChecker::getCoreVersion();
|
||||
$toVersion = $fromVersion;
|
||||
$secret = null;
|
||||
$logEntries = [];
|
||||
$ownershipSnapshot = [];
|
||||
|
||||
$log = function (string $message) use (&$logEntries) {
|
||||
$logEntries[] = '['.date('H:i:s').'] '.$message;
|
||||
};
|
||||
|
||||
$this->warnIfFileOwnerMismatch($log);
|
||||
|
||||
$sourceDir = $this->option('source');
|
||||
$zipPath = $this->option('zip');
|
||||
|
||||
try {
|
||||
// ── 시스템 요구사항 검증 (--source / --local 모드에서는 스킵) ──
|
||||
// --source 와 --zip 동시 지정 금지
|
||||
if ($sourceDir && $zipPath) {
|
||||
$this->error('--source 와 --zip 은 동시에 지정할 수 없습니다. 하나만 선택하세요.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
if (($sourceDir || $zipPath) && $this->option('local')) {
|
||||
$this->error('--local 은 --source / --zip 과 동시에 사용할 수 없습니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// --zip 옵션 검증 (zip 은 ZipArchive/unzip 추출이 필요하므로 시스템 요구사항 검증 대상)
|
||||
if ($zipPath) {
|
||||
$resolvedZip = realpath($zipPath);
|
||||
if (! $resolvedZip || ! is_file($resolvedZip)) {
|
||||
$this->error('지정된 ZIP 파일이 존재하지 않습니다: '.$zipPath);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$zipPath = $resolvedZip;
|
||||
}
|
||||
|
||||
// ── 시스템 요구사항 검증 (--source / --local 모드에서는 스킵, --zip 은 필요) ──
|
||||
if (! $sourceDir && ! $this->option('local')) {
|
||||
$requirements = $service->checkSystemRequirements();
|
||||
if (! $requirements['valid']) {
|
||||
@@ -71,12 +116,16 @@ class CoreUpdateCommand extends Command
|
||||
$log("수동 업데이트 모드: 소스 디렉토리 = {$sourceDir}");
|
||||
}
|
||||
|
||||
if ($zipPath) {
|
||||
$log("수동 업데이트 모드: ZIP 파일 = {$zipPath}");
|
||||
}
|
||||
|
||||
// ── Step 1: 업데이트 확인 (프로그레스바 없이) ──
|
||||
$this->info(__('settings.core_update.step_check').'...');
|
||||
$log('업데이트 확인 시작');
|
||||
|
||||
if ($sourceDir || $this->option('local')) {
|
||||
// --source / --local 모드: GitHub 스킵, 소스의 버전 읽기 또는 시뮬레이션
|
||||
if ($sourceDir || $this->option('local') || $zipPath) {
|
||||
// --source / --local / --zip 모드: GitHub 스킵, 소스의 버전 읽기
|
||||
if ($sourceDir) {
|
||||
$sourceConfigPath = $sourceDir.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
|
||||
if (file_exists($sourceConfigPath)) {
|
||||
@@ -90,11 +139,18 @@ class CoreUpdateCommand extends Command
|
||||
}
|
||||
}
|
||||
$log("수동 업데이트 모드: {$fromVersion} → {$toVersion}");
|
||||
} elseif ($zipPath) {
|
||||
// --zip 모드: 버전은 추출 후에만 확인 가능. 일단 fromVersion 유지하고 Step 4 다운로드 후 재판별.
|
||||
$toVersion = $fromVersion;
|
||||
$log("ZIP 업데이트 모드: 버전은 추출 후 판별 ({$zipPath})");
|
||||
} else {
|
||||
$parts = explode('.', $fromVersion);
|
||||
$parts[count($parts) - 1] = (int) end($parts) + 1;
|
||||
$toVersion = implode('.', $parts);
|
||||
$log("로컬 모드: {$fromVersion} → {$toVersion} 시뮬레이션");
|
||||
// --local 모드: 현재 코드베이스의 config/app.php에서 버전을 직접 파싱
|
||||
$localConfigPath = base_path('config'.DIRECTORY_SEPARATOR.'app.php');
|
||||
$configContent = file_get_contents($localConfigPath);
|
||||
if (preg_match("/['\"]version['\"]\s*=>\s*env\s*\(\s*['\"]APP_VERSION['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", $configContent, $versionMatch)) {
|
||||
$toVersion = $versionMatch[1];
|
||||
}
|
||||
$log("로컬 모드: {$fromVersion} → {$toVersion}");
|
||||
}
|
||||
} else {
|
||||
$updateInfo = $service->checkForUpdates();
|
||||
@@ -116,7 +172,11 @@ class CoreUpdateCommand extends Command
|
||||
// 사용자 확인
|
||||
$this->newLine();
|
||||
$this->info("현재 버전: {$fromVersion}");
|
||||
$this->info("업데이트 버전: {$toVersion}");
|
||||
if ($zipPath) {
|
||||
$this->info('업데이트 버전: (ZIP 추출 후 판별)');
|
||||
} else {
|
||||
$this->info("업데이트 버전: {$toVersion}");
|
||||
}
|
||||
$this->newLine();
|
||||
|
||||
if (! $this->confirm('코어를 업데이트하시겠습니까?')) {
|
||||
@@ -168,6 +228,8 @@ class CoreUpdateCommand extends Command
|
||||
// ── Step 4: 다운로드 ──
|
||||
if ($sourceDir) {
|
||||
$bar->setMessage('소스 디렉토리 검증 중...');
|
||||
} elseif ($zipPath) {
|
||||
$bar->setMessage('ZIP 파일 추출 중...');
|
||||
} elseif ($this->option('local')) {
|
||||
$bar->setMessage('로컬 소스 복제 중...');
|
||||
} else {
|
||||
@@ -182,6 +244,20 @@ class CoreUpdateCommand extends Command
|
||||
// 원본 소스를 _pending으로 복제 (원본 보호)
|
||||
$pendingPath = $service->copySourceToPending($sourceDir, $onProgress);
|
||||
$log("소스 디렉토리를 _pending으로 복제 완료: {$pendingPath}");
|
||||
} elseif ($zipPath) {
|
||||
$log("ZIP 추출 시작: {$zipPath}");
|
||||
$pendingPath = $service->extractZipToPending($zipPath, $onProgress);
|
||||
$log("ZIP 추출 완료: {$pendingPath}");
|
||||
|
||||
// 추출된 소스의 config/app.php 에서 toVersion 갱신
|
||||
$zipConfigPath = $pendingPath.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
|
||||
if (file_exists($zipConfigPath)) {
|
||||
$zipConfigContent = file_get_contents($zipConfigPath);
|
||||
if (preg_match("/['\"]version['\"]\s*=>\s*env\s*\(\s*['\"]APP_VERSION['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", $zipConfigContent, $versionMatch)) {
|
||||
$toVersion = $versionMatch[1];
|
||||
$log("ZIP 소스 버전 확인: {$toVersion}");
|
||||
}
|
||||
}
|
||||
} elseif ($this->option('local')) {
|
||||
$log('로컬 소스 복제 시작');
|
||||
$pendingPath = $service->prepareLocalSource($onProgress);
|
||||
@@ -201,20 +277,39 @@ class CoreUpdateCommand extends Command
|
||||
$log("백업 생성 완료: {$backupPath}");
|
||||
}
|
||||
|
||||
// ── Step 6: _pending에서 Composer Install ──
|
||||
$composerSkipped = $service->isComposerUnchangedForCore($pendingPath);
|
||||
// 원본 소유권 스냅샷 — 이후 Step 11 에서 composer 등이 오염시킨 소유권을
|
||||
// 각 경로의 업데이트 전 원본으로 복원하기 위해 백업 직후 시점에 수집한다.
|
||||
$ownershipSnapshot = $service->snapshotOwnership();
|
||||
if (! empty($ownershipSnapshot)) {
|
||||
$log('원본 소유권 스냅샷 수집: '.implode(',', array_keys($ownershipSnapshot)));
|
||||
}
|
||||
|
||||
// ── Step 6: _pending에서 Vendor 설치 (composer 또는 bundled) ──
|
||||
$vendorMode = VendorMode::fromStringOrAuto((string) $this->option('vendor-mode'));
|
||||
$composerSkipped = $vendorMode !== VendorMode::Bundled
|
||||
&& $service->isComposerUnchangedForCore($pendingPath);
|
||||
|
||||
if ($composerSkipped) {
|
||||
$bar->setMessage('Composer 의존성 변경 없음 — 스킵');
|
||||
$bar->advance();
|
||||
$log('composer.json/lock 변경 없음, composer install 스킵');
|
||||
$log('composer.json/lock 변경 없음, vendor 재설치 스킵');
|
||||
$vendorResult = null;
|
||||
} else {
|
||||
$bar->setMessage(__('settings.core_update.step_composer'));
|
||||
$bar->advance();
|
||||
$log('_pending에서 composer install 시작');
|
||||
$log("_pending vendor 설치 시작 (mode: {$vendorMode->value})");
|
||||
|
||||
$service->runComposerInstallInPending($pendingPath, $onProgress);
|
||||
$log('_pending에서 composer install 완료');
|
||||
try {
|
||||
$vendorResult = $service->runVendorInstallInPending($pendingPath, $vendorMode, $onProgress);
|
||||
$log(sprintf(
|
||||
'_pending vendor 설치 완료 (strategy: %s, packages: %d)',
|
||||
$vendorResult->strategy,
|
||||
$vendorResult->packageCount,
|
||||
));
|
||||
} catch (VendorInstallException $e) {
|
||||
$this->error('Vendor 설치 실패: '.$e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Step 7: 파일 적용 ──
|
||||
@@ -235,6 +330,7 @@ class CoreUpdateCommand extends Command
|
||||
$bar->advance();
|
||||
$log('vendor 디렉토리 복사 시작');
|
||||
|
||||
// composer/bundled 모드 모두 _pending/vendor/ 가 구성되어 있으므로 공통 복사
|
||||
$service->copyVendorFromPending($pendingPath, $onProgress);
|
||||
$log('vendor 디렉토리 복사 완료');
|
||||
}
|
||||
@@ -242,26 +338,54 @@ class CoreUpdateCommand extends Command
|
||||
// ── Step 9: Migration + 역할/메뉴 동기화 ──
|
||||
$bar->setMessage(__('settings.core_update.step_migration'));
|
||||
$bar->advance();
|
||||
$log('마이그레이션, 역할/메뉴/메일템플릿 동기화 실행');
|
||||
$log('마이그레이션, 역할/메뉴 동기화 실행');
|
||||
|
||||
$service->runMigrations();
|
||||
$service->syncCoreRolesAndPermissions();
|
||||
$service->syncCoreMenus();
|
||||
$service->syncCoreMailTemplates();
|
||||
$log('마이그레이션, 역할/메뉴/메일템플릿 동기화 완료');
|
||||
$log('마이그레이션, 역할/메뉴 동기화 완료');
|
||||
|
||||
// ── Step 10: Upgrade Steps ──
|
||||
//
|
||||
// 경로 B (beta.3+): 별도 프로세스 spawn — 새 PHP 프로세스가 최신 클래스·config 를
|
||||
// 로드하므로 upgrade step 이 신규 Service/Model/Repository 등을 자유롭게 사용 가능.
|
||||
//
|
||||
// 경로 A (beta.1 → beta.2): beta.1 CoreUpdateCommand 가 in-process 로 실행되는
|
||||
// 상황에서는 본 재작성된 로직 자체가 활성화되지 않는다. 해당 경로의 후처리는
|
||||
// upgrade step 파일(Upgrade_7_0_0_beta_2) 내부 로컬 로직으로 수행된다.
|
||||
//
|
||||
// proc_open 미지원 / 실행 실패 시 in-process fallback 으로 안전하게 전환.
|
||||
$bar->setMessage(__('settings.core_update.step_upgrade'));
|
||||
$bar->advance();
|
||||
$log('업그레이드 스텝 실행');
|
||||
$log('업그레이드 스텝 별도 프로세스 실행 시도');
|
||||
|
||||
$service->runUpgradeSteps($fromVersion, $toVersion, function (string $version) use ($bar, $log) {
|
||||
$bar->setMessage(__('settings.core_update.step_upgrade')." ({$version})");
|
||||
$bar->display();
|
||||
$log("업그레이드 스텝 실행: {$version}");
|
||||
});
|
||||
// progress bar 라인과 spawn stdout / step 로그가 같은 줄에 섞이지 않도록
|
||||
// bar 를 잠시 지우고, 상세 로그를 별도 줄로 출력한 뒤 다시 표시한다.
|
||||
$bar->clear();
|
||||
$this->newLine();
|
||||
$this->info('── 업그레이드 스텝 실행 ──');
|
||||
|
||||
$spawned = $this->spawnUpgradeStepsProcess(
|
||||
$fromVersion,
|
||||
$toVersion,
|
||||
(bool) $this->option('force'),
|
||||
$log,
|
||||
);
|
||||
|
||||
if (! $spawned) {
|
||||
$log('별도 프로세스 실행 실패 — in-process fallback');
|
||||
$service->runUpgradeSteps($fromVersion, $toVersion, function (string $version) use ($log) {
|
||||
$this->line(" • upgrade step 실행: {$version}");
|
||||
$log("업그레이드 스텝 실행: {$version}");
|
||||
}, (bool) $this->option('force'));
|
||||
$service->reloadCoreConfigAndResync();
|
||||
$log('fallback 완료 (config 재로드 + 권한/메뉴 재동기화)');
|
||||
}
|
||||
$log('업그레이드 스텝 완료');
|
||||
|
||||
$this->newLine();
|
||||
$bar->display();
|
||||
|
||||
// ── Step 11: Cleanup ──
|
||||
$bar->setMessage(__('settings.core_update.step_cleanup'));
|
||||
$bar->advance();
|
||||
@@ -269,6 +393,11 @@ class CoreUpdateCommand extends Command
|
||||
$service->updateVersionInEnv($toVersion);
|
||||
$service->clearAllCaches();
|
||||
|
||||
// sudo 실행 시 composer 등 외부 프로세스가 root 로 생성한 파일의 소유권을
|
||||
// 백업 직후 수집한 원본 스냅샷 기준으로 복원 (각 경로 고유 소유자 유지)
|
||||
$service->restoreOwnership($ownershipSnapshot, $onProgress);
|
||||
$log('업데이트 경로 소유권 복원 완료');
|
||||
|
||||
$service->cleanupPending($pendingPath);
|
||||
|
||||
if ($backupPath) {
|
||||
@@ -290,10 +419,27 @@ class CoreUpdateCommand extends Command
|
||||
|
||||
$this->info("그누보드7 코어가 {$toVersion} 버전으로 업데이트되었습니다!");
|
||||
$this->newLine();
|
||||
$this->warn('_bundled 확장이 업데이트되었습니다. 활성 확장에 반영하려면 다음 커맨드를 실행하세요:');
|
||||
$this->line(' php artisan module:update <identifier> --force');
|
||||
$this->line(' php artisan plugin:update <identifier> --force');
|
||||
$this->line(' php artisan template:update <identifier> --force');
|
||||
|
||||
// _bundled 확장 일괄 업데이트 프롬프트 (번들에 신버전이 있을 때만 표시).
|
||||
//
|
||||
// 주의: Step 11 restoreOwnership 이후에 실행되므로, 프롬프트 내 실제
|
||||
// 업데이트 실행 시 composer / updateComposerAutoload 등으로 생성되는
|
||||
// bootstrap/cache/autoload-extensions.php, {modules|plugins|templates}/{id}/vendor,
|
||||
// storage/app/* 등이 sudo 컨텍스트에서 root 로 오염될 수 있다.
|
||||
// 실제 업데이트가 수행된 경우 restoreOwnership 을 한 번 더 호출해 재복원한다.
|
||||
$promptResult = $this->runBundledExtensionUpdatePrompt(
|
||||
app(ModuleManager::class),
|
||||
app(PluginManager::class),
|
||||
app(TemplateManager::class),
|
||||
(bool) $this->option('force'),
|
||||
);
|
||||
|
||||
if (($promptResult['success'] ?? 0) > 0) {
|
||||
$this->newLine();
|
||||
$this->info('일괄 업데이트로 생성된 파일의 소유권을 복원하는 중...');
|
||||
$service->restoreOwnership($ownershipSnapshot, $onProgress);
|
||||
$log('일괄 확장 업데이트 후 소유권 재복원 완료');
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
|
||||
@@ -381,6 +527,107 @@ class CoreUpdateCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 업그레이드 스텝을 별도 PHP 프로세스에서 실행합니다 (경로 B).
|
||||
*
|
||||
* proc_open 으로 `core:execute-upgrade-steps` 커맨드를 spawn 하여 새 PHP 프로세스가
|
||||
* 최신 파일 기준으로 모든 클래스·config 를 로드하게 한다. 이로써 upgrade step 이
|
||||
* 신규 Service/Repository/Controller 등을 자유롭게 참조할 수 있다.
|
||||
*
|
||||
* stdout 을 실시간으로 상위 콘솔에 전달하여 진행 상황을 보여주고, exit code === 0
|
||||
* 일 때만 성공으로 판정한다. proc_open 미지원 환경·커맨드 미존재·비정상 종료는
|
||||
* false 반환하여 호출자가 in-process fallback 으로 전환할 수 있게 한다.
|
||||
*
|
||||
* @param string $fromVersion 시작 버전
|
||||
* @param string $toVersion 대상 버전
|
||||
* @param bool $force 동일 버전 강제 실행 여부
|
||||
* @param \Closure $log 로그 엔트리 수집 콜백
|
||||
* @return bool spawn 성공 여부 (false 면 fallback 실행 필요)
|
||||
*/
|
||||
private function spawnUpgradeStepsProcess(string $fromVersion, string $toVersion, bool $force, \Closure $log): bool
|
||||
{
|
||||
if (! function_exists('proc_open')) {
|
||||
$log('proc_open 비활성 — spawn 스킵, in-process fallback 진행');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$phpBinary = config('process.php_binary', PHP_BINARY);
|
||||
$artisan = base_path('artisan');
|
||||
|
||||
$command = [
|
||||
$phpBinary,
|
||||
$artisan,
|
||||
'core:execute-upgrade-steps',
|
||||
'--from='.$fromVersion,
|
||||
'--to='.$toVersion,
|
||||
];
|
||||
if ($force) {
|
||||
$command[] = '--force';
|
||||
}
|
||||
|
||||
$commandLine = implode(' ', array_map('escapeshellarg', $command)).' 2>&1';
|
||||
|
||||
$descriptors = [
|
||||
0 => ['pipe', 'r'],
|
||||
1 => ['pipe', 'w'],
|
||||
2 => ['pipe', 'w'],
|
||||
];
|
||||
|
||||
// spawn 자식에 전달할 env 구성.
|
||||
//
|
||||
// 주의: `$_ENV` 는 `variables_order` php.ini 설정(기본 CLI 가 "EGPCS" 지만 호스팅에 따라
|
||||
// "GPCS" 만 포함해 E 없을 수 있음) 에 따라 비어있을 수 있다. 이 경우 `$_ENV` 에 값을
|
||||
// 할당해도 실제 프로세스 환경변수 테이블에는 반영 안 되며, `array_merge($_ENV, ...)` 결과도
|
||||
// 불완전해져 spawn 자식이 G7_UPDATE_IN_PROGRESS 등 핵심 플래그를 받지 못한다.
|
||||
//
|
||||
// getenv() (인자 없이 호출, PHP 7.1+) 은 프로세스 환경변수 테이블을 직접 반환해
|
||||
// putenv 로 설정한 값까지 확실히 포함한다. getenv() 를 기반으로 삼고 $_ENV 로 보완하여
|
||||
// 양쪽 채널의 합집합을 자식에 전달한다.
|
||||
//
|
||||
// APP_VERSION: Step 11 updateVersionInEnv 는 아직 실행 전이라 .env 는 fromVersion.
|
||||
// G7_UPDATE_IN_PROGRESS: CoreServiceProvider::validateAndDeactivate 가드가 참조.
|
||||
$env = array_merge(getenv(), $_ENV, [
|
||||
'APP_VERSION' => $toVersion,
|
||||
'G7_UPDATE_IN_PROGRESS' => '1',
|
||||
]);
|
||||
|
||||
$process = proc_open($commandLine, $descriptors, $pipes, base_path(), $env);
|
||||
if (! is_resource($process)) {
|
||||
$log('spawn 실패 — proc_open 자원 생성 실패');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
fclose($pipes[0]);
|
||||
|
||||
// stdout 실시간 전달 — 상위 콘솔에서 진행 상황 확인 가능
|
||||
while (! feof($pipes[1])) {
|
||||
$line = fgets($pipes[1]);
|
||||
if ($line !== false) {
|
||||
$trimmed = rtrim($line);
|
||||
if ($trimmed !== '') {
|
||||
$this->line($trimmed);
|
||||
$log('[spawn] '.$trimmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
$exitCode = proc_close($process);
|
||||
|
||||
if ($exitCode === 0) {
|
||||
$log('spawn 완료 (exit=0)');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$log("spawn 비정상 종료 (exit={$exitCode}) — fallback 진행");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 업데이트 로그를 파일로 저장합니다.
|
||||
*
|
||||
@@ -411,4 +658,51 @@ class CoreUpdateCommand extends Command
|
||||
|
||||
Log::info("코어 업데이트 로그 저장: {$logPath}");
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 실행 사용자와 코어 파일 소유자가 다른 경우 경고를 표시합니다.
|
||||
*
|
||||
* 공유 호스팅에서 FTP 사용자(파일 소유자)와 SSH 사용자, 또는 SSH 사용자와
|
||||
* www-data 가 다른 경우 권한 거부가 발생할 수 있습니다. 차단하지는 않고
|
||||
* 사용자가 직접 판단하도록 경고만 출력합니다.
|
||||
*/
|
||||
private function warnIfFileOwnerMismatch(\Closure $log): void
|
||||
{
|
||||
if (! function_exists('posix_geteuid') || ! function_exists('posix_getpwuid')) {
|
||||
return; // Windows 또는 posix 확장 미설치
|
||||
}
|
||||
|
||||
$coreFile = base_path('composer.json');
|
||||
if (! file_exists($coreFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$currentUid = posix_geteuid();
|
||||
$ownerUid = fileowner($coreFile);
|
||||
|
||||
if ($currentUid === $ownerUid) {
|
||||
return;
|
||||
}
|
||||
|
||||
$currentUser = posix_getpwuid($currentUid)['name'] ?? (string) $currentUid;
|
||||
$ownerUser = posix_getpwuid($ownerUid)['name'] ?? (string) $ownerUid;
|
||||
|
||||
$this->newLine();
|
||||
$this->warn('⚠ 실행 사용자와 코어 파일 소유자가 다릅니다.');
|
||||
$this->warn(" 실행 사용자: {$currentUser} (uid={$currentUid})");
|
||||
$this->warn(" 코어 소유자: {$ownerUser} (uid={$ownerUid})");
|
||||
$this->warn(' → 권한 거부가 발생할 수 있습니다. 일반적으로 코어 파일 소유자로');
|
||||
$this->warn(' SSH 로그인 후 실행해야 합니다. vendor/ 가 다른 사용자 소유인 경우');
|
||||
$this->warn(" 'chown -R \$(whoami) vendor/' 후 재시도하세요.");
|
||||
$this->newLine();
|
||||
|
||||
$log("권한 경고: 실행자={$currentUser}({$currentUid}) vs 소유자={$ownerUser}({$ownerUid})");
|
||||
|
||||
Log::warning('core:update 실행 사용자가 코어 파일 소유자와 다름', [
|
||||
'current_uid' => $currentUid,
|
||||
'current_user' => $currentUser,
|
||||
'owner_uid' => $ownerUid,
|
||||
'owner_user' => $ownerUser,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user