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,9 +2,12 @@
|
||||
|
||||
namespace App\Extension\Traits;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\Cache\CoreCacheDriver;
|
||||
use App\Models\Module;
|
||||
use App\Services\CacheService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* 모듈 상태 캐시를 관리하는 Trait
|
||||
@@ -14,11 +17,6 @@ use App\Services\CacheService;
|
||||
*/
|
||||
trait CachesModuleStatus
|
||||
{
|
||||
/**
|
||||
* 캐시 그룹
|
||||
*/
|
||||
private static string $cacheGroup = 'modules';
|
||||
|
||||
/**
|
||||
* 활성화된 모듈 identifier 목록을 조회합니다.
|
||||
*
|
||||
@@ -26,14 +24,17 @@ trait CachesModuleStatus
|
||||
*/
|
||||
public static function getActiveModuleIdentifiers(): array
|
||||
{
|
||||
return CacheService::remember(
|
||||
self::$cacheGroup,
|
||||
'active_identifiers',
|
||||
if (! self::isExtensionTableReady('modules')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::resolveStatusCache()->remember(
|
||||
'ext.modules.active_identifiers',
|
||||
fn () => Module::where('status', ExtensionStatus::Active->value)
|
||||
->pluck('identifier')
|
||||
->toArray(),
|
||||
null,
|
||||
'modules'
|
||||
(int) g7_core_settings('cache.extension_status_ttl', 86400),
|
||||
['ext.status', 'ext.modules']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,15 +45,18 @@ trait CachesModuleStatus
|
||||
*/
|
||||
public static function getInstalledModuleIdentifiers(): array
|
||||
{
|
||||
return CacheService::remember(
|
||||
self::$cacheGroup,
|
||||
'installed_identifiers',
|
||||
if (! self::isExtensionTableReady('modules')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::resolveStatusCache()->remember(
|
||||
'ext.modules.installed_identifiers',
|
||||
fn () => Module::whereIn('status', [
|
||||
ExtensionStatus::Active->value,
|
||||
ExtensionStatus::Inactive->value,
|
||||
])->pluck('identifier')->toArray(),
|
||||
null,
|
||||
'modules'
|
||||
(int) g7_core_settings('cache.extension_status_ttl', 86400),
|
||||
['ext.status', 'ext.modules']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,9 +68,42 @@ trait CachesModuleStatus
|
||||
*/
|
||||
public static function invalidateModuleStatusCache(): void
|
||||
{
|
||||
CacheService::forgetMany(self::$cacheGroup, [
|
||||
'active_identifiers',
|
||||
'installed_identifiers',
|
||||
]);
|
||||
$cache = self::resolveStatusCache();
|
||||
$cache->forget('ext.modules.active_identifiers');
|
||||
$cache->forget('ext.modules.installed_identifiers');
|
||||
}
|
||||
|
||||
/**
|
||||
* DB 연결 + 테이블 존재 여부를 확인합니다 (인스톨러 안전성).
|
||||
*
|
||||
* 설치 완료 상태(`config('app.installer_completed')`)일 때는 테이블 존재를
|
||||
* 전제로 하여 `Schema::hasTable()` 호출을 건너뜁니다. 인스톨러 이전 환경이나
|
||||
* 테스트에서는 기존 체크 경로로 폴백합니다.
|
||||
*/
|
||||
private static function isExtensionTableReady(string $table): bool
|
||||
{
|
||||
if (config('app.installer_completed')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
DB::connection()->getPdo();
|
||||
|
||||
return Schema::hasTable($table);
|
||||
} catch (\Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CacheInterface 인스턴스를 lazy 조회합니다 (register 시점 안전).
|
||||
*/
|
||||
private static function resolveStatusCache(): CacheInterface
|
||||
{
|
||||
try {
|
||||
return app(CacheInterface::class);
|
||||
} catch (\Throwable $e) {
|
||||
return new CoreCacheDriver(config('cache.default', 'array'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user