v7.0.0-beta.1 release
This commit is contained in:
commit
6595fd0eb5
3967 files changed
+1875383
No files matched your search
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\ModuleManager;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ActivateModuleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:activate {identifier : 활성화할 모듈 식별자} {--force : 의존성 미충족 시 강제 활성화}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈을 활성화합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
|
||||
try {
|
||||
// 모듈 디렉토리 스캔 및 로드
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
// 모듈이 설치되어 있는지 확인
|
||||
$moduleRecord = $this->moduleRepository->findByIdentifier($identifier);
|
||||
if (! $moduleRecord) {
|
||||
$this->error('❌ '.__('modules.commands.activate.not_installed', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 이미 활성화된 모듈인지 확인
|
||||
if ($moduleRecord->status === ExtensionStatus::Active->value) {
|
||||
$this->warn('⚠️ '.__('modules.commands.activate.already_active', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 모듈 활성화
|
||||
$force = $this->option('force');
|
||||
$result = $this->moduleManager->activateModule($identifier, $force);
|
||||
|
||||
// 경고 응답인 경우 (의존성 미충족)
|
||||
if (isset($result['warning']) && $result['warning'] === true) {
|
||||
$this->warn('⚠️ '.$result['message']);
|
||||
$this->line('');
|
||||
|
||||
if (! empty($result['missing_modules'])) {
|
||||
$this->info('필요한 모듈:');
|
||||
foreach ($result['missing_modules'] as $module) {
|
||||
$statusLabel = $module['status'] === 'not_installed' ? '미설치' : '비활성';
|
||||
$this->line(" - {$module['identifier']} ({$module['name']}) [{$statusLabel}]");
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($result['missing_plugins'])) {
|
||||
$this->info('필요한 플러그인:');
|
||||
foreach ($result['missing_plugins'] as $plugin) {
|
||||
$statusLabel = $plugin['status'] === 'not_installed' ? '미설치' : '비활성';
|
||||
$this->line(" - {$plugin['identifier']} ({$plugin['name']}) [{$statusLabel}]");
|
||||
}
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
$this->info('강제로 활성화하려면 --force 옵션을 사용하세요.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($result['success']) {
|
||||
$this->info('✅ '.__('modules.commands.activate.success', ['module' => $identifier]));
|
||||
$this->info(' - '.__('modules.commands.activate.layouts_registered', ['count' => $result['layouts_registered']]));
|
||||
Log::info(__('modules.commands.activate.success', ['module' => $identifier]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
return Command::FAILURE;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 활성화 실패', [
|
||||
'module' => $identifier,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class BuildModuleCommand extends Command
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:build
|
||||
{identifier? : 빌드할 모듈 식별자 (생략 시 --all 필요)}
|
||||
{--all : 모든 모듈 빌드}
|
||||
{--watch : 파일 변경 감시 모드}
|
||||
{--production : 프로덕션 빌드}
|
||||
{--active : 활성 디렉토리에서 빌드}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈의 프론트엔드 에셋을 빌드합니다 (기본: _bundled 디렉토리)';
|
||||
|
||||
/**
|
||||
* 모듈 관리자
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$buildAll = $this->option('all');
|
||||
$watchMode = $this->option('watch');
|
||||
$productionMode = $this->option('production');
|
||||
|
||||
if (! $identifier && ! $buildAll) {
|
||||
$this->error('❌ 모듈 식별자를 지정하거나 --all 옵션을 사용하세요.');
|
||||
$this->line('');
|
||||
$this->line('사용법:');
|
||||
$this->line(' php artisan module:build sirsoft-ecommerce');
|
||||
$this->line(' php artisan module:build --all');
|
||||
$this->line(' php artisan module:build sirsoft-ecommerce --watch');
|
||||
$this->line(' php artisan module:build --all --production');
|
||||
$this->line(' php artisan module:build sirsoft-ecommerce --active');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
// 모듈 로드
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
if ($buildAll) {
|
||||
return $this->buildAllModules($productionMode);
|
||||
}
|
||||
|
||||
return $this->buildModule($identifier, $watchMode, $productionMode);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 빌드 실패', [
|
||||
'module' => $identifier ?? 'all',
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 빌드 대상 경로를 결정합니다.
|
||||
*
|
||||
* 기본값: _bundled 디렉토리. --active 옵션 시 활성 디렉토리.
|
||||
* --watch 모드에서는 활성 디렉토리를 사용합니다 (실시간 개발용).
|
||||
*
|
||||
* @param string $identifier 모듈 식별자
|
||||
* @return array|null ['path' => string, 'source' => 'bundled'|'active'] 또는 null
|
||||
*/
|
||||
private function resolveBuildPath(string $identifier): ?array
|
||||
{
|
||||
$bundledPath = base_path("modules/_bundled/{$identifier}");
|
||||
$activePath = base_path("modules/{$identifier}");
|
||||
|
||||
// --active 명시 → 활성 디렉토리
|
||||
if ($this->option('active')) {
|
||||
return is_dir($activePath)
|
||||
? ['path' => $activePath, 'source' => 'active']
|
||||
: null;
|
||||
}
|
||||
|
||||
// --watch 모드 → 활성 디렉토리 (실시간 개발용)
|
||||
if ($this->option('watch')) {
|
||||
if (is_dir($activePath)) {
|
||||
return ['path' => $activePath, 'source' => 'active'];
|
||||
}
|
||||
}
|
||||
|
||||
// 기본값: _bundled 우선
|
||||
if (is_dir($bundledPath)) {
|
||||
return ['path' => $bundledPath, 'source' => 'bundled'];
|
||||
}
|
||||
|
||||
// _bundled에 없으면 활성 디렉토리 폴백
|
||||
if (is_dir($activePath)) {
|
||||
return ['path' => $activePath, 'source' => 'active'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 단일 모듈 빌드
|
||||
*
|
||||
* @param string $identifier 모듈 식별자
|
||||
* @param bool $watchMode 파일 감시 모드
|
||||
* @param bool $productionMode 프로덕션 빌드
|
||||
* @return int 명령 실행 결과 코드
|
||||
*/
|
||||
private function buildModule(string $identifier, bool $watchMode, bool $productionMode): int
|
||||
{
|
||||
// 경로 결정
|
||||
$resolved = $this->resolveBuildPath($identifier);
|
||||
if (! $resolved) {
|
||||
$this->error("❌ 모듈을 찾을 수 없습니다: {$identifier}");
|
||||
$this->line(' _bundled 및 활성 디렉토리 모두 존재하지 않습니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$buildPath = $resolved['path'];
|
||||
$source = $resolved['source'];
|
||||
|
||||
// 소스 표시
|
||||
$sourceLabel = $source === 'bundled' ? '_bundled' : '활성';
|
||||
$this->info("📂 빌드 소스: {$sourceLabel} ({$buildPath})");
|
||||
|
||||
// package.json 존재 확인
|
||||
$packageJsonPath = $buildPath.'/package.json';
|
||||
if (! file_exists($packageJsonPath)) {
|
||||
$this->error('❌ package.json 파일이 없습니다: '.$packageJsonPath);
|
||||
$this->line(' 모듈 프론트엔드 구조를 먼저 생성하세요.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 에셋 빌드 가능 여부 확인 (활성 모듈 인스턴스가 있는 경우)
|
||||
$module = $this->moduleManager->getModule($identifier);
|
||||
if ($module && ! $module->canBuild() && ! $module->hasAssets()) {
|
||||
$this->warn('⚠️ 모듈에 빌드할 에셋이 없습니다: '.$identifier);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// node_modules 확인 및 설치
|
||||
if (! is_dir($buildPath.'/node_modules')) {
|
||||
$this->info('📦 의존성 설치 중...');
|
||||
$installResult = $this->runNpmCommand(['npm', 'install'], $buildPath);
|
||||
|
||||
if ($installResult !== Command::SUCCESS) {
|
||||
$this->error('❌ npm install 실패');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// 빌드 명령 결정
|
||||
$buildCommand = ['npm', 'run'];
|
||||
|
||||
if ($watchMode) {
|
||||
$buildCommand[] = 'dev';
|
||||
$this->info("👀 파일 감시 모드로 빌드 시작: {$identifier}");
|
||||
$this->line(' Ctrl+C로 종료할 수 있습니다.');
|
||||
} else {
|
||||
$buildCommand[] = 'build';
|
||||
$this->info("🔨 빌드 시작: {$identifier}".($productionMode ? ' (프로덕션)' : ''));
|
||||
}
|
||||
|
||||
// 빌드 실행
|
||||
$result = $this->runNpmCommand($buildCommand, $buildPath, ! $watchMode);
|
||||
|
||||
if ($result === Command::SUCCESS && ! $watchMode) {
|
||||
$this->info("✅ 빌드 완료: {$identifier}");
|
||||
|
||||
// 빌드 결과 파일 확인
|
||||
$this->displayBuildResults($buildPath, $identifier);
|
||||
|
||||
// 캐시 버전 증가 (브라우저 캐시 무효화)
|
||||
$this->incrementExtensionCacheVersion();
|
||||
$this->line(' - 캐시 버전 갱신됨');
|
||||
|
||||
// _bundled 빌드 시 활성 반영 안내
|
||||
if ($source === 'bundled') {
|
||||
$this->line('');
|
||||
$this->info("💡 활성 디렉토리에 반영하려면: php artisan module:update {$identifier}");
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 빌드 결과 파일 정보를 출력합니다.
|
||||
*
|
||||
* @param string $buildPath 빌드된 경로
|
||||
* @param string $identifier 모듈 식별자
|
||||
*/
|
||||
private function displayBuildResults(string $buildPath, string $identifier): void
|
||||
{
|
||||
// 활성 모듈 인스턴스가 있으면 getBuiltAssetPaths 활용
|
||||
$module = $this->moduleManager->getModule($identifier);
|
||||
if ($module) {
|
||||
$builtPaths = $module->getBuiltAssetPaths();
|
||||
|
||||
if (! empty($builtPaths['js'])) {
|
||||
$jsPath = $buildPath.'/'.$builtPaths['js'];
|
||||
if (file_exists($jsPath)) {
|
||||
$this->line(' - JS: '.$builtPaths['js'].' ('.number_format(filesize($jsPath) / 1024, 2).' KB)');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($builtPaths['css'])) {
|
||||
$cssPath = $buildPath.'/'.$builtPaths['css'];
|
||||
if (file_exists($cssPath)) {
|
||||
$this->line(' - CSS: '.$builtPaths['css'].' ('.number_format(filesize($cssPath) / 1024, 2).' KB)');
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 활성 인스턴스 없으면 manifest에서 직접 확인
|
||||
$manifestPath = $buildPath.'/module.json';
|
||||
if (file_exists($manifestPath)) {
|
||||
$manifest = json_decode(file_get_contents($manifestPath), true);
|
||||
$assets = $manifest['assets'] ?? [];
|
||||
|
||||
if (! empty($assets['js']['output'])) {
|
||||
$jsPath = $buildPath.'/'.$assets['js']['output'];
|
||||
if (file_exists($jsPath)) {
|
||||
$this->line(' - JS: '.$assets['js']['output'].' ('.number_format(filesize($jsPath) / 1024, 2).' KB)');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($assets['css']['output'])) {
|
||||
$cssPath = $buildPath.'/'.$assets['css']['output'];
|
||||
if (file_exists($cssPath)) {
|
||||
$this->line(' - CSS: '.$assets['css']['output'].' ('.number_format(filesize($cssPath) / 1024, 2).' KB)');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 모듈 빌드
|
||||
*
|
||||
* @param bool $productionMode 프로덕션 빌드
|
||||
* @return int 명령 실행 결과 코드
|
||||
*/
|
||||
private function buildAllModules(bool $productionMode): int
|
||||
{
|
||||
$buildTargets = [];
|
||||
|
||||
if ($this->option('active')) {
|
||||
// --active: 활성 디렉토리만 대상
|
||||
$activeModules = $this->moduleManager->getAllModules();
|
||||
foreach ($activeModules as $identifier => $module) {
|
||||
$activePath = base_path("modules/{$identifier}");
|
||||
if (file_exists($activePath.'/package.json')
|
||||
&& ($module->canBuild() || $module->hasAssets())) {
|
||||
$buildTargets[$identifier] = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 기본값: _bundled 디렉토리 스캔
|
||||
$bundledModules = $this->moduleManager->getBundledModules();
|
||||
foreach ($bundledModules as $identifier => $metadata) {
|
||||
$bundledPath = $metadata['source_path'];
|
||||
if (file_exists($bundledPath.'/package.json')) {
|
||||
$assets = $metadata['assets'] ?? [];
|
||||
if (! empty($assets['js']['entry']) || ! empty($assets['css']['entry']) || ! empty($assets)) {
|
||||
$buildTargets[$identifier] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($buildTargets)) {
|
||||
$this->warn('⚠️ 빌드할 모듈이 없습니다.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$sourceLabel = $this->option('active') ? '활성' : '_bundled';
|
||||
$this->info("🔨 모든 모듈 빌드 시작 ({$sourceLabel})".($productionMode ? ' (프로덕션)' : ''));
|
||||
$this->line(' 대상 모듈: '.implode(', ', array_keys($buildTargets)));
|
||||
$this->line('');
|
||||
|
||||
$successCount = 0;
|
||||
$failCount = 0;
|
||||
|
||||
foreach ($buildTargets as $identifier => $value) {
|
||||
$this->line(" [{$identifier}]");
|
||||
$result = $this->buildModule($identifier, false, $productionMode);
|
||||
|
||||
if ($result === Command::SUCCESS) {
|
||||
$successCount++;
|
||||
} else {
|
||||
$failCount++;
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
$this->info("📊 빌드 결과: 성공 {$successCount}개, 실패 {$failCount}개");
|
||||
|
||||
return $failCount > 0 ? Command::FAILURE : Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* npm 명령 실행
|
||||
*
|
||||
* @param array $command 실행할 명령
|
||||
* @param string $cwd 작업 디렉토리
|
||||
* @param bool $waitForCompletion 완료 대기 여부
|
||||
* @return int 명령 실행 결과 코드
|
||||
*/
|
||||
private function runNpmCommand(array $command, string $cwd, bool $waitForCompletion = true): int
|
||||
{
|
||||
// Windows 환경에서는 cmd /c 사용
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
$command = array_merge(['cmd', '/c'], $command);
|
||||
}
|
||||
|
||||
$process = new Process($command);
|
||||
$process->setWorkingDirectory($cwd);
|
||||
$process->setTimeout(null); // 타임아웃 없음
|
||||
|
||||
if ($waitForCompletion) {
|
||||
$process->run(function ($type, $buffer) {
|
||||
$this->output->write($buffer);
|
||||
});
|
||||
|
||||
return $process->isSuccessful() ? Command::SUCCESS : Command::FAILURE;
|
||||
}
|
||||
|
||||
// 감시 모드: 인터럽트까지 실행
|
||||
$process->start(function ($type, $buffer) {
|
||||
$this->output->write($buffer);
|
||||
});
|
||||
|
||||
// 프로세스가 실행 중인 동안 대기
|
||||
while ($process->isRunning()) {
|
||||
usleep(100000); // 100ms
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Extension\ModuleManager;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CheckModuleUpdatesCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:check-updates {identifier? : 특정 모듈만 확인 (선택)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈 업데이트를 확인합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
|
||||
try {
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
if ($identifier) {
|
||||
return $this->checkSingle($identifier);
|
||||
}
|
||||
|
||||
return $this->checkAll();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 업데이트 확인 실패', [
|
||||
'module' => $identifier,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 단일 모듈 업데이트를 확인합니다.
|
||||
*
|
||||
* @param string $identifier 모듈 식별자
|
||||
*/
|
||||
private function checkSingle(string $identifier): int
|
||||
{
|
||||
$module = $this->moduleRepository->findByIdentifier($identifier);
|
||||
|
||||
if (! $module) {
|
||||
$this->error('❌ '.__('modules.commands.check_updates.not_installed', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$result = $this->moduleManager->checkModuleUpdate($identifier);
|
||||
|
||||
// 단일 체크는 DB 갱신이 안 되므로 커맨드에서 직접 갱신
|
||||
$this->moduleRepository->updateByIdentifier($identifier, [
|
||||
'update_available' => $result['update_available'],
|
||||
'latest_version' => $result['latest_version'],
|
||||
'update_source' => $result['update_source'],
|
||||
]);
|
||||
|
||||
if ($result['update_available']) {
|
||||
$this->info('🔄 '.__('modules.commands.check_updates.single_update_available', [
|
||||
'module' => $identifier,
|
||||
'current' => $result['current_version'],
|
||||
'latest' => $result['latest_version'],
|
||||
'source' => $result['update_source'],
|
||||
]));
|
||||
} else {
|
||||
$this->info('✅ '.__('modules.commands.check_updates.single_up_to_date', [
|
||||
'module' => $identifier,
|
||||
'version' => $result['current_version'],
|
||||
]));
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 설치된 모듈의 업데이트를 확인합니다.
|
||||
*/
|
||||
private function checkAll(): int
|
||||
{
|
||||
$installedModules = $this->moduleManager->getInstalledModulesWithDetails();
|
||||
|
||||
if (empty($installedModules)) {
|
||||
$this->info(__('modules.commands.check_updates.no_installed'));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// checkAllModulesForUpdates는 내부에서 DB 갱신 포함
|
||||
$result = $this->moduleManager->checkAllModulesForUpdates();
|
||||
|
||||
$tableData = [];
|
||||
$updateCount = 0;
|
||||
|
||||
foreach ($result['details'] as $detail) {
|
||||
$isUpdate = $detail['update_available'] ?? false;
|
||||
if ($isUpdate) {
|
||||
$updateCount++;
|
||||
}
|
||||
|
||||
$tableData[] = [
|
||||
$detail['identifier'],
|
||||
$detail['current_version'] ?? '-',
|
||||
$detail['latest_version'] ?? '-',
|
||||
$detail['update_source'] ?? '-',
|
||||
$isUpdate
|
||||
? '🔄 '.__('modules.commands.check_updates.update_available')
|
||||
: '✅ '.__('modules.commands.check_updates.up_to_date'),
|
||||
];
|
||||
}
|
||||
|
||||
$headers = [
|
||||
__('modules.commands.check_updates.headers.identifier'),
|
||||
__('modules.commands.check_updates.headers.current_version'),
|
||||
__('modules.commands.check_updates.headers.latest_version'),
|
||||
__('modules.commands.check_updates.headers.source'),
|
||||
__('modules.commands.check_updates.headers.status'),
|
||||
];
|
||||
|
||||
$this->table($headers, $tableData);
|
||||
$this->newLine();
|
||||
$this->info(__('modules.commands.check_updates.summary', [
|
||||
'total' => count($result['details']),
|
||||
'updates' => $updateCount,
|
||||
]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:cache-clear
|
||||
{identifier? : 특정 모듈의 캐시만 삭제 (생략 시 모든 모듈)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈 캐시를 삭제합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
|
||||
try {
|
||||
// 모듈 디렉토리 스캔 및 로드
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
$clearedCount = 0;
|
||||
|
||||
if ($identifier) {
|
||||
// 특정 모듈 캐시 삭제
|
||||
$this->info(__('modules.commands.cache_clear.clearing_single', ['module' => $identifier]));
|
||||
|
||||
// 모듈이 존재하는지 확인
|
||||
$module = $this->moduleManager->getModule($identifier);
|
||||
if (! $module) {
|
||||
$this->error('❌ '.__('modules.not_found', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$clearedCount = $this->clearModuleCache($identifier);
|
||||
|
||||
$this->info('✅ '.__('modules.commands.cache_clear.success_single', [
|
||||
'module' => $identifier,
|
||||
'count' => $clearedCount,
|
||||
]));
|
||||
} else {
|
||||
// 모든 모듈 캐시 삭제
|
||||
$this->info(__('modules.commands.cache_clear.clearing_all'));
|
||||
|
||||
// 전체 모듈 캐시 키 삭제
|
||||
$cacheKeys = [
|
||||
'modules.all',
|
||||
'modules.active',
|
||||
'modules.installed',
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if (Cache::forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 각 모듈별 캐시 삭제
|
||||
$allModules = $this->moduleManager->getAllModules();
|
||||
foreach ($allModules as $moduleName => $module) {
|
||||
$clearedCount += $this->clearModuleCache($module->getIdentifier());
|
||||
}
|
||||
|
||||
$this->info('✅ '.__('modules.commands.cache_clear.success_all', ['count' => $clearedCount]));
|
||||
}
|
||||
|
||||
Log::info('모듈 캐시 삭제 완료', [
|
||||
'module' => $identifier ?? 'all',
|
||||
'count' => $clearedCount,
|
||||
]);
|
||||
|
||||
return Command::SUCCESS;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 캐시 삭제 실패', [
|
||||
'module' => $identifier ?? 'all',
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 모듈의 캐시를 삭제합니다.
|
||||
*/
|
||||
private function clearModuleCache(string $identifier): int
|
||||
{
|
||||
$clearedCount = 0;
|
||||
|
||||
// 모듈별 캐시 키
|
||||
$cacheKeys = [
|
||||
"module.config.{$identifier}",
|
||||
"module.info.{$identifier}",
|
||||
"module.routes.{$identifier}",
|
||||
"module.permissions.{$identifier}",
|
||||
"module.menus.{$identifier}",
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if (Cache::forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return $clearedCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Extension\ExtensionManager;
|
||||
use App\Extension\ModuleManager;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ComposerInstallModuleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:composer-install
|
||||
{identifier? : Composer 의존성을 설치할 모듈 식별자 (생략 시 --all 필요)}
|
||||
{--all : 모든 모듈의 Composer 의존성 설치}
|
||||
{--no-dev : dev 의존성 제외}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈의 Composer 의존성을 설치합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ExtensionManager $extensionManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$installAll = $this->option('all');
|
||||
$noDev = $this->option('no-dev');
|
||||
|
||||
if (! $identifier && ! $installAll) {
|
||||
$this->error('❌ 모듈 식별자를 지정하거나 --all 옵션을 사용하세요.');
|
||||
$this->line('');
|
||||
$this->line('사용법:');
|
||||
$this->line(' php artisan module:composer-install sirsoft-ecommerce');
|
||||
$this->line(' php artisan module:composer-install --all');
|
||||
$this->line(' php artisan module:composer-install --all --no-dev');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
if ($installAll) {
|
||||
return $this->installAllModules($noDev);
|
||||
}
|
||||
|
||||
return $this->installModule($identifier, $noDev);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 Composer 의존성 설치 실패', [
|
||||
'module' => $identifier ?? 'all',
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 단일 모듈의 Composer 의존성 설치
|
||||
*
|
||||
* @param string $identifier 모듈 식별자
|
||||
* @param bool $noDev dev 의존성 제외 여부
|
||||
* @return int 커맨드 결과 코드
|
||||
*/
|
||||
private function installModule(string $identifier, bool $noDev): int
|
||||
{
|
||||
$module = $this->moduleManager->getModule($identifier);
|
||||
|
||||
if (! $module) {
|
||||
$this->error('❌ '.__('modules.errors.not_found', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (! $this->extensionManager->hasComposerDependencies('modules', $identifier)) {
|
||||
$this->info('ℹ️ '.__('modules.composer_install.no_dependencies', ['module' => $identifier]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$deps = $this->extensionManager->getComposerDependencies('modules', $identifier);
|
||||
$this->info('📦 '.__('modules.composer_install.start', ['module' => $identifier]));
|
||||
$this->line(' '.implode(', ', array_keys($deps)));
|
||||
|
||||
$result = $this->extensionManager->runComposerInstall('modules', $identifier, $noDev, $this);
|
||||
|
||||
if ($result) {
|
||||
$this->info('✅ '.__('modules.composer_install.success', ['module' => $identifier]));
|
||||
|
||||
// 오토로드 갱신
|
||||
$this->extensionManager->updateComposerAutoload();
|
||||
$this->line(' 오토로드 캐시 갱신 완료');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$this->error('❌ '.__('modules.composer_install.failed', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 모듈의 Composer 의존성 설치
|
||||
*
|
||||
* @param bool $noDev dev 의존성 제외 여부
|
||||
* @return int 커맨드 결과 코드
|
||||
*/
|
||||
private function installAllModules(bool $noDev): int
|
||||
{
|
||||
$modules = $this->moduleManager->getAllModules();
|
||||
|
||||
if (empty($modules)) {
|
||||
$this->warn('⚠️ 설치된 모듈이 없습니다.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 중복 패키지 감지
|
||||
$duplicates = $this->extensionManager->detectDuplicatePackages();
|
||||
if (! empty($duplicates)) {
|
||||
$this->warn('⚠️ 중복 패키지 감지:');
|
||||
foreach ($duplicates as $package => $users) {
|
||||
$this->warn(" - {$package}: ".implode(', ', $users));
|
||||
}
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
$this->info('📦 모든 모듈의 Composer 의존성 설치 시작');
|
||||
|
||||
$successCount = 0;
|
||||
$skipCount = 0;
|
||||
$failCount = 0;
|
||||
|
||||
foreach ($modules as $identifier => $module) {
|
||||
if (! $this->extensionManager->hasComposerDependencies('modules', $identifier)) {
|
||||
$skipCount++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->line(" [{$identifier}]");
|
||||
$result = $this->extensionManager->runComposerInstall('modules', $identifier, $noDev, $this);
|
||||
|
||||
if ($result) {
|
||||
$successCount++;
|
||||
$this->info(" ✅ 완료: {$identifier}");
|
||||
} else {
|
||||
$failCount++;
|
||||
$this->error(" ❌ 실패: {$identifier}");
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
// 오토로드 갱신
|
||||
$this->extensionManager->updateComposerAutoload();
|
||||
|
||||
$this->info(__('modules.composer_install.summary', [
|
||||
'success' => $successCount,
|
||||
'skip' => $skipCount,
|
||||
'fail' => $failCount,
|
||||
]));
|
||||
|
||||
return $failCount > 0 ? Command::FAILURE : Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\ModuleManager;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DeactivateModuleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:deactivate {identifier : 비활성화할 모듈 식별자} {--force : 의존 템플릿이 있어도 강제 비활성화}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈을 비활성화합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
|
||||
try {
|
||||
// 모듈 디렉토리 스캔 및 로드
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
// 모듈이 설치되어 있는지 확인
|
||||
$moduleRecord = $this->moduleRepository->findByIdentifier($identifier);
|
||||
if (! $moduleRecord) {
|
||||
$this->error('❌ '.__('modules.commands.deactivate.not_installed', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 모듈이 활성화되어 있는지 확인
|
||||
if ($moduleRecord->status !== ExtensionStatus::Active->value) {
|
||||
$this->warn('⚠️ '.__('modules.commands.deactivate.not_active', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 모듈 비활성화
|
||||
$force = $this->option('force');
|
||||
$result = $this->moduleManager->deactivateModule($identifier, $force);
|
||||
|
||||
// 경고 응답인 경우 (의존 템플릿 존재)
|
||||
if (isset($result['warning']) && $result['warning'] === true) {
|
||||
$this->warn('⚠️ '.$result['message']);
|
||||
$this->line('');
|
||||
$this->info('의존하는 템플릿 목록:');
|
||||
foreach ($result['dependent_templates'] as $template) {
|
||||
$this->line(" - {$template['identifier']} ({$template['name']})");
|
||||
}
|
||||
$this->line('');
|
||||
$this->info('강제로 비활성화하려면 --force 옵션을 사용하세요.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($result['success']) {
|
||||
$this->info('✅ '.__('modules.commands.deactivate.success', ['module' => $identifier]));
|
||||
$this->info(' - '.__('modules.commands.deactivate.layouts_deleted', ['count' => $result['layouts_deleted']]));
|
||||
$this->warn('⚠️ '.__('modules.commands.deactivate.warning'));
|
||||
Log::info(__('modules.commands.deactivate.success', ['module' => $identifier]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
return Command::FAILURE;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 비활성화 실패', [
|
||||
'module' => $identifier,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Console\Commands\Traits\HasProgressBar;
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Enums\ExtensionOwnerType;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Models\Menu;
|
||||
use App\Models\Permission;
|
||||
use App\Rules\ValidExtensionIdentifier;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class InstallModuleCommand extends Command
|
||||
{
|
||||
use HasProgressBar;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:install {identifier : 설치할 모듈 식별자}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈을 설치합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
|
||||
// 식별자 형식 검증
|
||||
$validator = Validator::make(
|
||||
['identifier' => $identifier],
|
||||
['identifier' => [new ValidExtensionIdentifier]]
|
||||
);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$this->error('❌ '.$validator->errors()->first('identifier'));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
// 모듈 디렉토리 스캔 및 로드
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
// 이미 설치된 모듈인지 확인
|
||||
$existingModule = $this->moduleRepository->findByIdentifier($identifier);
|
||||
if ($existingModule) {
|
||||
$this->warn('⚠️ '.__('modules.commands.install.already_installed', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 모듈 설치
|
||||
$onProgress = $this->createProgressCallback(ModuleManager::INSTALL_STEPS);
|
||||
try {
|
||||
$result = $this->moduleManager->installModule($identifier, $onProgress);
|
||||
$this->finishProgress();
|
||||
} catch (\Exception $e) {
|
||||
$this->finishProgress();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
// 설치된 모듈 정보 조회
|
||||
$module = $this->moduleRepository->findByIdentifier($identifier);
|
||||
|
||||
// 모듈 인스턴스에서 생성된 role 개수 조회
|
||||
$moduleInstance = $this->moduleManager->getModule($identifier);
|
||||
$rolesCount = 0;
|
||||
if ($moduleInstance && method_exists($moduleInstance, 'getRoles')) {
|
||||
$rolesCount = count($moduleInstance->getRoles());
|
||||
}
|
||||
|
||||
// 권한 및 메뉴 개수 조회
|
||||
$permissionsCount = Permission::byExtension(ExtensionOwnerType::Module, $identifier)->count();
|
||||
$menusCount = Menu::byExtension(ExtensionOwnerType::Module, $identifier)->count();
|
||||
|
||||
// 성공 메시지
|
||||
$this->info('✅ '.__('modules.commands.install.success', ['module' => $identifier]));
|
||||
$this->info(' - '.__('modules.commands.install.vendor', ['vendor' => $module->vendor]));
|
||||
$this->info(' - '.__('modules.commands.install.version', ['version' => $module->version]));
|
||||
$this->info(' - '.__('modules.commands.install.roles_created', ['count' => $rolesCount]));
|
||||
$this->info(' - '.__('modules.commands.install.permissions_created', ['count' => $permissionsCount]));
|
||||
$this->info(' - '.__('modules.commands.install.menus_created', ['count' => $menusCount]));
|
||||
|
||||
Log::info(__('modules.commands.install.success', ['module' => $identifier]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
return Command::FAILURE;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 설치 실패', [
|
||||
'module' => $identifier,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\ModuleManager;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ListModuleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:list
|
||||
{--status= : 상태로 필터 (installed, uninstalled, active, inactive)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈 목록을 조회합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
// 모듈 디렉토리 스캔 및 로드
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
$statusFilter = $this->option('status');
|
||||
|
||||
// 상태 필터 검증
|
||||
if ($statusFilter && ! in_array($statusFilter, ['installed', 'uninstalled', 'active', 'inactive'])) {
|
||||
$this->error('❌ '.__('modules.commands.list.invalid_status'));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 설치된 모듈 정보
|
||||
$installedModules = $this->moduleManager->getInstalledModulesWithDetails();
|
||||
|
||||
// 미설치 모듈 정보
|
||||
$uninstalledModules = $this->moduleManager->getUninstalledModules();
|
||||
|
||||
// 테이블 데이터 준비
|
||||
$tableData = [];
|
||||
|
||||
// 설치된 모듈 추가
|
||||
foreach ($installedModules as $identifier => $module) {
|
||||
// 상태 필터
|
||||
if ($statusFilter) {
|
||||
if ($statusFilter === 'uninstalled') {
|
||||
continue;
|
||||
}
|
||||
if ($statusFilter === 'active' && $module['status'] !== ExtensionStatus::Active->value) {
|
||||
continue;
|
||||
}
|
||||
if ($statusFilter === 'inactive' && $module['status'] !== ExtensionStatus::Inactive->value) {
|
||||
continue;
|
||||
}
|
||||
if ($statusFilter === 'installed' && ! in_array($module['status'], [ExtensionStatus::Active->value, ExtensionStatus::Inactive->value])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$tableData[] = [
|
||||
'identifier' => $identifier,
|
||||
'name' => $module['name'],
|
||||
'vendor' => $module['vendor'],
|
||||
'version' => $module['version'],
|
||||
'status' => $this->formatStatus($module['status']),
|
||||
];
|
||||
}
|
||||
|
||||
// 미설치 모듈 추가
|
||||
if (! $statusFilter || $statusFilter === 'uninstalled') {
|
||||
foreach ($uninstalledModules as $identifier => $module) {
|
||||
// 상태 필터 (uninstalled 또는 필터 없음)
|
||||
if ($statusFilter && $statusFilter !== 'uninstalled') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tableData[] = [
|
||||
'identifier' => $identifier,
|
||||
'name' => $module['name'],
|
||||
'vendor' => $module['vendor'],
|
||||
'version' => $module['version'],
|
||||
'status' => $this->formatStatus('uninstalled'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 모듈이 없는 경우
|
||||
if (empty($tableData)) {
|
||||
$this->info(__('modules.commands.list.no_modules'));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 테이블 헤더
|
||||
$headers = [
|
||||
__('modules.commands.list.headers.identifier'),
|
||||
__('modules.commands.list.headers.name'),
|
||||
__('modules.commands.list.headers.vendor'),
|
||||
__('modules.commands.list.headers.version'),
|
||||
__('modules.commands.list.headers.status'),
|
||||
];
|
||||
|
||||
// 테이블 출력
|
||||
$this->table($headers, $tableData);
|
||||
|
||||
// 요약 정보
|
||||
$totalCount = count($tableData);
|
||||
$activeCount = count(array_filter($tableData, fn ($m) => str_contains($m['status'], __('modules.commands.list.status.active'))));
|
||||
$installedCount = count(array_filter($tableData, fn ($m) => ! str_contains($m['status'], __('modules.commands.list.status.uninstalled'))));
|
||||
|
||||
$this->newLine();
|
||||
$this->info(__('modules.commands.list.summary', [
|
||||
'total' => $totalCount,
|
||||
'installed' => $installedCount,
|
||||
'active' => $activeCount,
|
||||
]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 상태 포맷팅
|
||||
*/
|
||||
private function formatStatus(string $status): string
|
||||
{
|
||||
return match ($status) {
|
||||
ExtensionStatus::Active->value => '✅ '.__('modules.commands.list.status.active'),
|
||||
ExtensionStatus::Inactive->value => '⏸️ '.__('modules.commands.list.status.inactive'),
|
||||
'uninstalled' => '📦 '.__('modules.commands.list.status.uninstalled'),
|
||||
default => $status,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Models\Module;
|
||||
use App\Services\ModuleService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* 모듈 레이아웃 갱신 커맨드
|
||||
*
|
||||
* 레이아웃 JSON 파일만 수정된 경우, 빌드 없이 레이아웃만 갱신합니다.
|
||||
*/
|
||||
class RefreshModuleLayoutCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:refresh-layout
|
||||
{identifier? : 특정 모듈의 식별자 (생략 시 모든 활성 모듈)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈 레이아웃을 갱신합니다 (빌드 없이 JSON만 DB에 동기화)';
|
||||
|
||||
public function __construct(
|
||||
private ModuleService $moduleService
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
|
||||
try {
|
||||
if ($identifier) {
|
||||
return $this->refreshSingle($identifier);
|
||||
}
|
||||
|
||||
return $this->refreshAll();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 레이아웃 갱신 실패', [
|
||||
'module' => $identifier ?? 'all',
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 모듈의 레이아웃을 갱신합니다.
|
||||
*/
|
||||
private function refreshSingle(string $identifier): int
|
||||
{
|
||||
$this->info("모듈 '{$identifier}' 레이아웃 갱신 중...");
|
||||
|
||||
$result = $this->moduleService->refreshModuleLayouts($identifier);
|
||||
|
||||
if ($result) {
|
||||
$this->info("✅ 모듈 '{$identifier}' 레이아웃 갱신 완료");
|
||||
Log::info('모듈 레이아웃 갱신 완료', ['module' => $identifier]);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$this->error("❌ 모듈 '{$identifier}' 레이아웃 갱신 실패");
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 활성 모듈의 레이아웃을 갱신합니다.
|
||||
*/
|
||||
private function refreshAll(): int
|
||||
{
|
||||
$modules = Module::where('status', 'active')->pluck('identifier')->toArray();
|
||||
|
||||
if (empty($modules)) {
|
||||
$this->line('활성화된 모듈이 없습니다.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$this->info('모든 활성 모듈 레이아웃 갱신 중...');
|
||||
|
||||
$successCount = 0;
|
||||
$failCount = 0;
|
||||
|
||||
foreach ($modules as $moduleIdentifier) {
|
||||
$this->line(" {$moduleIdentifier} 갱신 중...");
|
||||
|
||||
try {
|
||||
$result = $this->moduleService->refreshModuleLayouts($moduleIdentifier);
|
||||
|
||||
if ($result) {
|
||||
$this->info(" ✅ {$moduleIdentifier} 완료");
|
||||
$successCount++;
|
||||
} else {
|
||||
$this->warn(" ⚠️ {$moduleIdentifier} 실패");
|
||||
$failCount++;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->warn(" ⚠️ {$moduleIdentifier}: ".$e->getMessage());
|
||||
$failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
$this->info("✅ 총 {$successCount}개 성공, {$failCount}개 실패");
|
||||
|
||||
Log::info('모듈 레이아웃 일괄 갱신 완료', [
|
||||
'success' => $successCount,
|
||||
'failed' => $failCount,
|
||||
]);
|
||||
|
||||
return $failCount > 0 ? Command::FAILURE : Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\ExtensionManager;
|
||||
use App\Extension\ModuleManager;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SeedModuleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:seed
|
||||
{identifier? : 시더를 실행할 모듈 식별자 (생략 시 모든 활성 모듈)}
|
||||
{--class= : 실행할 특정 시더 클래스명}
|
||||
{--count=* : 시더에 전달할 카운트 옵션 (형식: key=value, 예: --count=products=1000)}
|
||||
{--sample : 샘플 데이터 시더도 함께 실행}
|
||||
{--force : 프로덕션 환경에서도 강제 실행}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈의 데이터베이스 시더를 실행합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$seederClass = $this->option('class');
|
||||
$force = $this->option('force');
|
||||
|
||||
// 프로덕션 환경 확인
|
||||
if (app()->environment('production') && ! $force) {
|
||||
$this->error('❌ 프로덕션 환경에서는 --force 옵션이 필요합니다.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
// 모듈 로드
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
if ($identifier) {
|
||||
return $this->seedModule($identifier, $seederClass);
|
||||
}
|
||||
|
||||
return $this->seedAllActiveModules($seederClass);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 시더 실행 실패', [
|
||||
'module' => $identifier ?? 'all',
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 단일 모듈 시더 실행
|
||||
*
|
||||
* @param string $identifier 모듈 식별자
|
||||
* @param string|null $seederClass 특정 시더 클래스명
|
||||
* @return int 명령 실행 결과
|
||||
*/
|
||||
private function seedModule(string $identifier, ?string $seederClass): int
|
||||
{
|
||||
// 모듈 존재 여부 확인
|
||||
$module = $this->moduleManager->getModule($identifier);
|
||||
|
||||
if (! $module) {
|
||||
$this->error('❌ '.__('modules.errors.not_found', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 활성화 상태 확인
|
||||
$moduleRecord = $this->moduleRepository->findByIdentifier($identifier);
|
||||
|
||||
if (! $moduleRecord || $moduleRecord->status !== ExtensionStatus::Active->value) {
|
||||
$this->error('❌ 모듈이 활성화되어 있지 않습니다: '.$identifier);
|
||||
$this->line(' 먼저 php artisan module:activate '.$identifier.' 명령을 실행하세요.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 시더 경로 확인
|
||||
$modulePath = base_path("modules/{$identifier}");
|
||||
$seederPath = $modulePath.'/database/seeders';
|
||||
|
||||
if (! is_dir($seederPath)) {
|
||||
$this->warn('⚠️ 모듈에 시더 디렉토리가 없습니다: '.$identifier);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 시더 클래스 결정
|
||||
$seederClassName = $this->resolveSeederClass($identifier, $seederClass);
|
||||
|
||||
if (! class_exists($seederClassName)) {
|
||||
$this->error('❌ 시더 클래스를 찾을 수 없습니다: '.$seederClassName);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$this->info("🌱 시더 실행 시작: {$identifier}");
|
||||
$this->line(' 클래스: '.$seederClassName);
|
||||
$this->line('');
|
||||
|
||||
// 시더 실행
|
||||
$seeder = app($seederClassName);
|
||||
$seeder->setCommand($this);
|
||||
|
||||
// --sample 옵션 전파
|
||||
if (method_exists($seeder, 'setIncludeSample')) {
|
||||
$seeder->setIncludeSample((bool) $this->option('sample'));
|
||||
}
|
||||
|
||||
// --count 옵션 전파
|
||||
$counts = $this->parseCountOptions();
|
||||
if (! empty($counts) && method_exists($seeder, 'setSeederCounts')) {
|
||||
$seeder->setSeederCounts($counts);
|
||||
}
|
||||
|
||||
$seeder->run();
|
||||
|
||||
$this->line('');
|
||||
$this->info("✅ 시더 실행 완료: {$identifier}");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 활성 모듈 시더 실행
|
||||
*
|
||||
* @param string|null $seederClass 특정 시더 클래스명
|
||||
* @return int 명령 실행 결과
|
||||
*/
|
||||
private function seedAllActiveModules(?string $seederClass): int
|
||||
{
|
||||
$activeModules = $this->moduleManager->getActiveModules();
|
||||
|
||||
if (empty($activeModules)) {
|
||||
$this->warn('⚠️ 활성화된 모듈이 없습니다.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 시더가 있는 모듈만 필터링
|
||||
$seedableModules = [];
|
||||
|
||||
foreach ($activeModules as $identifier => $module) {
|
||||
$seederPath = base_path("modules/{$identifier}/database/seeders");
|
||||
$seederClassName = $this->resolveSeederClass($identifier, $seederClass);
|
||||
|
||||
if (is_dir($seederPath) && class_exists($seederClassName)) {
|
||||
$seedableModules[$identifier] = $module;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($seedableModules)) {
|
||||
$this->warn('⚠️ 시더가 있는 활성 모듈이 없습니다.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$this->info('🌱 모든 활성 모듈 시더 실행 시작');
|
||||
$this->line(' 대상 모듈: '.implode(', ', array_keys($seedableModules)));
|
||||
$this->line('');
|
||||
|
||||
$successCount = 0;
|
||||
$failCount = 0;
|
||||
|
||||
foreach ($seedableModules as $identifier => $module) {
|
||||
$this->line("━━━ [{$identifier}] ━━━");
|
||||
$result = $this->seedModule($identifier, $seederClass);
|
||||
|
||||
if ($result === Command::SUCCESS) {
|
||||
$successCount++;
|
||||
} else {
|
||||
$failCount++;
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
$this->info("📊 시더 실행 결과: 성공 {$successCount}개, 실패 {$failCount}개");
|
||||
|
||||
return $failCount > 0 ? Command::FAILURE : Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* --count 옵션을 파싱하여 연관 배열로 반환합니다.
|
||||
*
|
||||
* 입력: ['products=1000', 'orders=500']
|
||||
* 출력: ['products' => 1000, 'orders' => 500]
|
||||
*
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function parseCountOptions(): array
|
||||
{
|
||||
$countOptions = $this->option('count');
|
||||
$counts = [];
|
||||
|
||||
foreach ($countOptions as $option) {
|
||||
if (str_contains($option, '=')) {
|
||||
[$key, $value] = explode('=', $option, 2);
|
||||
$key = trim($key);
|
||||
if ($key !== '') {
|
||||
$counts[$key] = (int) trim($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $counts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 시더 클래스명 해석
|
||||
*
|
||||
* @param string $identifier 모듈 식별자
|
||||
* @param string|null $seederClass 사용자 지정 시더 클래스명
|
||||
* @return string 완전한 시더 클래스명
|
||||
*/
|
||||
private function resolveSeederClass(string $identifier, ?string $seederClass): string
|
||||
{
|
||||
$namespace = ExtensionManager::moduleIdentifierToNamespace($identifier);
|
||||
|
||||
if ($seederClass) {
|
||||
// 사용자가 지정한 클래스명 사용
|
||||
if (str_contains($seederClass, '\\')) {
|
||||
return $seederClass;
|
||||
}
|
||||
|
||||
return $namespace.'Database\\Seeders\\'.$seederClass;
|
||||
}
|
||||
|
||||
// 기본 DatabaseSeeder 사용
|
||||
return $namespace.'Database\\Seeders\\DatabaseSeeder';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Console\Commands\Traits\HasProgressBar;
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Enums\ExtensionOwnerType;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Models\Menu;
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UninstallModuleCommand extends Command
|
||||
{
|
||||
use HasProgressBar;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:uninstall
|
||||
{identifier : 제거할 모듈 식별자}
|
||||
{--force : 확인 없이 삭제}
|
||||
{--delete-data : 모듈 데이터(테이블, 환경설정) 함께 삭제}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈을 제거합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
|
||||
try {
|
||||
// 모듈 디렉토리 스캔 및 로드
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
// 모듈이 설치되어 있는지 확인
|
||||
$moduleRecord = $this->moduleRepository->findByIdentifier($identifier);
|
||||
if (! $moduleRecord) {
|
||||
$this->error('❌ '.__('modules.commands.uninstall.not_installed', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 모듈 인스턴스에서 role 개수 조회
|
||||
$moduleInstance = $this->moduleManager->getModule($identifier);
|
||||
$rolesCount = 0;
|
||||
if ($moduleInstance && method_exists($moduleInstance, 'getRoles')) {
|
||||
$rolesCount = count($moduleInstance->getRoles());
|
||||
}
|
||||
|
||||
// 권한, 메뉴, 레이아웃 개수 조회
|
||||
$permissionsCount = Permission::byExtension(ExtensionOwnerType::Module, $identifier)->count();
|
||||
$menusCount = Menu::byExtension(ExtensionOwnerType::Module, $identifier)->count();
|
||||
$layoutsCount = $this->moduleManager->getModuleLayoutsCount($identifier);
|
||||
|
||||
// 확인 프롬프트 (--force 옵션이 없는 경우)
|
||||
if (! $this->option('force')) {
|
||||
$this->warn(__('modules.commands.uninstall.confirm_prompt', ['module' => $identifier]));
|
||||
$this->line(__('modules.commands.uninstall.confirm_details.roles', ['count' => $rolesCount]));
|
||||
$this->line(__('modules.commands.uninstall.confirm_details.permissions', ['count' => $permissionsCount]));
|
||||
$this->line(__('modules.commands.uninstall.confirm_details.menus', ['count' => $menusCount]));
|
||||
$this->line(__('modules.commands.uninstall.confirm_details.layouts', ['count' => $layoutsCount]));
|
||||
$this->line(__('modules.commands.uninstall.confirm_details.data'));
|
||||
if ($this->option('delete-data')) {
|
||||
$this->warn('⚠️ --delete-data: 마이그레이션 롤백 및 환경설정 파일이 함께 삭제됩니다.');
|
||||
}
|
||||
$this->newLine();
|
||||
|
||||
if (! $this->confirm(__('modules.commands.uninstall.confirm_question'), false)) {
|
||||
$this->info(__('modules.commands.uninstall.aborted'));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
// 모듈 제거
|
||||
$deleteData = $this->option('delete-data');
|
||||
$onProgress = $this->createProgressCallback(ModuleManager::UNINSTALL_STEPS);
|
||||
try {
|
||||
$result = $this->moduleManager->uninstallModule($identifier, $deleteData, $onProgress);
|
||||
$this->finishProgress();
|
||||
} catch (\Exception $e) {
|
||||
$this->finishProgress();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$this->info('✅ '.__('modules.commands.uninstall.success', ['module' => $identifier]));
|
||||
$this->info(' - '.__('modules.commands.uninstall.roles_deleted', ['count' => $rolesCount]));
|
||||
$this->info(' - '.__('modules.commands.uninstall.permissions_deleted', ['count' => $permissionsCount]));
|
||||
$this->info(' - '.__('modules.commands.uninstall.menus_deleted', ['count' => $menusCount]));
|
||||
$this->info(' - '.__('modules.commands.uninstall.layouts_deleted', ['count' => $layoutsCount]));
|
||||
Log::info(__('modules.commands.uninstall.success', ['module' => $identifier]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
return Command::FAILURE;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
Log::error('모듈 제거 실패', [
|
||||
'module' => $identifier,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Console\Commands\Traits\HasProgressBar;
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Extension\ModuleManager;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateModuleCommand extends Command
|
||||
{
|
||||
use HasProgressBar;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'module:update
|
||||
{identifier : 업데이트할 모듈 식별자}
|
||||
{--force : 버전 비교 없이 강제 업데이트}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = '모듈을 최신 버전으로 업데이트합니다';
|
||||
|
||||
/**
|
||||
* 모듈 관리자 및 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$identifier = $this->argument('identifier');
|
||||
$force = $this->option('force');
|
||||
|
||||
try {
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
// 모듈 존재 확인
|
||||
$module = $this->moduleRepository->findByIdentifier($identifier);
|
||||
|
||||
if (! $module) {
|
||||
$this->error('❌ '.__('modules.commands.update.not_installed', ['module' => $identifier]));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// 업데이트 확인
|
||||
$checkResult = $this->moduleManager->checkModuleUpdate($identifier);
|
||||
|
||||
if (! $checkResult['update_available'] && ! $force) {
|
||||
$this->info('✅ '.__('modules.commands.update.no_update', ['module' => $identifier]));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 업데이트 정보 표시
|
||||
$this->info(__('modules.commands.update.current_version', ['version' => $checkResult['current_version']]));
|
||||
|
||||
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']]));
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
|
||||
// 확인 프롬프트 (--force 시 건너뜀)
|
||||
if (! $force && ! $this->confirm(__('modules.commands.update.confirm_question'), false)) {
|
||||
$this->info(__('modules.commands.update.aborted'));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 업데이트 실행
|
||||
$onProgress = $this->createProgressCallback(ModuleManager::UPDATE_STEPS);
|
||||
try {
|
||||
$updateResult = $this->moduleManager->updateModule($identifier, $force, $onProgress);
|
||||
$this->finishProgress();
|
||||
} catch (\Exception $e) {
|
||||
$this->finishProgress();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($updateResult['success']) {
|
||||
$this->newLine();
|
||||
$this->info('✅ '.__('modules.commands.update.success', ['module' => $identifier]));
|
||||
$this->info(' '.__('modules.commands.update.version_change', [
|
||||
'from' => $updateResult['from_version'],
|
||||
'to' => $updateResult['to_version'],
|
||||
]));
|
||||
|
||||
Log::info('모듈 업데이트 완료', [
|
||||
'module' => $identifier,
|
||||
'from' => $updateResult['from_version'],
|
||||
'to' => $updateResult['to_version'],
|
||||
]);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
return Command::FAILURE;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('❌ '.$e->getMessage());
|
||||
$this->warn('💡 '.__('modules.commands.update.backup_restored'));
|
||||
|
||||
Log::error('모듈 업데이트 실패', [
|
||||
'module' => $identifier,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user