admin themes to ms

This commit is contained in:
2025-01-09 12:17:32 +03:00
parent 7489e999ef
commit 6a07e5cdde
7 changed files with 110 additions and 58 deletions

View File

@ -82,12 +82,22 @@ class AdminThemeService
return $info;
}
public function getAdminThemeInfoBySlug(string $slug)
public function getAdminThemeInfoBySlug(string $slug): false|array|string
{
// TODO
$dirs = $this->getAdminThemeDirs();
foreach ($dirs as $dir) {
foreach (new DirectoryIterator($dir) as $fileInfo) {
if ($fileInfo->isDot()) continue;
if ($this->getAdminThemeInfo($fileInfo->getPathname())['slug'] === $slug) {
return $this->getAdminThemeInfo($fileInfo->getPathname());
}
}
}
return false;
}
public function isInstall(string $slug): bool
public function getAdminThemeDirs(): array
{
$adminThemePaths = Option::where("key", "admin_theme_paths")->first();
$dirs = [];
@ -97,6 +107,12 @@ class AdminThemeService
$dirs[] = getConst($p);
}
}
return $dirs;
}
public function isInstall(string $slug): bool
{
$dirs = $this->getAdminThemeDirs();
foreach ($dirs as $dir) {
foreach (new DirectoryIterator($dir) as $fileInfo) {
if ($fileInfo->isDot()) continue;
@ -116,8 +132,7 @@ class AdminThemeService
$modulesInfo = json_decode($modulesInfo->getBody()->getContents(), true);
$themeInfo = $this->getAdminThemeInfo($slug);
// Debug::dd($themeInfo);
$themeInfo = $this->getAdminThemeInfoBySlug($slug);
foreach ($modulesInfo as $mod) {
if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) {
return true;
@ -195,11 +210,20 @@ class AdminThemeService
$this->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default');
}
$fileHelper = new Files();
if (file_exists(ROOT_DIR . $path)) {
$fileHelper->recursiveRemoveDir(ROOT_DIR . $path);
if (file_exists($path)) {
$fileHelper->recursiveRemoveDir($path);
}
if (file_exists(RESOURCES_DIR . '/' . $themeInfo['slug'])) {
$fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeInfo['slug']);
}
}
public function update(string $path): bool
{
if ($this->install($path)) {
return true;
}
return false;
}
}