Merge branch 'master' of https://git.itguild.info/ItGuild/igmf
This commit is contained in:
commit
b1dacff877
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace kernel\app_themes\custom\services;
|
namespace kernel\app_themes\custom\services;
|
||||||
|
|
||||||
class CustomService
|
class CustomThemeService
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
@ -86,11 +86,40 @@ class ThemeService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->runDeactivateScript($this->getActiveThemeInfo());
|
||||||
|
$this->runInitScript($themeInfo);
|
||||||
|
|
||||||
$activeTheme->value = getConst($theme);
|
$activeTheme->value = getConst($theme);
|
||||||
$activeTheme->save();
|
$activeTheme->save();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function runInitScript($themeInfo): void
|
||||||
|
{
|
||||||
|
if (isset($themeInfo['theme_class'])) {
|
||||||
|
if (isset($themeInfo['theme_class_file'])) {
|
||||||
|
require_once $themeInfo['theme_class_file'];
|
||||||
|
}
|
||||||
|
$themeClass = new $themeInfo['theme_class']();
|
||||||
|
$themeClass->init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $themeInfo
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function runDeactivateScript($themeInfo): void
|
||||||
|
{
|
||||||
|
if (isset($themeInfo['theme_class'])) {
|
||||||
|
if (isset($themeInfo['theme_class_file'])) {
|
||||||
|
require_once $themeInfo['theme_class_file'];
|
||||||
|
}
|
||||||
|
$themeClass = new $themeInfo['theme_class']();
|
||||||
|
$themeClass->deactivate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getActiveThemeInfo(): false|array|string
|
public function getActiveThemeInfo(): false|array|string
|
||||||
{
|
{
|
||||||
return $this->getThemeInfo($this->active_theme);
|
return $this->getThemeInfo($this->active_theme);
|
||||||
@ -179,7 +208,8 @@ class ThemeService
|
|||||||
$tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $themeName . "/";
|
$tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $themeName . "/";
|
||||||
|
|
||||||
$fileHelper = new Files();
|
$fileHelper = new Files();
|
||||||
$fileHelper->copy_folder(ROOT_DIR . $path, $tmpThemeDirFull . 'meta/');
|
$fileHelper->copy_folder(ROOT_DIR . $path, $tmpThemeDirFull . 'meta/app/');
|
||||||
|
$fileHelper->copy_folder(KERNEL_DIR . '/app_themes/' . $themeName, $tmpThemeDirFull . 'meta/kernel/');
|
||||||
$fileHelper->copy_folder(RESOURCES_DIR . '/themes/' . $themeName, $tmpThemeDirFull . 'resources/');
|
$fileHelper->copy_folder(RESOURCES_DIR . '/themes/' . $themeName, $tmpThemeDirFull . 'resources/');
|
||||||
|
|
||||||
if (!is_dir(RESOURCES_DIR . '/tmp/themes')) {
|
if (!is_dir(RESOURCES_DIR . '/tmp/themes')) {
|
||||||
@ -213,10 +243,16 @@ class ThemeService
|
|||||||
$manifest = Manifest::getWithVars($manifestJson);
|
$manifest = Manifest::getWithVars($manifestJson);
|
||||||
|
|
||||||
$fileHelper = new Files();
|
$fileHelper = new Files();
|
||||||
if (isset($manifest['theme_path'])) {
|
if (isset($manifest['theme_app_path'])) {
|
||||||
$fileHelper->copy_folder($tmpThemeDirFull . "meta", $manifest['theme_path']);
|
$fileHelper->copy_folder($tmpThemeDirFull . "meta/app", $manifest['theme_app_path']);
|
||||||
} else {
|
} else {
|
||||||
$fileHelper->copy_folder($tmpThemeDirFull . "meta", APP_DIR . '/themes/' . $manifest['slug']);
|
$fileHelper->copy_folder($tmpThemeDirFull . "meta/app", APP_DIR . '/themes/' . $manifest['slug']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($manifest['theme_kernel_path'])) {
|
||||||
|
$fileHelper->copy_folder($tmpThemeDirFull . "meta/kernel", $manifest['theme_app_path']);
|
||||||
|
} else {
|
||||||
|
$fileHelper->copy_folder($tmpThemeDirFull . "meta/kernel", APP_DIR . '/themes/' . $manifest['slug']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($manifest['resource_path'])) {
|
if (isset($manifest['resource_path'])) {
|
||||||
@ -242,6 +278,9 @@ class ThemeService
|
|||||||
if (file_exists($path)) {
|
if (file_exists($path)) {
|
||||||
$fileHelper->recursiveRemoveDir($path);
|
$fileHelper->recursiveRemoveDir($path);
|
||||||
}
|
}
|
||||||
|
if (file_exists(KERNEL_DIR . '/app_themes/' . $themeInfo['slug'])) {
|
||||||
|
$fileHelper->recursiveRemoveDir(KERNEL_DIR . '/app_themes/' . $themeInfo['slug']);
|
||||||
|
}
|
||||||
if (file_exists(RESOURCES_DIR . '/themes/' . $themeInfo['slug'])) {
|
if (file_exists(RESOURCES_DIR . '/themes/' . $themeInfo['slug'])) {
|
||||||
$fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/themes/' . $themeInfo['slug']);
|
$fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/themes/' . $themeInfo['slug']);
|
||||||
}
|
}
|
||||||
@ -249,11 +288,36 @@ class ThemeService
|
|||||||
|
|
||||||
public function update(string $path): bool
|
public function update(string $path): bool
|
||||||
{
|
{
|
||||||
if ($this->install($path)) {
|
$zip = new ZipArchive;
|
||||||
return true;
|
$tmpThemeDir = md5(time());
|
||||||
|
$res = $zip->open(ROOT_DIR . $path);
|
||||||
|
if ($res === TRUE) {
|
||||||
|
$tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpThemeDir . "/";
|
||||||
|
$zip->extractTo($tmpThemeDirFull);
|
||||||
|
$zip->close();
|
||||||
|
} else {
|
||||||
|
$this->addError('unable to open zip archive');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if (!file_exists($tmpThemeDirFull . "meta/manifest.json")){
|
||||||
|
$this->addError('manifest.json not found');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$manifestJson = getConst(file_get_contents($tmpThemeDirFull . "meta/manifest.json"));
|
||||||
|
$manifest = Manifest::getWithVars($manifestJson);
|
||||||
|
|
||||||
|
$fileHelper = new Files();
|
||||||
|
if (isset($manifest['theme_kernel_path'])) {
|
||||||
|
$fileHelper->copy_folder($tmpThemeDirFull . "meta/kernel", $manifest['theme_app_path']);
|
||||||
|
} else {
|
||||||
|
$fileHelper->copy_folder($tmpThemeDirFull . "meta/kernel", APP_DIR . '/themes/' . $manifest['slug']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileHelper->recursiveRemoveDir($tmpThemeDirFull);
|
||||||
|
unlink(ROOT_DIR . $path);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getThemeRout(string $path)
|
public function getThemeRout(string $path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user