v7.0.0 release

This commit is contained in:
HeuJung committed 2026-07-01 10:30:32 +09:00
1 parent 0e7fa04b03
commit c4ea9a6cd1
3582 files changed
+626189 -160151

No files matched your search

+13 -2
View File
@@ -33,9 +33,20 @@ class CoreBackupHelper
public static function createBackup(array $targets, ?\Closure $onProgress = null, array $excludes = []): string
{
$timestamp = date('Ymd_His');
$backupPath = storage_path("app/core_backups/core_{$timestamp}");
$backupRoot = storage_path('app/core_backups');
$backupPath = $backupRoot.DIRECTORY_SEPARATOR."core_{$timestamp}";
File::ensureDirectoryExists($backupPath, 0770, true);
// 백업 루트(core_backups)를 php-fpm 그룹이 쓸 수 있도록 보장한 뒤 타임스탬프
// 디렉토리를 만든다. sudo 업데이트가 core_backups 를 root/운영자 소유 + g-w(0755)
// 로 만들어 두면 이후 www-data 가 그 안에 mkdir 하지 못해 백업 생성이 실패한다
// (mkdir(): Permission denied). 루트를 g+w(0775) 로 정상화하고 소유권을 부모에서
// 상속한다(소유자 아님 → chmod 불가 환경은 silent no-op, 멱등).
File::ensureDirectoryExists($backupRoot, 0775);
FilePermissionHelper::inheritOwnershipFromParent($backupRoot);
FilePermissionHelper::syncGroupWritability($backupRoot);
File::ensureDirectoryExists($backupPath, 0775, true);
FilePermissionHelper::inheritOwnershipFromParent($backupPath);
foreach ($targets as $target) {
$sourcePath = base_path($target);
@@ -0,0 +1,106 @@
<?php
namespace App\Extension\Helpers;
use Illuminate\Support\Facades\Log;
/**
* editor-spec.json 합본 헬퍼.
*
* editor-spec.json 이 과대해져(admin 18k 줄) 상위 블록 단위로 분할되었다. 분할
* 형식은 manifest(`editor-spec.json`)에 메타 + 소형 블록을 인라인으로 두고, 대형
* 블록은 `$include` 맵으로 `editor-spec/{block}.json` 을 참조하는 구조다.
*
* 서빙 4개 사이트는 활성 디렉토리만 기준으로 합본한다 — `_bundled` 폴백은 없다
* `_bundled` 작업분은 `{module,plugin,template}:update` 로 활성 디렉토리에
* 반영된 뒤에만 런타임에 보인다. 다음 형태의 manifest 를 받는다:
*
* {
* "templateId": "...", "version": "...", "darkMode": { ... },
* "$include": {
* "componentPalette": "editor-spec/componentPalette.json",
* "controls": "editor-spec/controls.json"
* }
* }
*
* 본 헬퍼는 manifest 의 `$include` 를 manifest 디렉토리 기준으로 해석해 단일
* 병합 spec(top-level merge)으로 합본한다. 런타임 API 응답은 분할 전 단일 파일과
* 동일한 형태(`array<string,mixed>`)를 유지하므로 프론트엔드 로더는 무영향이다.
*
* `$include` 가 없는 구버전/미분할 editor-spec.json 은 manifest 원본을 그대로
* 반환한다(하위 호환). include 파일 미존재/파싱 실패 시 해당 키만 누락하고 경고를
* 남긴다(무손실 디그레이드).
*
*/
class EditorSpecAssembler
{
/**
* manifest 파일을 디코드하고 `$include` 블록을 합본한 단일 spec 을 반환합니다.
*
* `$include` 부재 시 manifest 원본을 그대로 반환합니다(하위 호환). include 경로는
* manifest 가 위치한 디렉토리 기준 상대 경로로 해석합니다.
*
* @param string $manifestPath editor-spec.json manifest 의 절대 경로
* @return array<string, mixed>|null 합본 spec, 디코드 실패 시 null
*/
public static function assemble(string $manifestPath): ?array
{
$manifest = self::decodeJsonFile($manifestPath);
if ($manifest === null) {
return null;
}
$includes = $manifest['$include'] ?? null;
unset($manifest['$include']);
if (! is_array($includes) || $includes === []) {
// 미분할(구버전) editor-spec.json — manifest 원본 그대로 반환.
return $manifest;
}
$baseDir = \dirname($manifestPath);
foreach ($includes as $key => $relative) {
if (! is_string($key) || ! is_string($relative) || $relative === '') {
continue;
}
$blockPath = $baseDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $relative);
$block = self::decodeJsonFile($blockPath);
if ($block === null) {
// include 파일 미존재/파싱 실패 — 해당 키 누락(무손실 디그레이드) + 경고.
Log::warning('EditorSpecAssembler: include 블록 로드 실패', [
'manifest' => $manifestPath,
'block' => $key,
'path' => $blockPath,
]);
continue;
}
// top-level merge — include 결과가 해당 key 의 값이 된다.
// manifest 인라인 값이 있으면 include 가 덮어쓴다(분할본이 정본).
$manifest[$key] = $block;
}
return $manifest;
}
/**
* JSON 파일을 읽어 배열로 디코드합니다. 미존재/비배열/파싱 실패 시 null.
*
* @param string $path 절대 경로
* @return array<string, mixed>|null 디코드된 배열, 실패 시 null
*/
private static function decodeJsonFile(string $path): ?array
{
if (! file_exists($path) || ! is_file($path)) {
return null;
}
$decoded = json_decode((string) file_get_contents($path), true);
return is_array($decoded) ? $decoded : null;
}
}
@@ -33,9 +33,22 @@ class ExtensionBackupHelper
}
$timestamp = date('Ymd_His');
$backupRoot = storage_path('app/extension_backups');
$backupTypeDir = storage_path("app/extension_backups/{$type}");
$backupPath = storage_path("app/extension_backups/{$type}/{$identifier}_{$timestamp}");
File::ensureDirectoryExists(dirname($backupPath));
// 백업 부모 체인(extension_backups → {type})을 php-fpm 그룹이 쓸 수 있도록 보장한다.
//
// sudo 업데이트가 이 디렉토리들을 root/운영자 소유 + g-w(0755) 로 만들어 두면, 이후
// www-data(php-fpm) 가 그 안에 백업 디렉토리를 mkdir 하지 못해 "mkdir(): Permission
// denied" 로 실패한다(백업 생성 단계 중단). 디렉토리를 g+w(0775) 로 생성하고, 이미
// 존재하면 부모 소유권 상속 + g+w 승격으로 정상화한다. 소유자가 아니라 chmod 가
// 불가한 환경에서는 silent no-op(멱등) — 운영자가 디렉토리 권한을 직접 부여한다.
foreach ([$backupRoot, $backupTypeDir] as $dir) {
File::ensureDirectoryExists($dir, 0775);
FilePermissionHelper::inheritOwnershipFromParent($dir);
FilePermissionHelper::syncGroupWritability($dir);
}
// 파일별 복사로 진행 상세 보고
self::copyDirectoryWithProgress($sourcePath, $backupPath, $sourcePath, $onProgress);
@@ -58,6 +71,8 @@ class ExtensionBackupHelper
?\Closure $onProgress = null
): void {
File::ensureDirectoryExists($dest, 0775);
// 백업 디렉토리 트리도 부모 소유권을 상속해 sudo update 후 root 소유 잔존을 차단한다.
FilePermissionHelper::inheritOwnershipFromParent($dest);
$items = new \FilesystemIterator($source, \FilesystemIterator::SKIP_DOTS);
foreach ($items as $item) {
@@ -126,7 +126,17 @@ class ExtensionMenuSyncHelper
$updateData['url'] = $newAttributes['url'] ?? null;
}
$this->menuRepository->update($existing, $updateData);
// user_overrides 자동 마킹 비활성화 — 시스템 sync 컨텍스트는 사용자 변경이 아님.
// HasUserOverrides::bootHasUserOverrides 의 updating 이벤트 hook 이 'seeding' 플래그를
// 보고 자동 마킹을 건너뛴다. 미설정 시 동일한 module.php 정의값을 적용해도 icon/name/order
// 등 trackable 필드가 dirty 로 잡혀 user_overrides 에 자동 추가되어, 이후 sync 가 차단되는
// 결함이 발생한다.
app()->instance('user_overrides.seeding', true);
try {
$this->menuRepository->update($existing, $updateData);
} finally {
app()->forgetInstance('user_overrides.seeding');
}
return $existing->fresh();
}
@@ -87,7 +87,17 @@ class ExtensionRoleSyncHelper
// 기타 속성 병합
$updateData = array_merge($updateData, $otherAttributes);
$this->roleRepository->update($existing, $updateData);
// user_overrides 자동 마킹 비활성화 — 시스템 sync 컨텍스트는 사용자 변경이 아님.
// ExtensionMenuSyncHelper 와 동일 패턴 (HasUserOverrides::bootHasUserOverrides 의
// updating 이벤트 hook 이 'seeding' 플래그를 보고 자동 마킹을 건너뛴다).
// 미설정 시 동일한 정의값을 적용해도 name/description 등 trackable 필드가 dirty 로
// 잡혀 user_overrides 에 자동 추가되어 이후 sync 가 차단되는 결함이 발생한다.
app()->instance('user_overrides.seeding', true);
try {
$this->roleRepository->update($existing, $updateData);
} finally {
app()->forgetInstance('user_overrides.seeding');
}
return $existing->fresh();
}
+43 -35
View File
@@ -16,20 +16,24 @@ class FilePermissionHelper
* - 신규 파일: 부모 디렉토리의 소유자/그룹 상속 (퍼미션은 PHP 기본 umask)
* - removeOrphans=false: 소스에 없고 대상에만 있는 파일 유지 (사용자 추가 파일 보호)
* - removeOrphans=true: 소스에 없고 대상에만 있는 파일/디렉토리 삭제 (excludes 제외)
* - preserveTopLevelOrphans=true: removeOrphans=true 라도 *최상위 한 레벨* 에서 소스에
* 없는 항목(디렉토리/파일)은 삭제하지 않는다. 소스에 존재하는 디렉토리 내부의
* orphan 정리는 그대로 수행된다. 코어 업데이트가 `{domain}/_bundled` 를 sync 할 때
* 사용자가 `_bundled/` 바로 아래에 직접 만든 커스텀 확장 디렉토리를 보존하기 위함.
*
* 신규 항목의 소유권 상속은 sudo 로 실행된 업데이트 프로세스가 root 소유로 파일을
* 생성하는 것을 방지한다. vendor/ 처럼 cleanDirectory 후 재생성되는 디렉토리 구조
* 전체가 기존 부모(= vendor/) 의 소유권을 승계하도록 보장한다.
*
* @param string $source 소스 디렉토리 경로
* @param string $destination 대상 디렉토리 경로
* @param \Closure|null $onProgress 진행 콜백
* @param array $excludes 제외할 이름 또는 경로 목록 (예: ['node_modules', '.git', 'node_modules/test_dir'])
* @param string $relativePath 현재 상대 경로 (내부 재귀용)
* @param bool $removeOrphans 소스에 없는 대상 파일/디렉토리 삭제 여부
* @return void
* @param string $source 소스 디렉토리 경로
* @param string $destination 대상 디렉토리 경로
* @param \Closure|null $onProgress 진행 콜백
* @param array $excludes 제외할 이름 또는 경로 목록 (예: ['node_modules', '.git', 'node_modules/test_dir'])
* @param string $relativePath 현재 상대 경로 (내부 재귀용)
* @param bool $removeOrphans 소스에 없는 대상 파일/디렉토리 삭제 여부
* @param bool $preserveTopLevelOrphans 최상위 한 레벨의 orphan 보존 여부
*/
public static function copyDirectory(string $source, string $destination, ?\Closure $onProgress = null, array $excludes = [], string $relativePath = '', bool $removeOrphans = false): void
public static function copyDirectory(string $source, string $destination, ?\Closure $onProgress = null, array $excludes = [], string $relativePath = '', bool $removeOrphans = false, bool $preserveTopLevelOrphans = false): void
{
if (! File::isDirectory($destination)) {
// 신규 디렉토리: 부모 디렉토리의 퍼미션/소유권 상속
@@ -61,7 +65,8 @@ class FilePermissionHelper
}
if ($item->isDir()) {
static::copyDirectory($item->getPathname(), $destPath, $onProgress, $excludes, $itemRelativePath, $removeOrphans);
// preserveTopLevelOrphans 는 최상위 한 레벨 한정 — 자식 재귀에는 항상 false 전달.
static::copyDirectory($item->getPathname(), $destPath, $onProgress, $excludes, $itemRelativePath, $removeOrphans, preserveTopLevelOrphans: false);
} else {
static::copyFile($item->getPathname(), $destPath);
}
@@ -69,7 +74,7 @@ class FilePermissionHelper
// 소스에 없는 대상 파일/디렉토리 삭제
if ($removeOrphans && File::isDirectory($destination)) {
static::removeOrphanItems($source, $destination, $excludes, $relativePath);
static::removeOrphanItems($source, $destination, $excludes, $relativePath, $preserveTopLevelOrphans);
}
}
@@ -86,7 +91,7 @@ class FilePermissionHelper
*
* @param string $source 소스 symlink 경로
* @param string $destination 대상 symlink 경로
* @return bool symlink 복원 성공 여부 (false 면 호출자가 일반 복사로 폴백)
* @return bool symlink 복원 성공 여부 (false 면 호출자가 일반 복사로 폴백)
*/
protected static function copySymlink(string $source, string $destination): bool
{
@@ -122,14 +127,21 @@ class FilePermissionHelper
*
* excludes 목록에 해당하는 항목은 삭제하지 않습니다.
*
* @param string $source 소스 디렉토리 경로
* @param string $destination 대상 디렉토리 경로
* @param array $excludes 제외할 이름 또는 경로 목록
* @param string $relativePath 현재 상대 경로
* @return void
* @param string $source 소스 디렉토리 경로
* @param string $destination 대상 디렉토리 경로
* @param array $excludes 제외할 이름 또는 경로 목록
* @param string $relativePath 현재 상대 경로
* @param bool $preserveTopLevelOrphans 최상위 한 레벨의 orphan 보존 여부
*/
protected static function removeOrphanItems(string $source, string $destination, array $excludes, string $relativePath): void
protected static function removeOrphanItems(string $source, string $destination, array $excludes, string $relativePath, bool $preserveTopLevelOrphans = false): void
{
// 최상위 한 레벨에서 소스에 없는 항목(사용자 추가) 보존 — `_bundled/my-project` 등.
// 호출자(copyDirectory)는 최상위 진입 시에만 relativePath='' + 플래그 true 로 들어오며,
// 자식 재귀에는 항상 false 가 전달되므로 본 분기는 최상위에서만 활성화된다.
if ($preserveTopLevelOrphans && $relativePath === '') {
return;
}
$destItems = new \FilesystemIterator($destination, \FilesystemIterator::SKIP_DOTS);
foreach ($destItems as $destItem) {
@@ -165,9 +177,9 @@ class FilePermissionHelper
* - 단순 이름 (슬래시 미포함): 모든 레벨에서 해당 이름과 매칭
* - 경로 패턴 (슬래시 포함): 상대 경로와 정확히 매칭
*
* @param string $itemName 현재 항목의 파일/디렉토리 이름
* @param string $itemRelativePath 루트로부터의 상대 경로
* @param array $excludes 제외 목록
* @param string $itemName 현재 항목의 파일/디렉토리 이름
* @param string $itemRelativePath 루트로부터의 상대 경로
* @param array $excludes 제외 목록
* @return bool 제외 대상 여부
*/
public static function isExcluded(string $itemName, string $itemRelativePath, array $excludes): bool
@@ -199,9 +211,8 @@ class FilePermissionHelper
* 파일을 생성하는 문제를 방지하기 위함이다. vendor/ 내부처럼 cleanDirectory 후
* 전량 재생성되는 경로에서 필요하다.
*
* @param string $source 소스 파일
* @param string $destination 대상 파일
* @return void
* @param string $source 소스 파일
* @param string $destination 대상 파일
*/
public static function copyFile(string $source, string $destination): void
{
@@ -239,8 +250,7 @@ class FilePermissionHelper
/**
* 부모 디렉토리의 퍼미션·소유자·그룹을 상속하여 신규 디렉토리를 생성합니다.
*
* @param string $path 생성할 디렉토리 경로
* @return void
* @param string $path 생성할 디렉토리 경로
*/
protected static function createDirectoryInheritingParent(string $path): void
{
@@ -262,7 +272,6 @@ class FilePermissionHelper
* 외부 호출처(예: `SettingsMigrator::writeJsonFile`) 가 직접 호출 가능하도록 public.
*
* @param string $path 소유권을 상속받을 파일 또는 디렉토리
* @return void
*/
public static function inheritOwnershipFromParent(string $path): void
{
@@ -277,10 +286,9 @@ class FilePermissionHelper
/**
* 소유자·그룹을 적용합니다. sudo 없이 실행 시 silent fail 로 현행 동작 유지.
*
* @param string $path 대상 경로
* @param int|false $owner fileowner() 반환값 (false 허용)
* @param int|false $group filegroup() 반환값 (false 허용)
* @return void
* @param string $path 대상 경로
* @param int|false $owner fileowner() 반환값 (false 허용)
* @param int|false $group filegroup() 반환값 (false 허용)
*/
protected static function applyOwnership(string $path, int|false $owner, int|false $group): void
{
@@ -303,7 +311,7 @@ class FilePermissionHelper
* - sudo 실행된 업데이트가 원본 스냅샷을 수집하지 못한 경우의 fallback
* - 외부 프로세스(composer 등) 가 root 로 오염시킨 경로의 원본 추정
*
* @return array{0: int|false, 1: int|false, 2: string} [owner, group, source]
* @return array{0: int|false, 1: int|false, 2: string} [owner, group, source]
*/
public static function inferWebServerOwnership(): array
{
@@ -345,9 +353,9 @@ class FilePermissionHelper
* 처리하고 대상은 따라가지 않는다. @chown/@chgrp suppress 로 권한 부족 / chown 미지원
* 환경에서도 silent fail.
*
* @param string $path 대상 경로 (파일 또는 디렉토리)
* @param int $owner 기준 소유자 UID
* @param int|false $group 기준 그룹 GID (false = 그룹 유지)
* @param string $path 대상 경로 (파일 또는 디렉토리)
* @param int $owner 기준 소유자 UID
* @param int|false $group 기준 그룹 GID (false = 그룹 유지)
* @return int 실제 소유권을 변경한 항목 수
*/
public static function chownRecursive(string $path, int $owner, int|false $group): int
@@ -421,7 +429,7 @@ class FilePermissionHelper
* - silent fail — 권한 부족·chmod 미지원 환경에서도 예외 미발생
*
* @param string $root 대상 루트 (재귀 순회)
* @return int 실제 chmod 한 항목 수
* @return int 실제 chmod 한 항목 수
*/
public static function syncGroupWritability(string $root): int
{
@@ -2,6 +2,8 @@
namespace App\Extension\Helpers;
use App\Contracts\Repositories\IdentityPolicyRepositoryInterface;
use App\Listeners\Identity\EnforceIdentityPolicyListener;
use App\Models\IdentityPolicy;
use Illuminate\Support\Facades\Log;
@@ -18,6 +20,13 @@ use Illuminate\Support\Facades\Log;
*/
class IdentityPolicySyncHelper
{
/**
* @param IdentityPolicyRepositoryInterface $repository 정책 데이터 접근 Repository
*/
public function __construct(
protected IdentityPolicyRepositoryInterface $repository,
) {}
/**
* 정책을 동기화합니다 (user_overrides 보존 upsert).
*
@@ -29,7 +38,7 @@ class IdentityPolicySyncHelper
*/
public function syncPolicy(array $data): IdentityPolicy
{
return IdentityPolicy::syncOrCreateFromUpgrade(
$policy = IdentityPolicy::syncOrCreateFromUpgrade(
['key' => $data['key']],
[
'scope' => $data['scope'] ?? 'route',
@@ -46,6 +55,15 @@ class IdentityPolicySyncHelper
'fail_mode' => $data['fail_mode'] ?? 'block',
]
);
// scope=hook 정책이 새로 적재되면 그 target 에 enforce 구독을 멱등 (재)바인딩한다.
// 코어 리스너 자동발견은 부팅 전반부에 1회만 일어나 그 시점에 없던 모듈 hook target 을
// 놓치므로, 정책이 DB 에 적재되는 이 시점에 보충한다(이미 바인딩된 target 은 멱등 스킵).
if (($policy->scope instanceof \BackedEnum ? $policy->scope->value : $policy->scope) === 'hook') {
EnforceIdentityPolicyListener::syncDynamicHookSubscriptions();
}
return $policy;
}
/**
@@ -63,16 +81,9 @@ class IdentityPolicySyncHelper
string $sourceIdentifier,
array $currentKeys,
): int {
$query = IdentityPolicy::query()
->where('source_type', $sourceType)
->where('source_identifier', $sourceIdentifier);
if (! empty($currentKeys)) {
$query->whereNotIn('key', $currentKeys);
}
$targets = $query->get(['id', 'key']);
$targets = $this->repository->findStale($sourceType, $sourceIdentifier, $currentKeys);
foreach ($targets as $policy) {
// per-model delete — deleted 이벤트로 라우트 스코프 캐시가 flush 된다(bulk delete 와 차이).
$policy->delete();
}