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,7 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Events\Dashboard\DashboardUpdated;
|
||||
use App\Extension\HookManager;
|
||||
use App\Services\DashboardService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@@ -31,11 +31,13 @@ class BroadcastDashboardResources extends Command
|
||||
* 커맨드를 실행합니다.
|
||||
*
|
||||
* @param DashboardService $dashboardService 대시보드 서비스
|
||||
* @return int
|
||||
*/
|
||||
public function handle(DashboardService $dashboardService): int
|
||||
{
|
||||
broadcast(new DashboardUpdated('resources', $dashboardService->getSystemResources()));
|
||||
HookManager::broadcast('core.admin.dashboard', 'dashboard.resources.updated', [
|
||||
'type' => 'resources',
|
||||
'data' => $dashboardService->getSystemResources(),
|
||||
]);
|
||||
|
||||
$this->info('시스템 리소스 정보가 브로드캐스트되었습니다.');
|
||||
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Core\Concerns;
|
||||
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Extension\TemplateManager;
|
||||
use App\Extension\Vendor\VendorMode;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* 코어 업데이트 완료 후 _bundled 번들에 신버전이 포함된
|
||||
* 모듈/플러그인/템플릿을 일괄 업데이트하는 대화형 프롬프트.
|
||||
*
|
||||
* CoreUpdateCommand 에서 사용되며, 다음 단계로 동작한다.
|
||||
* 1) 각 확장 매니저의 checkAllXxxForUpdates() 로 번들 업데이트 감지
|
||||
* 2) 감지 목록 표시 + 일괄 업데이트 진행 여부 확인
|
||||
* 3) 동의 시 전역 레이아웃 전략(overwrite|keep) 1회 질의
|
||||
* 4) 확장별 예외 변경 질의 (choice 로 다중 선택)
|
||||
* 5) 각 확장 매니저의 updateXxx() 호출
|
||||
* 6) 결과 요약 출력
|
||||
*
|
||||
* --force 옵션이 지정된 경우: 프롬프트 스킵 + 전역 전략 'overwrite' 로 즉시 실행.
|
||||
*/
|
||||
trait BundledExtensionUpdatePrompt
|
||||
{
|
||||
/**
|
||||
* 번들 업데이트 목록 수집.
|
||||
*
|
||||
* @return array{modules: array, plugins: array, templates: array}
|
||||
*/
|
||||
protected function collectBundledUpdates(
|
||||
ModuleManager $moduleManager,
|
||||
PluginManager $pluginManager,
|
||||
TemplateManager $templateManager,
|
||||
): array {
|
||||
// CoreUpdateService::collectBundledExtensionUpdates() 를 통해 _bundled manifest 버전을
|
||||
// DB 현재 버전과 직접 비교한다. Manager::checkXxxUpdate() 의 "GitHub 엄격 우선" 정책을
|
||||
// 우회하여 GitHub 미릴리스 상태에서도 _bundled 신버전을 정확히 감지.
|
||||
return app(\App\Services\CoreUpdateService::class)->collectBundledExtensionUpdates();
|
||||
}
|
||||
|
||||
/**
|
||||
* 일괄 업데이트 UX 를 실행하고 결과를 반환한다.
|
||||
*
|
||||
* @return array{success: int, failed: int, skipped: int, has_updates: bool}
|
||||
*/
|
||||
protected function runBundledExtensionUpdatePrompt(
|
||||
ModuleManager $moduleManager,
|
||||
PluginManager $pluginManager,
|
||||
TemplateManager $templateManager,
|
||||
bool $force,
|
||||
): array {
|
||||
$updates = $this->collectBundledUpdates($moduleManager, $pluginManager, $templateManager);
|
||||
$total = count($updates['modules']) + count($updates['plugins']) + count($updates['templates']);
|
||||
|
||||
if ($total === 0) {
|
||||
$this->info('활성 확장이 최신 번들과 일치합니다.');
|
||||
|
||||
return ['success' => 0, 'failed' => 0, 'skipped' => 0, 'has_updates' => false];
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
$this->info('번들에 새 버전이 포함된 확장이 감지되었습니다:');
|
||||
foreach ($updates['modules'] as $m) {
|
||||
$this->line(" [모듈] {$m['identifier']} {$m['current_version']} → {$m['latest_version']}");
|
||||
}
|
||||
foreach ($updates['plugins'] as $p) {
|
||||
$this->line(" [플러그인] {$p['identifier']} {$p['current_version']} → {$p['latest_version']}");
|
||||
}
|
||||
foreach ($updates['templates'] as $t) {
|
||||
$this->line(" [템플릿] {$t['identifier']} {$t['current_version']} → {$t['latest_version']}");
|
||||
}
|
||||
$this->newLine();
|
||||
|
||||
if (! $force && ! $this->confirm('일괄 업데이트를 진행하시겠습니까?', true)) {
|
||||
$this->info('일괄 업데이트를 건너뜁니다.');
|
||||
|
||||
return ['success' => 0, 'failed' => 0, 'skipped' => $total, 'has_updates' => true];
|
||||
}
|
||||
|
||||
// 전역 레이아웃 전략
|
||||
$globalStrategy = 'overwrite';
|
||||
if (! $force) {
|
||||
$answer = $this->choice(
|
||||
'전역 레이아웃 전략을 선택하세요',
|
||||
['overwrite' => '모든 레이아웃을 번들로 덮어쓰기', 'keep' => '사용자가 수정한 레이아웃은 보존'],
|
||||
'overwrite',
|
||||
);
|
||||
$globalStrategy = $answer;
|
||||
}
|
||||
|
||||
// 확장별 전략 오버라이드
|
||||
$strategies = $this->collectPerExtensionStrategies($updates, $globalStrategy, $force);
|
||||
|
||||
// 일괄 실행
|
||||
return $this->executeBulkUpdate(
|
||||
$moduleManager,
|
||||
$pluginManager,
|
||||
$templateManager,
|
||||
$updates,
|
||||
$strategies,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 확장별 전략 오버라이드 수집.
|
||||
*
|
||||
* @param array $updates collectBundledUpdates() 반환값
|
||||
* @return array<string, string> key: "{type}:{identifier}", value: strategy
|
||||
*/
|
||||
private function collectPerExtensionStrategies(array $updates, string $globalStrategy, bool $force): array
|
||||
{
|
||||
$strategies = [];
|
||||
foreach (['modules', 'plugins', 'templates'] as $type) {
|
||||
foreach ($updates[$type] as $ext) {
|
||||
$strategies["{$type}:{$ext['identifier']}"] = $globalStrategy;
|
||||
}
|
||||
}
|
||||
|
||||
if ($force) {
|
||||
return $strategies;
|
||||
}
|
||||
|
||||
if (! $this->confirm('전역 전략과 다르게 적용할 확장이 있습니까?', false)) {
|
||||
return $strategies;
|
||||
}
|
||||
|
||||
$choices = [];
|
||||
foreach ($updates['modules'] as $m) {
|
||||
$choices[] = "[모듈] {$m['identifier']}";
|
||||
}
|
||||
foreach ($updates['plugins'] as $p) {
|
||||
$choices[] = "[플러그인] {$p['identifier']}";
|
||||
}
|
||||
foreach ($updates['templates'] as $t) {
|
||||
$choices[] = "[템플릿] {$t['identifier']}";
|
||||
}
|
||||
|
||||
$overrideStrategy = $globalStrategy === 'overwrite' ? 'keep' : 'overwrite';
|
||||
|
||||
$this->info("예외 확장은 '{$overrideStrategy}' 전략이 적용됩니다.");
|
||||
$selected = $this->ask('예외 확장 선택 (쉼표로 구분, 빈 값이면 건너뛰기)', '');
|
||||
|
||||
if (trim((string) $selected) === '') {
|
||||
return $strategies;
|
||||
}
|
||||
|
||||
$lookup = [];
|
||||
$idx = 0;
|
||||
foreach (['modules', 'plugins', 'templates'] as $type) {
|
||||
foreach ($updates[$type] as $ext) {
|
||||
$lookup[$choices[$idx]] = "{$type}:{$ext['identifier']}";
|
||||
$idx++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array_map('trim', explode(',', (string) $selected)) as $choice) {
|
||||
if (isset($lookup[$choice])) {
|
||||
$strategies[$lookup[$choice]] = $overrideStrategy;
|
||||
}
|
||||
}
|
||||
|
||||
return $strategies;
|
||||
}
|
||||
|
||||
/**
|
||||
* 실제 일괄 업데이트 실행.
|
||||
*
|
||||
* @return array{success: int, failed: int, skipped: int, has_updates: bool}
|
||||
*/
|
||||
private function executeBulkUpdate(
|
||||
ModuleManager $moduleManager,
|
||||
PluginManager $pluginManager,
|
||||
TemplateManager $templateManager,
|
||||
array $updates,
|
||||
array $strategies,
|
||||
): array {
|
||||
$success = 0;
|
||||
$failed = 0;
|
||||
|
||||
$this->newLine();
|
||||
$this->info('── 일괄 업데이트 실행 ──');
|
||||
|
||||
foreach ($updates['modules'] as $m) {
|
||||
$id = $m['identifier'];
|
||||
$strategy = $strategies["modules:{$id}"] ?? 'overwrite';
|
||||
$this->line("→ [모듈] {$id} ({$strategy})");
|
||||
try {
|
||||
$moduleManager->updateModule($id, true, null, VendorMode::Auto, $strategy, null, 'bundled');
|
||||
$success++;
|
||||
} catch (\Throwable $e) {
|
||||
$failed++;
|
||||
$this->warn(" 실패: {$e->getMessage()}");
|
||||
Log::error('번들 일괄 업데이트 실패', ['type' => 'module', 'id' => $id, 'error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($updates['plugins'] as $p) {
|
||||
$id = $p['identifier'];
|
||||
$strategy = $strategies["plugins:{$id}"] ?? 'overwrite';
|
||||
$this->line("→ [플러그인] {$id} ({$strategy})");
|
||||
try {
|
||||
$pluginManager->updatePlugin($id, true, null, VendorMode::Auto, $strategy, null, 'bundled');
|
||||
$success++;
|
||||
} catch (\Throwable $e) {
|
||||
$failed++;
|
||||
$this->warn(" 실패: {$e->getMessage()}");
|
||||
Log::error('번들 일괄 업데이트 실패', ['type' => 'plugin', 'id' => $id, 'error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($updates['templates'] as $t) {
|
||||
$id = $t['identifier'];
|
||||
$strategy = $strategies["templates:{$id}"] ?? 'overwrite';
|
||||
$this->line("→ [템플릿] {$id} ({$strategy})");
|
||||
try {
|
||||
$templateManager->updateTemplate($id, true, null, $strategy, 'bundled');
|
||||
$success++;
|
||||
} catch (\Throwable $e) {
|
||||
$failed++;
|
||||
$this->warn(" 실패: {$e->getMessage()}");
|
||||
Log::error('번들 일괄 업데이트 실패', ['type' => 'template', 'id' => $id, 'error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
$this->info("업데이트 완료: 성공 {$success}, 실패 {$failed}");
|
||||
|
||||
return [
|
||||
'success' => $success,
|
||||
'failed' => $failed,
|
||||
'skipped' => 0,
|
||||
'has_updates' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Core;
|
||||
|
||||
use App\Console\Commands\Vendor\Concerns\RunsVendorBundleAction;
|
||||
use App\Extension\Vendor\VendorBundler;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 코어 vendor/ 디렉토리를 vendor-bundle.zip 으로 빌드합니다.
|
||||
*
|
||||
* 기존 *:build 패턴과 일관된 코어 단독 vendor 번들 빌드 명령어.
|
||||
*/
|
||||
class CoreVendorBundleCommand extends Command
|
||||
{
|
||||
use RunsVendorBundleAction;
|
||||
|
||||
protected $signature = 'core:vendor-bundle
|
||||
{--force : 해시 체크 무시, 강제 재빌드}
|
||||
{--check : 실제 빌드 없이 stale 여부만 확인}';
|
||||
|
||||
protected $description = '코어 vendor/ 디렉토리를 vendor-bundle.zip 으로 빌드합니다 (공유 호스팅용)';
|
||||
|
||||
public function handle(VendorBundler $bundler): int
|
||||
{
|
||||
$targets = [['type' => 'core', 'identifier' => null]];
|
||||
|
||||
return $this->runBuildAction(
|
||||
$bundler,
|
||||
$targets,
|
||||
(bool) $this->option('force'),
|
||||
(bool) $this->option('check'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Core;
|
||||
|
||||
use App\Console\Commands\Vendor\Concerns\RunsVendorBundleAction;
|
||||
use App\Extension\Vendor\VendorIntegrityChecker;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 코어 vendor-bundle.zip 무결성을 검증합니다.
|
||||
*/
|
||||
class CoreVendorVerifyCommand extends Command
|
||||
{
|
||||
use RunsVendorBundleAction;
|
||||
|
||||
protected $signature = 'core:vendor-verify';
|
||||
|
||||
protected $description = '코어 vendor-bundle.zip 의 SHA256 무결성을 검증합니다';
|
||||
|
||||
public function handle(VendorIntegrityChecker $checker): int
|
||||
{
|
||||
$targets = [['type' => 'core', 'identifier' => null]];
|
||||
|
||||
return $this->runVerifyAction($checker, $targets);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Core;
|
||||
|
||||
use App\Services\CoreUpdateService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* 코어 업그레이드 스텝을 별도 프로세스에서 실행합니다.
|
||||
*
|
||||
* CoreUpdateCommand 의 Step 10 에서 proc_open 으로 호출하여 최신 버전 클래스·
|
||||
* config 를 새 PHP 프로세스에서 로드하게 하는 진입점. 새 프로세스에서 실행되므로
|
||||
* upgrade step 이 신규 Service/Repository/Controller 등을 자유롭게 호출할 수 있다.
|
||||
*
|
||||
* 단, 이는 beta.3 이후 업그레이드 경로(경로 B)에만 적용된다. beta.1 → beta.2
|
||||
* 업그레이드는 beta.1 의 CoreUpdateCommand 가 본 커맨드를 알지 못하므로 spawn
|
||||
* 효과를 받지 못한다(경로 A) — 이 경우 upgrade step 파일 내부 로컬 로직으로
|
||||
* 후처리를 수행해야 한다. 상세는 docs/extension/upgrade-step-guide.md 참조.
|
||||
*/
|
||||
class ExecuteUpgradeStepsCommand extends Command
|
||||
{
|
||||
protected $signature = 'core:execute-upgrade-steps
|
||||
{--from= : 시작 버전}
|
||||
{--to= : 대상 버전}
|
||||
{--force : 동일 버전 강제 실행}';
|
||||
|
||||
protected $description = '코어 업그레이드 스텝을 별도 프로세스에서 실행합니다 (CoreUpdateCommand 내부용)';
|
||||
|
||||
/**
|
||||
* 커맨드를 실행합니다.
|
||||
*
|
||||
* @param CoreUpdateService $service 코어 업데이트 서비스
|
||||
* @return int 종료 코드
|
||||
*/
|
||||
public function handle(CoreUpdateService $service): int
|
||||
{
|
||||
$from = (string) $this->option('from');
|
||||
$to = (string) $this->option('to');
|
||||
$force = (bool) $this->option('force');
|
||||
|
||||
if ($from === '' || $to === '') {
|
||||
$this->error('--from 과 --to 는 필수 옵션입니다.');
|
||||
|
||||
return self::INVALID;
|
||||
}
|
||||
|
||||
try {
|
||||
$service->runUpgradeSteps(
|
||||
$from,
|
||||
$to,
|
||||
fn (string $version) => $this->info("upgrade step 실행: {$version}"),
|
||||
$force,
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('core:execute-upgrade-steps 실패', [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
$this->error($e->getMessage());
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\GeoIp;
|
||||
|
||||
use App\Services\GeoIpDatabaseService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* MaxMind GeoLite2 DB 다운로드/갱신 커맨드.
|
||||
*
|
||||
* 모든 비즈니스 로직은 GeoIpDatabaseService에 위임합니다.
|
||||
* 이 커맨드는 CLI 인터페이스(옵션 파싱 + 결과 출력)만 담당합니다.
|
||||
*/
|
||||
class UpdateGeoLiteDatabaseCommand extends Command
|
||||
{
|
||||
protected $signature = 'geoip:update
|
||||
{--force : 파일이 이미 존재해도 재다운로드}
|
||||
{--dry-run : 실제 다운로드 없이 키/URL만 검증}';
|
||||
|
||||
protected $description = 'MaxMind GeoLite2-City DB를 다운로드하여 storage/app/geoip/에 배치합니다.';
|
||||
|
||||
/**
|
||||
* 커맨드를 실행합니다.
|
||||
*
|
||||
* @param GeoIpDatabaseService $service GeoIP DB 관리 서비스
|
||||
* @return int 종료 코드
|
||||
*/
|
||||
public function handle(GeoIpDatabaseService $service): int
|
||||
{
|
||||
if ($this->option('dry-run')) {
|
||||
return $this->handleDryRun($service);
|
||||
}
|
||||
|
||||
$result = $service->updateDatabase((bool) $this->option('force'));
|
||||
|
||||
return $this->reportResult($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* dry-run 모드: 라이선스 키 마스킹 후 URL만 출력합니다.
|
||||
*
|
||||
* @param GeoIpDatabaseService $service GeoIP DB 관리 서비스
|
||||
* @return int 종료 코드
|
||||
*/
|
||||
private function handleDryRun(GeoIpDatabaseService $service): int
|
||||
{
|
||||
if (! $service->isLicenseKeyConfigured()) {
|
||||
$this->error('MaxMind 라이선스 키가 설정되지 않았습니다.');
|
||||
$this->line('관리자 > 환경설정 > 고급 탭에서 라이선스 키를 입력하세요.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$maskedUrl = $service->buildDownloadUrlForDisplay(true);
|
||||
$this->info('[dry-run] 다운로드 URL 검증 완료');
|
||||
$this->line(" URL: {$maskedUrl}");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service 결과를 CLI 출력으로 변환하고 exit code를 반환합니다.
|
||||
*
|
||||
* @param array<string, mixed> $result Service::updateDatabase() 반환값
|
||||
* @return int 종료 코드
|
||||
*/
|
||||
private function reportResult(array $result): int
|
||||
{
|
||||
$status = (string) ($result['status'] ?? '');
|
||||
$message = (string) ($result['message'] ?? '');
|
||||
|
||||
if ($status === 'missing_license_key') {
|
||||
$this->error($message);
|
||||
$this->line('관리자 > 환경설정 > 고급 탭에서 라이선스 키를 입력하세요.');
|
||||
$this->line('무료 발급: https://www.maxmind.com/en/geolite2/signup');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($status === 'skipped') {
|
||||
$this->info($message);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
if ($status === 'updated') {
|
||||
$data = $result['data'] ?? [];
|
||||
$this->newLine();
|
||||
$this->info('✅ '.$message);
|
||||
$this->line(sprintf(' 파일: %s', $data['database_path'] ?? '-'));
|
||||
$this->line(sprintf(' 크기: %.2f MB', (int) ($data['file_size_bytes'] ?? 0) / 1048576));
|
||||
$this->line(sprintf(' 소요 시간: %s초', $data['elapsed_seconds'] ?? '-'));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 그 외 모든 실패 상태
|
||||
$this->error($message !== '' ? $message : 'GeoIP DB 업데이트에 실패했습니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Extension\ModuleManager;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ClearModuleCacheCommand extends Command
|
||||
@@ -26,7 +26,8 @@ class ClearModuleCacheCommand extends Command
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
private ModuleRepositoryInterface $moduleRepository,
|
||||
private CacheInterface $cache
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -74,7 +75,7 @@ class ClearModuleCacheCommand extends Command
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if (Cache::forget($key)) {
|
||||
if ($this->cache->forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
@@ -122,7 +123,7 @@ class ClearModuleCacheCommand extends Command
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if (Cache::forget($key)) {
|
||||
if ($this->cache->forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Console\Commands\Traits\HasProgressBar;
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Enums\ExtensionOwnerType;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\Vendor\VendorMode;
|
||||
use App\Models\Menu;
|
||||
use App\Models\Permission;
|
||||
use App\Rules\ValidExtensionIdentifier;
|
||||
@@ -20,7 +21,10 @@ class InstallModuleCommand extends Command
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:install {identifier : 설치할 모듈 식별자}';
|
||||
protected $signature = 'module:install
|
||||
{identifier : 설치할 모듈 식별자}
|
||||
{--vendor-mode=auto : Vendor 설치 모드 (auto|composer|bundled)}
|
||||
{--force : 이미 설치된 경우에도 _bundled/_pending 원본으로 활성 디렉토리를 덮어쓰고 재설치 (불완전 설치 복구)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -56,22 +60,29 @@ class InstallModuleCommand extends Command
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$force = (bool) $this->option('force');
|
||||
|
||||
try {
|
||||
// 모듈 디렉토리 스캔 및 로드
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
// 이미 설치된 모듈인지 확인
|
||||
// 이미 설치된 모듈인지 확인 (force 시 스킵하여 재설치/복구 허용)
|
||||
$existingModule = $this->moduleRepository->findByIdentifier($identifier);
|
||||
if ($existingModule) {
|
||||
if ($existingModule && ! $force) {
|
||||
$this->warn('⚠️ '.__('modules.commands.install.already_installed', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($existingModule && $force) {
|
||||
$this->warn('⚠️ '.__('modules.commands.install.force_reinstall', ['module' => $identifier]));
|
||||
}
|
||||
|
||||
// 모듈 설치
|
||||
$vendorMode = VendorMode::fromStringOrAuto((string) $this->option('vendor-mode'));
|
||||
$onProgress = $this->createProgressCallback(ModuleManager::INSTALL_STEPS);
|
||||
try {
|
||||
$result = $this->moduleManager->installModule($identifier, $onProgress);
|
||||
$result = $this->moduleManager->installModule($identifier, $onProgress, $vendorMode, $force);
|
||||
$this->finishProgress();
|
||||
} catch (\Exception $e) {
|
||||
$this->finishProgress();
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Console\Commands\Vendor\Concerns\RunsVendorBundleAction;
|
||||
use App\Extension\Vendor\VendorBundler;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 모듈 vendor/ 디렉토리를 vendor-bundle.zip 으로 빌드합니다.
|
||||
*
|
||||
* 기존 module:build 패턴과 동일하게 positional identifier + --all 옵션 지원.
|
||||
*/
|
||||
class ModuleVendorBundleCommand extends Command
|
||||
{
|
||||
use RunsVendorBundleAction;
|
||||
|
||||
protected $signature = 'module:vendor-bundle
|
||||
{identifier? : 빌드할 모듈 식별자 (생략 시 --all 필요)}
|
||||
{--all : 모든 _bundled 모듈 빌드}
|
||||
{--force : 해시 체크 무시, 강제 재빌드}
|
||||
{--check : 실제 빌드 없이 stale 여부만 확인}';
|
||||
|
||||
protected $description = '모듈 vendor/ 디렉토리를 vendor-bundle.zip 으로 빌드합니다 (공유 호스팅용)';
|
||||
|
||||
public function handle(VendorBundler $bundler): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$all = (bool) $this->option('all');
|
||||
|
||||
if (! $identifier && ! $all) {
|
||||
$this->error('식별자 또는 --all 옵션을 지정해야 합니다.');
|
||||
$this->line('사용법:');
|
||||
$this->line(' php artisan module:vendor-bundle sirsoft-ecommerce');
|
||||
$this->line(' php artisan module:vendor-bundle --all');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$targets = [];
|
||||
if ($all) {
|
||||
foreach ($this->discoverBundledIdentifiers('module') as $id) {
|
||||
$targets[] = ['type' => 'module', 'identifier' => $id];
|
||||
}
|
||||
} else {
|
||||
$targets[] = ['type' => 'module', 'identifier' => $identifier];
|
||||
}
|
||||
|
||||
return $this->runBuildAction(
|
||||
$bundler,
|
||||
$targets,
|
||||
(bool) $this->option('force'),
|
||||
(bool) $this->option('check'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Console\Commands\Vendor\Concerns\RunsVendorBundleAction;
|
||||
use App\Extension\Vendor\VendorIntegrityChecker;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 모듈 vendor-bundle.zip 무결성을 검증합니다.
|
||||
*/
|
||||
class ModuleVendorVerifyCommand extends Command
|
||||
{
|
||||
use RunsVendorBundleAction;
|
||||
|
||||
protected $signature = 'module:vendor-verify
|
||||
{identifier? : 검증할 모듈 식별자 (생략 시 --all 필요)}
|
||||
{--all : 모든 _bundled 모듈 검증}';
|
||||
|
||||
protected $description = '모듈 vendor-bundle.zip 의 SHA256 무결성을 검증합니다';
|
||||
|
||||
public function handle(VendorIntegrityChecker $checker): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$all = (bool) $this->option('all');
|
||||
|
||||
if (! $identifier && ! $all) {
|
||||
$this->error('식별자 또는 --all 옵션을 지정해야 합니다.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$targets = [];
|
||||
if ($all) {
|
||||
foreach ($this->discoverBundledIdentifiers('module') as $id) {
|
||||
$targets[] = ['type' => 'module', 'identifier' => $id];
|
||||
}
|
||||
} else {
|
||||
$targets[] = ['type' => 'module', 'identifier' => $identifier];
|
||||
}
|
||||
|
||||
return $this->runVerifyAction($checker, $targets);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Console\Commands\Module;
|
||||
use App\Console\Commands\Traits\HasProgressBar;
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\Vendor\VendorMode;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -17,7 +18,11 @@ class UpdateModuleCommand extends Command
|
||||
*/
|
||||
protected $signature = 'module:update
|
||||
{identifier : 업데이트할 모듈 식별자}
|
||||
{--force : 버전 비교 없이 강제 업데이트}';
|
||||
{--force : 버전 비교 없이 강제 업데이트}
|
||||
{--vendor-mode=auto : Vendor 설치 모드 (auto|composer|bundled)}
|
||||
{--layout-strategy=overwrite : 레이아웃 전략 (overwrite|keep)}
|
||||
{--source=auto : 업데이트 소스 (auto|bundled|github) — bundled 는 _bundled 만 사용(GitHub 우회)}
|
||||
{--zip= : 외부 ZIP 파일 경로 (지정 시 GitHub/번들 우회 + 버전은 module.json 기준)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -41,6 +46,40 @@ class UpdateModuleCommand extends Command
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$force = $this->option('force');
|
||||
$layoutStrategy = (string) $this->option('layout-strategy');
|
||||
$sourceOption = (string) $this->option('source');
|
||||
$zipPath = $this->option('zip');
|
||||
|
||||
if (! in_array($layoutStrategy, ['overwrite', 'keep'], true)) {
|
||||
$this->error('❌ --layout-strategy 는 overwrite 또는 keep 이어야 합니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (! in_array($sourceOption, ['auto', 'bundled', 'github'], true)) {
|
||||
$this->error('❌ --source 는 auto, bundled, github 중 하나여야 합니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// --zip 과 --source 동시 지정 금지 (zip 이 우선 대상이므로)
|
||||
if ($zipPath !== null && $sourceOption !== 'auto') {
|
||||
$this->error('❌ --zip 은 --source 와 동시에 지정할 수 없습니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($zipPath !== null) {
|
||||
$resolvedZip = realpath($zipPath);
|
||||
if (! $resolvedZip || ! is_file($resolvedZip)) {
|
||||
$this->error('❌ 지정된 ZIP 파일이 존재하지 않습니다: '.$zipPath);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$zipPath = $resolvedZip;
|
||||
}
|
||||
|
||||
$sourceOverride = $sourceOption === 'auto' ? null : $sourceOption;
|
||||
|
||||
try {
|
||||
$this->moduleManager->loadModules();
|
||||
@@ -54,23 +93,29 @@ class UpdateModuleCommand extends Command
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 업데이트 확인
|
||||
$checkResult = $this->moduleManager->checkModuleUpdate($identifier);
|
||||
// 업데이트 확인 (--zip 모드는 GitHub/번들 비교를 우회하므로 스킵)
|
||||
if ($zipPath === null) {
|
||||
$checkResult = $this->moduleManager->checkModuleUpdate($identifier);
|
||||
|
||||
if (! $checkResult['update_available'] && ! $force) {
|
||||
$this->info('✅ '.__('modules.commands.update.no_update', ['module' => $identifier]));
|
||||
if (! $checkResult['update_available'] && ! $force) {
|
||||
$this->info('✅ '.__('modules.commands.update.no_update', ['module' => $identifier]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 업데이트 정보 표시
|
||||
$this->info(__('modules.commands.update.current_version', ['version' => $checkResult['current_version']]));
|
||||
// 업데이트 정보 표시
|
||||
$this->info(__('modules.commands.update.current_version', ['version' => $checkResult['current_version']]));
|
||||
|
||||
if ($force && ! $checkResult['update_available']) {
|
||||
$this->warn('⚠️ '.__('modules.commands.update.force_mode'));
|
||||
if ($force && ! $checkResult['update_available']) {
|
||||
$this->warn('⚠️ '.__('modules.commands.update.force_mode'));
|
||||
} else {
|
||||
$this->info(__('modules.commands.update.latest_version', ['version' => $checkResult['latest_version']]));
|
||||
$this->info(__('modules.commands.update.update_source', ['source' => $checkResult['update_source']]));
|
||||
}
|
||||
} else {
|
||||
$this->info(__('modules.commands.update.latest_version', ['version' => $checkResult['latest_version']]));
|
||||
$this->info(__('modules.commands.update.update_source', ['source' => $checkResult['update_source']]));
|
||||
$this->info(__('modules.commands.update.current_version', ['version' => $module->version]));
|
||||
$this->info('업데이트 소스: ZIP ('.$zipPath.')');
|
||||
$this->info('업데이트 버전: (module.json 추출 후 판별)');
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
@@ -83,9 +128,31 @@ class UpdateModuleCommand extends Command
|
||||
}
|
||||
|
||||
// 업데이트 실행
|
||||
$vendorMode = VendorMode::fromStringOrAuto((string) $this->option('vendor-mode'));
|
||||
$onProgress = $this->createProgressCallback(ModuleManager::UPDATE_STEPS);
|
||||
|
||||
// upgrade step 콘솔 출력 콜백: progress bar 를 잠시 지우고 별도 줄에 출력
|
||||
$onUpgradeStep = function (string $version) use ($identifier): void {
|
||||
if ($this->progressBar) {
|
||||
$this->progressBar->clear();
|
||||
}
|
||||
$this->line(" • [{$identifier}] upgrade step 실행: {$version}");
|
||||
if ($this->progressBar) {
|
||||
$this->progressBar->display();
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
$updateResult = $this->moduleManager->updateModule($identifier, $force, $onProgress);
|
||||
$updateResult = $this->moduleManager->updateModule(
|
||||
$identifier,
|
||||
$force,
|
||||
$onProgress,
|
||||
$vendorMode,
|
||||
$layoutStrategy,
|
||||
$onUpgradeStep,
|
||||
$sourceOverride,
|
||||
$zipPath,
|
||||
);
|
||||
$this->finishProgress();
|
||||
} catch (\Exception $e) {
|
||||
$this->finishProgress();
|
||||
@@ -104,6 +171,7 @@ class UpdateModuleCommand extends Command
|
||||
'module' => $identifier,
|
||||
'from' => $updateResult['from_version'],
|
||||
'to' => $updateResult['to_version'],
|
||||
'layout_strategy' => $layoutStrategy,
|
||||
]);
|
||||
|
||||
return Command::SUCCESS;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\NotificationService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 오래된 사이트내 알림을 정리하는 커맨드
|
||||
*/
|
||||
class NotificationCleanupCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'notification:cleanup';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '보관 기간이 지난 사이트내 알림을 삭제합니다';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @param NotificationService $service 알림 서비스
|
||||
* @return int 명령 실행 결과 코드
|
||||
*/
|
||||
public function handle(NotificationService $service): int
|
||||
{
|
||||
$this->info('알림 정리 시작...');
|
||||
|
||||
$config = config('notification.database_channel', []);
|
||||
$this->info(" 읽음 보관: {$config['read_retention_days']}일, 미읽음 보관: {$config['unread_retention_days']}일");
|
||||
|
||||
$result = $service->cleanup();
|
||||
|
||||
$this->info(" 읽음 알림 삭제: {$result['deleted_read']}건");
|
||||
$this->info(" 미읽음 알림 삭제: {$result['deleted_unread']}건");
|
||||
$this->info('알림 정리 완료');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Console\Commands\Plugin;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Contracts\Repositories\PluginRepositoryInterface;
|
||||
use App\Extension\PluginManager;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ClearPluginCacheCommand extends Command
|
||||
@@ -26,7 +26,8 @@ class ClearPluginCacheCommand extends Command
|
||||
*/
|
||||
public function __construct(
|
||||
private PluginManager $pluginManager,
|
||||
private PluginRepositoryInterface $pluginRepository
|
||||
private PluginRepositoryInterface $pluginRepository,
|
||||
private CacheInterface $cache
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -74,7 +75,7 @@ class ClearPluginCacheCommand extends Command
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if (Cache::forget($key)) {
|
||||
if ($this->cache->forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
@@ -121,7 +122,7 @@ class ClearPluginCacheCommand extends Command
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if (Cache::forget($key)) {
|
||||
if ($this->cache->forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Console\Commands\Traits\HasProgressBar;
|
||||
use App\Contracts\Repositories\PluginRepositoryInterface;
|
||||
use App\Enums\ExtensionOwnerType;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Extension\Vendor\VendorMode;
|
||||
use App\Models\Permission;
|
||||
use App\Rules\ValidExtensionIdentifier;
|
||||
use Illuminate\Console\Command;
|
||||
@@ -19,7 +20,10 @@ class InstallPluginCommand extends Command
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'plugin:install {identifier : 설치할 플러그인 식별자}';
|
||||
protected $signature = 'plugin:install
|
||||
{identifier : 설치할 플러그인 식별자}
|
||||
{--vendor-mode=auto : Vendor 설치 모드 (auto|composer|bundled)}
|
||||
{--force : 이미 설치된 경우에도 _bundled/_pending 원본으로 활성 디렉토리를 덮어쓰고 재설치 (불완전 설치 복구)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -55,22 +59,29 @@ class InstallPluginCommand extends Command
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$force = (bool) $this->option('force');
|
||||
|
||||
try {
|
||||
// 플러그인 디렉토리 스캔 및 로드
|
||||
$this->pluginManager->loadPlugins();
|
||||
|
||||
// 이미 설치된 플러그인인지 확인
|
||||
// 이미 설치된 플러그인인지 확인 (force 시 스킵하여 재설치/복구 허용)
|
||||
$existingPlugin = $this->pluginRepository->findByIdentifier($identifier);
|
||||
if ($existingPlugin) {
|
||||
if ($existingPlugin && ! $force) {
|
||||
$this->warn('⚠️ '.__('plugins.commands.install.already_installed', ['plugin' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($existingPlugin && $force) {
|
||||
$this->warn('⚠️ '.__('plugins.commands.install.force_reinstall', ['plugin' => $identifier]));
|
||||
}
|
||||
|
||||
// 플러그인 설치
|
||||
$vendorMode = VendorMode::fromStringOrAuto((string) $this->option('vendor-mode'));
|
||||
$onProgress = $this->createProgressCallback(PluginManager::INSTALL_STEPS);
|
||||
try {
|
||||
$result = $this->pluginManager->installPlugin($identifier, $onProgress);
|
||||
$result = $this->pluginManager->installPlugin($identifier, $onProgress, $vendorMode, $force);
|
||||
$this->finishProgress();
|
||||
} catch (\Exception $e) {
|
||||
$this->finishProgress();
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Plugin;
|
||||
|
||||
use App\Console\Commands\Vendor\Concerns\RunsVendorBundleAction;
|
||||
use App\Extension\Vendor\VendorBundler;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 플러그인 vendor/ 디렉토리를 vendor-bundle.zip 으로 빌드합니다.
|
||||
*
|
||||
* 기존 plugin:build 패턴과 동일하게 positional identifier + --all 옵션 지원.
|
||||
*/
|
||||
class PluginVendorBundleCommand extends Command
|
||||
{
|
||||
use RunsVendorBundleAction;
|
||||
|
||||
protected $signature = 'plugin:vendor-bundle
|
||||
{identifier? : 빌드할 플러그인 식별자 (생략 시 --all 필요)}
|
||||
{--all : 모든 _bundled 플러그인 빌드}
|
||||
{--force : 해시 체크 무시, 강제 재빌드}
|
||||
{--check : 실제 빌드 없이 stale 여부만 확인}';
|
||||
|
||||
protected $description = '플러그인 vendor/ 디렉토리를 vendor-bundle.zip 으로 빌드합니다 (공유 호스팅용)';
|
||||
|
||||
public function handle(VendorBundler $bundler): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$all = (bool) $this->option('all');
|
||||
|
||||
if (! $identifier && ! $all) {
|
||||
$this->error('식별자 또는 --all 옵션을 지정해야 합니다.');
|
||||
$this->line('사용법:');
|
||||
$this->line(' php artisan plugin:vendor-bundle sirsoft-payment');
|
||||
$this->line(' php artisan plugin:vendor-bundle --all');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$targets = [];
|
||||
if ($all) {
|
||||
foreach ($this->discoverBundledIdentifiers('plugin') as $id) {
|
||||
$targets[] = ['type' => 'plugin', 'identifier' => $id];
|
||||
}
|
||||
} else {
|
||||
$targets[] = ['type' => 'plugin', 'identifier' => $identifier];
|
||||
}
|
||||
|
||||
return $this->runBuildAction(
|
||||
$bundler,
|
||||
$targets,
|
||||
(bool) $this->option('force'),
|
||||
(bool) $this->option('check'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Plugin;
|
||||
|
||||
use App\Console\Commands\Vendor\Concerns\RunsVendorBundleAction;
|
||||
use App\Extension\Vendor\VendorIntegrityChecker;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 플러그인 vendor-bundle.zip 무결성을 검증합니다.
|
||||
*/
|
||||
class PluginVendorVerifyCommand extends Command
|
||||
{
|
||||
use RunsVendorBundleAction;
|
||||
|
||||
protected $signature = 'plugin:vendor-verify
|
||||
{identifier? : 검증할 플러그인 식별자 (생략 시 --all 필요)}
|
||||
{--all : 모든 _bundled 플러그인 검증}';
|
||||
|
||||
protected $description = '플러그인 vendor-bundle.zip 의 SHA256 무결성을 검증합니다';
|
||||
|
||||
public function handle(VendorIntegrityChecker $checker): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$all = (bool) $this->option('all');
|
||||
|
||||
if (! $identifier && ! $all) {
|
||||
$this->error('식별자 또는 --all 옵션을 지정해야 합니다.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$targets = [];
|
||||
if ($all) {
|
||||
foreach ($this->discoverBundledIdentifiers('plugin') as $id) {
|
||||
$targets[] = ['type' => 'plugin', 'identifier' => $id];
|
||||
}
|
||||
} else {
|
||||
$targets[] = ['type' => 'plugin', 'identifier' => $identifier];
|
||||
}
|
||||
|
||||
return $this->runVerifyAction($checker, $targets);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Console\Commands\Plugin;
|
||||
use App\Console\Commands\Traits\HasProgressBar;
|
||||
use App\Contracts\Repositories\PluginRepositoryInterface;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Extension\Vendor\VendorMode;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -17,7 +18,11 @@ class UpdatePluginCommand extends Command
|
||||
*/
|
||||
protected $signature = 'plugin:update
|
||||
{identifier : 업데이트할 플러그인 식별자}
|
||||
{--force : 버전 비교 없이 강제 업데이트}';
|
||||
{--force : 버전 비교 없이 강제 업데이트}
|
||||
{--vendor-mode=auto : Vendor 설치 모드 (auto|composer|bundled)}
|
||||
{--layout-strategy=overwrite : 레이아웃 전략 (overwrite|keep)}
|
||||
{--source=auto : 업데이트 소스 (auto|bundled|github) — bundled 는 _bundled 만 사용(GitHub 우회)}
|
||||
{--zip= : 외부 ZIP 파일 경로 (지정 시 GitHub/번들 우회 + 버전은 plugin.json 기준)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -41,6 +46,39 @@ class UpdatePluginCommand extends Command
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$force = $this->option('force');
|
||||
$layoutStrategy = (string) $this->option('layout-strategy');
|
||||
$sourceOption = (string) $this->option('source');
|
||||
$zipPath = $this->option('zip');
|
||||
|
||||
if (! in_array($layoutStrategy, ['overwrite', 'keep'], true)) {
|
||||
$this->error('❌ --layout-strategy 는 overwrite 또는 keep 이어야 합니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (! in_array($sourceOption, ['auto', 'bundled', 'github'], true)) {
|
||||
$this->error('❌ --source 는 auto, bundled, github 중 하나여야 합니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($zipPath !== null && $sourceOption !== 'auto') {
|
||||
$this->error('❌ --zip 은 --source 와 동시에 지정할 수 없습니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($zipPath !== null) {
|
||||
$resolvedZip = realpath($zipPath);
|
||||
if (! $resolvedZip || ! is_file($resolvedZip)) {
|
||||
$this->error('❌ 지정된 ZIP 파일이 존재하지 않습니다: '.$zipPath);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$zipPath = $resolvedZip;
|
||||
}
|
||||
|
||||
$sourceOverride = $sourceOption === 'auto' ? null : $sourceOption;
|
||||
|
||||
try {
|
||||
$this->pluginManager->loadPlugins();
|
||||
@@ -54,23 +92,29 @@ class UpdatePluginCommand extends Command
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 업데이트 확인
|
||||
$checkResult = $this->pluginManager->checkPluginUpdate($identifier);
|
||||
// 업데이트 확인 (--zip 모드는 GitHub/번들 비교를 우회하므로 스킵)
|
||||
if ($zipPath === null) {
|
||||
$checkResult = $this->pluginManager->checkPluginUpdate($identifier);
|
||||
|
||||
if (! $checkResult['update_available'] && ! $force) {
|
||||
$this->info('✅ '.__('plugins.commands.update.no_update', ['plugin' => $identifier]));
|
||||
if (! $checkResult['update_available'] && ! $force) {
|
||||
$this->info('✅ '.__('plugins.commands.update.no_update', ['plugin' => $identifier]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 업데이트 정보 표시
|
||||
$this->info(__('plugins.commands.update.current_version', ['version' => $checkResult['current_version']]));
|
||||
// 업데이트 정보 표시
|
||||
$this->info(__('plugins.commands.update.current_version', ['version' => $checkResult['current_version']]));
|
||||
|
||||
if ($force && ! $checkResult['update_available']) {
|
||||
$this->warn('⚠️ '.__('plugins.commands.update.force_mode'));
|
||||
if ($force && ! $checkResult['update_available']) {
|
||||
$this->warn('⚠️ '.__('plugins.commands.update.force_mode'));
|
||||
} else {
|
||||
$this->info(__('plugins.commands.update.latest_version', ['version' => $checkResult['latest_version']]));
|
||||
$this->info(__('plugins.commands.update.update_source', ['source' => $checkResult['update_source']]));
|
||||
}
|
||||
} else {
|
||||
$this->info(__('plugins.commands.update.latest_version', ['version' => $checkResult['latest_version']]));
|
||||
$this->info(__('plugins.commands.update.update_source', ['source' => $checkResult['update_source']]));
|
||||
$this->info(__('plugins.commands.update.current_version', ['version' => $plugin->version]));
|
||||
$this->info('업데이트 소스: ZIP ('.$zipPath.')');
|
||||
$this->info('업데이트 버전: (plugin.json 추출 후 판별)');
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
@@ -83,9 +127,31 @@ class UpdatePluginCommand extends Command
|
||||
}
|
||||
|
||||
// 업데이트 실행
|
||||
$vendorMode = VendorMode::fromStringOrAuto((string) $this->option('vendor-mode'));
|
||||
$onProgress = $this->createProgressCallback(PluginManager::UPDATE_STEPS);
|
||||
|
||||
// upgrade step 콘솔 출력 콜백: progress bar 를 잠시 지우고 별도 줄에 출력
|
||||
$onUpgradeStep = function (string $version) use ($identifier): void {
|
||||
if ($this->progressBar) {
|
||||
$this->progressBar->clear();
|
||||
}
|
||||
$this->line(" • [{$identifier}] upgrade step 실행: {$version}");
|
||||
if ($this->progressBar) {
|
||||
$this->progressBar->display();
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
$updateResult = $this->pluginManager->updatePlugin($identifier, $force, $onProgress);
|
||||
$updateResult = $this->pluginManager->updatePlugin(
|
||||
$identifier,
|
||||
$force,
|
||||
$onProgress,
|
||||
$vendorMode,
|
||||
$layoutStrategy,
|
||||
$onUpgradeStep,
|
||||
$sourceOverride,
|
||||
$zipPath,
|
||||
);
|
||||
$this->finishProgress();
|
||||
} catch (\Exception $e) {
|
||||
$this->finishProgress();
|
||||
@@ -104,6 +170,7 @@ class UpdatePluginCommand extends Command
|
||||
'plugin' => $identifier,
|
||||
'from' => $updateResult['from_version'],
|
||||
'to' => $updateResult['to_version'],
|
||||
'layout_strategy' => $layoutStrategy,
|
||||
]);
|
||||
|
||||
return Command::SUCCESS;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Console\Commands\Template;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Extension\TemplateManager;
|
||||
use App\Models\Template;
|
||||
use App\Models\TemplateLayout;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ClearTemplateCacheCommand extends Command
|
||||
@@ -26,7 +26,8 @@ class ClearTemplateCacheCommand extends Command
|
||||
* 템플릿 관리자
|
||||
*/
|
||||
public function __construct(
|
||||
private TemplateManager $templateManager
|
||||
private TemplateManager $templateManager,
|
||||
private CacheInterface $cache
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -82,25 +83,25 @@ class ClearTemplateCacheCommand extends Command
|
||||
if ($templateRecord) {
|
||||
$layouts = TemplateLayout::where('template_id', $templateRecord->id)->get();
|
||||
foreach ($layouts as $layout) {
|
||||
Cache::forget("layout.{$identifier}.{$layout->name}");
|
||||
$this->cache->forget("layout.{$identifier}.{$layout->name}");
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Routes 캐시 삭제
|
||||
Cache::forget("template.routes.{$identifier}");
|
||||
$this->cache->forget("template.routes.{$identifier}");
|
||||
$clearedCount++;
|
||||
|
||||
// 3. 다국어 파일 캐시 삭제
|
||||
$supportedLocales = config('app.supported_locales', ['ko', 'en']);
|
||||
foreach ($supportedLocales as $locale) {
|
||||
Cache::forget("template.language.{$identifier}.{$locale}");
|
||||
$this->cache->forget("template.language.{$identifier}.{$locale}");
|
||||
$clearedCount++;
|
||||
}
|
||||
|
||||
// 4. 활성 템플릿 타입 캐시 삭제
|
||||
if ($templateRecord) {
|
||||
Cache::forget("templates.active.{$templateRecord->type}");
|
||||
$this->cache->forget("templates.active.{$templateRecord->type}");
|
||||
$clearedCount++;
|
||||
}
|
||||
|
||||
@@ -132,24 +133,24 @@ class ClearTemplateCacheCommand extends Command
|
||||
// 1. 레이아웃 캐시 삭제
|
||||
$layouts = TemplateLayout::where('template_id', $templateRecord->id)->get();
|
||||
foreach ($layouts as $layout) {
|
||||
Cache::forget("layout.{$templateRecord->identifier}.{$layout->name}");
|
||||
$this->cache->forget("layout.{$templateRecord->identifier}.{$layout->name}");
|
||||
$clearedCount++;
|
||||
}
|
||||
|
||||
// 2. Routes 캐시 삭제
|
||||
Cache::forget("template.routes.{$templateRecord->identifier}");
|
||||
$this->cache->forget("template.routes.{$templateRecord->identifier}");
|
||||
$clearedCount++;
|
||||
|
||||
// 3. 다국어 파일 캐시 삭제
|
||||
foreach ($supportedLocales as $locale) {
|
||||
Cache::forget("template.language.{$templateRecord->identifier}.{$locale}");
|
||||
$this->cache->forget("template.language.{$templateRecord->identifier}.{$locale}");
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 활성 템플릿 타입 캐시 삭제
|
||||
Cache::forget('templates.active.admin');
|
||||
Cache::forget('templates.active.user');
|
||||
$this->cache->forget('templates.active.admin');
|
||||
$this->cache->forget('templates.active.user');
|
||||
$clearedCount += 2;
|
||||
|
||||
$this->info('✅ '.__('templates.commands.cache_clear.success_all', [
|
||||
|
||||
@@ -17,7 +17,9 @@ class InstallTemplateCommand extends Command
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'template:install {identifier : 템플릿 식별자 (디렉토리명)}';
|
||||
protected $signature = 'template:install
|
||||
{identifier : 템플릿 식별자 (디렉토리명)}
|
||||
{--force : 이미 설치된 경우에도 _bundled/_pending 원본으로 활성 디렉토리를 덮어쓰고 재설치 (불완전 설치 복구)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -53,14 +55,22 @@ class InstallTemplateCommand extends Command
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$force = (bool) $this->option('force');
|
||||
|
||||
try {
|
||||
// 템플릿 디렉토리 스캔 및 로드
|
||||
$this->templateManager->loadTemplates();
|
||||
|
||||
// 이미 설치된 템플릿인지 확인 (force 시 경고 후 재설치/복구 허용)
|
||||
$existingTemplate = $this->templateRepository->findByIdentifier($identifier);
|
||||
if ($existingTemplate && $force) {
|
||||
$this->warn('⚠️ '.__('templates.commands.install.force_reinstall', ['template' => $identifier]));
|
||||
}
|
||||
|
||||
// 템플릿 설치
|
||||
$onProgress = $this->createProgressCallback(TemplateManager::INSTALL_STEPS);
|
||||
try {
|
||||
$result = $this->templateManager->installTemplate($identifier, $onProgress);
|
||||
$result = $this->templateManager->installTemplate($identifier, $onProgress, $force);
|
||||
$this->finishProgress();
|
||||
} catch (\Exception $e) {
|
||||
$this->finishProgress();
|
||||
|
||||
@@ -18,7 +18,9 @@ class UpdateTemplateCommand extends Command
|
||||
protected $signature = 'template:update
|
||||
{identifier : 업데이트할 템플릿 식별자}
|
||||
{--layout-strategy=overwrite : 레이아웃 전략 (overwrite|keep)}
|
||||
{--force : 버전 비교 없이 강제 업데이트}';
|
||||
{--force : 버전 비교 없이 강제 업데이트}
|
||||
{--source=auto : 업데이트 소스 (auto|bundled|github) — bundled 는 _bundled 만 사용(GitHub 우회)}
|
||||
{--zip= : 외부 ZIP 파일 경로 (지정 시 GitHub/번들 우회 + 버전은 template.json 기준)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -43,6 +45,8 @@ class UpdateTemplateCommand extends Command
|
||||
$identifier = $this->argument('identifier');
|
||||
$layoutStrategy = $this->option('layout-strategy');
|
||||
$force = $this->option('force');
|
||||
$sourceOption = (string) $this->option('source');
|
||||
$zipPath = $this->option('zip');
|
||||
|
||||
// 레이아웃 전략 검증
|
||||
if (! in_array($layoutStrategy, ['overwrite', 'keep'])) {
|
||||
@@ -51,6 +55,30 @@ class UpdateTemplateCommand extends Command
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (! in_array($sourceOption, ['auto', 'bundled', 'github'], true)) {
|
||||
$this->error('❌ --source 는 auto, bundled, github 중 하나여야 합니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($zipPath !== null && $sourceOption !== 'auto') {
|
||||
$this->error('❌ --zip 은 --source 와 동시에 지정할 수 없습니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($zipPath !== null) {
|
||||
$resolvedZip = realpath($zipPath);
|
||||
if (! $resolvedZip || ! is_file($resolvedZip)) {
|
||||
$this->error('❌ 지정된 ZIP 파일이 존재하지 않습니다: '.$zipPath);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$zipPath = $resolvedZip;
|
||||
}
|
||||
|
||||
$sourceOverride = $sourceOption === 'auto' ? null : $sourceOption;
|
||||
|
||||
try {
|
||||
$this->templateManager->loadTemplates();
|
||||
|
||||
@@ -63,23 +91,29 @@ class UpdateTemplateCommand extends Command
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 업데이트 확인
|
||||
$checkResult = $this->templateManager->checkTemplateUpdate($identifier);
|
||||
// 업데이트 확인 (--zip 모드는 GitHub/번들 비교를 우회하므로 스킵)
|
||||
if ($zipPath === null) {
|
||||
$checkResult = $this->templateManager->checkTemplateUpdate($identifier);
|
||||
|
||||
if (! $checkResult['update_available'] && ! $force) {
|
||||
$this->info('✅ '.__('templates.commands.update.no_update', ['template' => $identifier]));
|
||||
if (! $checkResult['update_available'] && ! $force) {
|
||||
$this->info('✅ '.__('templates.commands.update.no_update', ['template' => $identifier]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 업데이트 정보 표시
|
||||
$this->info(__('templates.commands.update.current_version', ['version' => $checkResult['current_version']]));
|
||||
// 업데이트 정보 표시
|
||||
$this->info(__('templates.commands.update.current_version', ['version' => $checkResult['current_version']]));
|
||||
|
||||
if ($force && ! $checkResult['update_available']) {
|
||||
$this->warn('⚠️ '.__('templates.commands.update.force_mode'));
|
||||
if ($force && ! $checkResult['update_available']) {
|
||||
$this->warn('⚠️ '.__('templates.commands.update.force_mode'));
|
||||
} else {
|
||||
$this->info(__('templates.commands.update.latest_version', ['version' => $checkResult['latest_version']]));
|
||||
$this->info(__('templates.commands.update.update_source', ['source' => $checkResult['update_source']]));
|
||||
}
|
||||
} else {
|
||||
$this->info(__('templates.commands.update.latest_version', ['version' => $checkResult['latest_version']]));
|
||||
$this->info(__('templates.commands.update.update_source', ['source' => $checkResult['update_source']]));
|
||||
$this->info(__('templates.commands.update.current_version', ['version' => $template->version]));
|
||||
$this->info('업데이트 소스: ZIP ('.$zipPath.')');
|
||||
$this->info('업데이트 버전: (template.json 추출 후 판별)');
|
||||
}
|
||||
|
||||
$this->info(__('templates.commands.update.layout_strategy', ['strategy' => $layoutStrategy]));
|
||||
@@ -115,7 +149,7 @@ class UpdateTemplateCommand extends Command
|
||||
// 업데이트 실행
|
||||
$onProgress = $this->createProgressCallback(TemplateManager::UPDATE_STEPS);
|
||||
try {
|
||||
$updateResult = $this->templateManager->updateTemplate($identifier, $layoutStrategy, $force, $onProgress);
|
||||
$updateResult = $this->templateManager->updateTemplate($identifier, $force, $onProgress, $layoutStrategy, $sourceOverride, $zipPath);
|
||||
$this->finishProgress();
|
||||
} catch (\Exception $e) {
|
||||
$this->finishProgress();
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Vendor;
|
||||
|
||||
use App\Console\Commands\Vendor\Concerns\RunsVendorBundleAction;
|
||||
use App\Extension\Vendor\VendorBundler;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 코어 + 모든 _bundled 모듈/플러그인 vendor 번들 일괄 빌드.
|
||||
*
|
||||
* 개별 빌드는 다음 명령어를 사용:
|
||||
* - core:vendor-bundle
|
||||
* - module:vendor-bundle [identifier|--all]
|
||||
* - plugin:vendor-bundle [identifier|--all]
|
||||
*
|
||||
* 본 명령어는 운영/CI 시나리오에서 한 번에 전체 번들을 갱신하기 위한 일괄 전용 명령어다.
|
||||
*/
|
||||
class BuildVendorBundleCommand extends Command
|
||||
{
|
||||
use RunsVendorBundleAction;
|
||||
|
||||
protected $signature = 'vendor-bundle:build-all
|
||||
{--force : 해시 체크 무시, 강제 재빌드}
|
||||
{--check : 실제 빌드 없이 stale 여부만 확인}';
|
||||
|
||||
protected $description = '코어 + 모든 _bundled 모듈/플러그인의 vendor 번들을 일괄 빌드합니다';
|
||||
|
||||
public function handle(VendorBundler $bundler): int
|
||||
{
|
||||
$targets = [['type' => 'core', 'identifier' => null]];
|
||||
|
||||
foreach ($this->discoverBundledIdentifiers('module') as $id) {
|
||||
$targets[] = ['type' => 'module', 'identifier' => $id];
|
||||
}
|
||||
|
||||
foreach ($this->discoverBundledIdentifiers('plugin') as $id) {
|
||||
$targets[] = ['type' => 'plugin', 'identifier' => $id];
|
||||
}
|
||||
|
||||
return $this->runBuildAction(
|
||||
$bundler,
|
||||
$targets,
|
||||
(bool) $this->option('force'),
|
||||
(bool) $this->option('check'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Vendor\Concerns;
|
||||
|
||||
use App\Extension\Vendor\Exceptions\VendorInstallException;
|
||||
use App\Extension\Vendor\VendorBundleResult;
|
||||
use App\Extension\Vendor\VendorBundler;
|
||||
use App\Extension\Vendor\VendorIntegrityChecker;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
/**
|
||||
* Vendor 번들 빌드/검증 액션 공통 로직.
|
||||
*
|
||||
* core:vendor-bundle / module:vendor-bundle / plugin:vendor-bundle 및
|
||||
* 일괄 빌드 vendor-bundle:build-all 명령어들이 본 trait 을 공유한다.
|
||||
*/
|
||||
trait RunsVendorBundleAction
|
||||
{
|
||||
/**
|
||||
* 빌드 또는 stale 체크 수행.
|
||||
*
|
||||
* @param array<int, array{type: string, identifier: ?string}> $targets
|
||||
* @param bool $force 해시 체크 무시하고 강제 재빌드
|
||||
* @param bool $check 실제 빌드 없이 stale 여부만 확인 (true 면 stale 시 종료코드 1)
|
||||
*/
|
||||
protected function runBuildAction(VendorBundler $bundler, array $targets, bool $force, bool $check): int
|
||||
{
|
||||
if (empty($targets)) {
|
||||
$this->error('빌드 대상이 없습니다.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->line($check ? 'Vendor Bundle Status Check' : 'Vendor Bundle Build');
|
||||
$this->line(str_repeat('─', 66));
|
||||
$this->newLine();
|
||||
|
||||
$hasStale = false;
|
||||
$results = [];
|
||||
|
||||
foreach ($targets as $target) {
|
||||
try {
|
||||
if ($check) {
|
||||
if ($this->performCheck($bundler, $target)) {
|
||||
$hasStale = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$results[] = $this->performBuild($bundler, $target, $force);
|
||||
} catch (VendorInstallException $e) {
|
||||
$this->error(sprintf('✗ %s: %s', $this->formatTargetLabel($target), $e->getMessage()));
|
||||
} catch (\Throwable $e) {
|
||||
$this->error(sprintf('✗ %s: %s', $this->formatTargetLabel($target), $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
$this->line(str_repeat('─', 66));
|
||||
|
||||
if ($check) {
|
||||
return $hasStale ? self::FAILURE : self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->printBuildSummary($results);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 무결성 검증 수행.
|
||||
*
|
||||
* @param array<int, array{type: string, identifier: ?string}> $targets
|
||||
*/
|
||||
protected function runVerifyAction(VendorIntegrityChecker $checker, array $targets): int
|
||||
{
|
||||
if (empty($targets)) {
|
||||
$this->error('검증 대상이 없습니다.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->line('Vendor Bundle Integrity Verification');
|
||||
$this->line(str_repeat('─', 66));
|
||||
$this->newLine();
|
||||
|
||||
$failures = 0;
|
||||
foreach ($targets as $target) {
|
||||
$label = $this->formatTargetLabel($target);
|
||||
$outputPath = $this->resolveOutputPath($target);
|
||||
|
||||
if (! is_dir($outputPath)) {
|
||||
$this->warn("- $label: 출력 경로 없음");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$zipPath = $outputPath.DIRECTORY_SEPARATOR.VendorIntegrityChecker::ZIP_FILENAME;
|
||||
if (! file_exists($zipPath)) {
|
||||
$this->line("- $label: 번들 없음 (스킵)");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = $checker->verify($outputPath);
|
||||
|
||||
if ($result->valid) {
|
||||
$packageCount = $result->meta['package_count'] ?? 0;
|
||||
$zipSize = @filesize($zipPath) ?: 0;
|
||||
$this->line(sprintf(
|
||||
'✓ %s: OK (%.1f MB, %d packages)',
|
||||
$label,
|
||||
$zipSize / 1024 / 1024,
|
||||
$packageCount,
|
||||
));
|
||||
} else {
|
||||
$failures++;
|
||||
$this->error(sprintf('✗ %s: FAILED', $label));
|
||||
foreach ($result->errorMessages() as $message) {
|
||||
$this->line(' - '.$message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
$this->line(str_repeat('─', 66));
|
||||
|
||||
if ($failures > 0) {
|
||||
$this->error("검증 실패: $failures 개");
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info('모든 번들이 무결성 검증을 통과했습니다.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* `_bundled` 디렉토리에서 모든 모듈/플러그인 식별자 목록 반환.
|
||||
*
|
||||
* @param string $type 'module' | 'plugin'
|
||||
* @return array<int, string>
|
||||
*/
|
||||
protected function discoverBundledIdentifiers(string $type): array
|
||||
{
|
||||
$base = base_path($type === 'module' ? 'modules/_bundled' : 'plugins/_bundled');
|
||||
if (! is_dir($base)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$identifiers = [];
|
||||
foreach (File::directories($base) as $dir) {
|
||||
if (is_file($dir.DIRECTORY_SEPARATOR.'composer.json')) {
|
||||
$identifiers[] = basename($dir);
|
||||
}
|
||||
}
|
||||
|
||||
return $identifiers;
|
||||
}
|
||||
|
||||
private function performBuild(VendorBundler $bundler, array $target, bool $force): VendorBundleResult
|
||||
{
|
||||
$label = $this->formatTargetLabel($target);
|
||||
$this->line("▶ $label 빌드 중...");
|
||||
|
||||
$result = $target['type'] === 'core'
|
||||
? $bundler->buildForCore($force)
|
||||
: $bundler->buildForExtension($target['type'], $target['identifier'], $force);
|
||||
|
||||
if ($result->skipped && $result->reason === 'no-external-dependencies') {
|
||||
$this->line(sprintf(
|
||||
' ○ %s: 스킵 (외부 composer 의존성 없음)',
|
||||
$label,
|
||||
));
|
||||
} elseif ($result->skipped && $result->reason === 'extension-not-installed') {
|
||||
$this->line(sprintf(
|
||||
' ○ %s: 스킵 (확장이 설치되지 않음 — 먼저 module:install / plugin:install 필요)',
|
||||
$label,
|
||||
));
|
||||
} elseif ($result->skipped) {
|
||||
$this->line(sprintf(
|
||||
' ○ %s: 스킵 (%s, %s, %d packages)',
|
||||
$label,
|
||||
$result->reason,
|
||||
$result->zipSizeHuman(),
|
||||
$result->packageCount,
|
||||
));
|
||||
} else {
|
||||
$this->line(sprintf(
|
||||
' ✓ %s: %s, %d packages',
|
||||
$label,
|
||||
$result->zipSizeHuman(),
|
||||
$result->packageCount,
|
||||
));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* stale 여부 확인만 수행.
|
||||
*
|
||||
* @return bool stale 이면 true
|
||||
*/
|
||||
private function performCheck(VendorBundler $bundler, array $target): bool
|
||||
{
|
||||
$label = $this->formatTargetLabel($target);
|
||||
$sourcePath = $this->resolveSourcePath($target);
|
||||
$outputPath = $this->resolveOutputPath($target);
|
||||
|
||||
if (! is_dir($sourcePath)) {
|
||||
$this->warn("- $label: 소스 경로 없음 ($sourcePath)");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$composerJsonPath = $sourcePath.DIRECTORY_SEPARATOR.'composer.json';
|
||||
if (! is_file($composerJsonPath)) {
|
||||
$this->line("- $label: SKIPPED (composer.json 없음)");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 외부 composer 의존성이 없는 확장은 번들링 대상이 아님
|
||||
if (! $this->composerJsonHasExternalDependencies($composerJsonPath)) {
|
||||
$this->line("- $label: SKIPPED (외부 composer 의존성 없음)");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$stale = $bundler->isStale($sourcePath, $outputPath);
|
||||
if ($stale) {
|
||||
$this->error("✗ $label: STALE — 재빌드 필요");
|
||||
} else {
|
||||
$this->line("✓ $label: up-to-date");
|
||||
}
|
||||
|
||||
return $stale;
|
||||
}
|
||||
|
||||
/**
|
||||
* composer.json 에 외부 패키지 의존성이 있는지 확인합니다.
|
||||
*
|
||||
* VendorBundler::hasExternalDependencies() 와 동일 로직 — trait 에서 중복 구현을
|
||||
* 피하지 않고 독립적으로 구현하여 VendorBundler 인스턴스 없이도 사용 가능하게 함.
|
||||
*/
|
||||
private function composerJsonHasExternalDependencies(string $composerJsonPath): bool
|
||||
{
|
||||
$json = @file_get_contents($composerJsonPath);
|
||||
if ($json === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
|
||||
} catch (\JsonException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$require = $data['require'] ?? [];
|
||||
if (! is_array($require) || empty($require)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (array_keys($require) as $package) {
|
||||
if ($package === 'php' || str_starts_with($package, 'ext-')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{type: string, identifier: ?string} $target
|
||||
*/
|
||||
private function formatTargetLabel(array $target): string
|
||||
{
|
||||
return $target['type'] === 'core'
|
||||
? 'core'
|
||||
: sprintf('%ss/%s', $target['type'], $target['identifier']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 소스 경로 (composer.json, composer.lock, vendor/ 를 읽는 경로).
|
||||
*
|
||||
* 코어: base_path() 자체가 소스이자 출력
|
||||
* 모듈/플러그인: 활성 디렉토리 (modules/{id}, plugins/{id}) — 설치 시 composer install 이 실행된 곳
|
||||
*
|
||||
* @param array{type: string, identifier: ?string} $target
|
||||
*/
|
||||
private function resolveSourcePath(array $target): string
|
||||
{
|
||||
return match ($target['type']) {
|
||||
'core' => base_path(),
|
||||
'module' => base_path('modules/'.$target['identifier']),
|
||||
'plugin' => base_path('plugins/'.$target['identifier']),
|
||||
default => '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 출력 경로 (vendor-bundle.zip 과 vendor-bundle.json 을 쓰는 경로).
|
||||
*
|
||||
* 코어: base_path() (소스와 동일)
|
||||
* 모듈/플러그인: _bundled 디렉토리 — Git 추적되는 배포 아티팩트 저장 위치
|
||||
*
|
||||
* @param array{type: string, identifier: ?string} $target
|
||||
*/
|
||||
private function resolveOutputPath(array $target): string
|
||||
{
|
||||
return match ($target['type']) {
|
||||
'core' => base_path(),
|
||||
'module' => base_path('modules/_bundled/'.$target['identifier']),
|
||||
'plugin' => base_path('plugins/_bundled/'.$target['identifier']),
|
||||
default => '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, VendorBundleResult> $results
|
||||
*/
|
||||
private function printBuildSummary(array $results): void
|
||||
{
|
||||
$built = 0;
|
||||
$skipped = 0;
|
||||
$totalSize = 0;
|
||||
|
||||
foreach ($results as $result) {
|
||||
if ($result->skipped) {
|
||||
$skipped++;
|
||||
} else {
|
||||
$built++;
|
||||
}
|
||||
$totalSize += $result->zipSize;
|
||||
}
|
||||
|
||||
$this->line(sprintf(
|
||||
'Summary: %d built, %d skipped, total %.1f MB',
|
||||
$built,
|
||||
$skipped,
|
||||
$totalSize / 1024 / 1024,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Vendor;
|
||||
|
||||
use App\Console\Commands\Vendor\Concerns\RunsVendorBundleAction;
|
||||
use App\Extension\Vendor\VendorIntegrityChecker;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 코어 + 모든 _bundled 모듈/플러그인 vendor 번들 일괄 검증.
|
||||
*
|
||||
* 개별 검증은 다음 명령어를 사용:
|
||||
* - core:vendor-verify
|
||||
* - module:vendor-verify [identifier|--all]
|
||||
* - plugin:vendor-verify [identifier|--all]
|
||||
*
|
||||
* 본 명령어는 운영/CI 시나리오에서 한 번에 전체 번들의 무결성을 확인하기 위한 일괄 전용 명령어다.
|
||||
*/
|
||||
class VerifyVendorBundleCommand extends Command
|
||||
{
|
||||
use RunsVendorBundleAction;
|
||||
|
||||
protected $signature = 'vendor-bundle:verify-all';
|
||||
|
||||
protected $description = '코어 + 모든 _bundled 모듈/플러그인의 vendor 번들 무결성을 일괄 검증합니다';
|
||||
|
||||
public function handle(VendorIntegrityChecker $checker): int
|
||||
{
|
||||
$targets = [['type' => 'core', 'identifier' => null]];
|
||||
|
||||
foreach ($this->discoverBundledIdentifiers('module') as $id) {
|
||||
$targets[] = ['type' => 'module', 'identifier' => $id];
|
||||
}
|
||||
|
||||
foreach ($this->discoverBundledIdentifiers('plugin') as $id) {
|
||||
$targets[] = ['type' => 'plugin', 'identifier' => $id];
|
||||
}
|
||||
|
||||
return $this->runVerifyAction($checker, $targets);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user