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\Template;
|
||||
use App\Services\CacheService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* 템플릿 상태 캐시를 관리하는 Trait
|
||||
@@ -14,11 +17,6 @@ use App\Services\CacheService;
|
||||
*/
|
||||
trait CachesTemplateStatus
|
||||
{
|
||||
/**
|
||||
* 캐시 그룹
|
||||
*/
|
||||
private static string $templateCacheGroup = 'templates';
|
||||
|
||||
/**
|
||||
* 활성화된 템플릿 identifier 목록을 조회합니다.
|
||||
*
|
||||
@@ -26,14 +24,17 @@ trait CachesTemplateStatus
|
||||
*/
|
||||
public static function getActiveTemplateIdentifiers(): array
|
||||
{
|
||||
return CacheService::remember(
|
||||
self::$templateCacheGroup,
|
||||
'active_identifiers',
|
||||
if (! self::isTemplateTableReady()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::resolveTemplateStatusCache()->remember(
|
||||
'ext.templates.active_identifiers',
|
||||
fn () => Template::where('status', ExtensionStatus::Active->value)
|
||||
->pluck('identifier')
|
||||
->toArray(),
|
||||
null,
|
||||
'templates'
|
||||
(int) g7_core_settings('cache.extension_status_ttl', 86400),
|
||||
['ext.status', 'ext.templates']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -45,15 +46,18 @@ trait CachesTemplateStatus
|
||||
*/
|
||||
public static function getActiveTemplateIdentifiersByType(string $type): array
|
||||
{
|
||||
return CacheService::remember(
|
||||
self::$templateCacheGroup,
|
||||
"active_identifiers_{$type}",
|
||||
if (! self::isTemplateTableReady()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::resolveTemplateStatusCache()->remember(
|
||||
"ext.templates.active_identifiers_{$type}",
|
||||
fn () => Template::where('status', ExtensionStatus::Active->value)
|
||||
->where('type', $type)
|
||||
->pluck('identifier')
|
||||
->toArray(),
|
||||
null,
|
||||
'templates'
|
||||
(int) g7_core_settings('cache.extension_status_ttl', 86400),
|
||||
['ext.status', 'ext.templates']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,15 +68,18 @@ trait CachesTemplateStatus
|
||||
*/
|
||||
public static function getInstalledTemplateIdentifiers(): array
|
||||
{
|
||||
return CacheService::remember(
|
||||
self::$templateCacheGroup,
|
||||
'installed_identifiers',
|
||||
if (! self::isTemplateTableReady()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::resolveTemplateStatusCache()->remember(
|
||||
'ext.templates.installed_identifiers',
|
||||
fn () => Template::whereIn('status', [
|
||||
ExtensionStatus::Active->value,
|
||||
ExtensionStatus::Inactive->value,
|
||||
])->pluck('identifier')->toArray(),
|
||||
null,
|
||||
'templates'
|
||||
(int) g7_core_settings('cache.extension_status_ttl', 86400),
|
||||
['ext.status', 'ext.templates']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,11 +91,38 @@ trait CachesTemplateStatus
|
||||
*/
|
||||
public static function invalidateTemplateStatusCache(): void
|
||||
{
|
||||
CacheService::forgetMany(self::$templateCacheGroup, [
|
||||
'active_identifiers',
|
||||
'active_identifiers_admin',
|
||||
'active_identifiers_user',
|
||||
'installed_identifiers',
|
||||
]);
|
||||
$cache = self::resolveTemplateStatusCache();
|
||||
$cache->forget('ext.templates.active_identifiers');
|
||||
$cache->forget('ext.templates.active_identifiers_admin');
|
||||
$cache->forget('ext.templates.active_identifiers_user');
|
||||
$cache->forget('ext.templates.installed_identifiers');
|
||||
}
|
||||
|
||||
/**
|
||||
* 설치 완료 상태에서는 `Schema::hasTable()` 호출을 건너뜁니다.
|
||||
* 인스톨러 이전 환경이나 테스트에서는 기존 체크 경로로 폴백합니다.
|
||||
*/
|
||||
private static function isTemplateTableReady(): bool
|
||||
{
|
||||
if (config('app.installer_completed')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
DB::connection()->getPdo();
|
||||
|
||||
return Schema::hasTable('templates');
|
||||
} catch (\Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function resolveTemplateStatusCache(): CacheInterface
|
||||
{
|
||||
try {
|
||||
return app(CacheInterface::class);
|
||||
} catch (\Throwable $e) {
|
||||
return new CoreCacheDriver(config('cache.default', 'array'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user