modules init/deactivate, modules migrations
This commit is contained in:
@ -17,12 +17,18 @@ class ModuleService
|
||||
if (file_exists($module . "/manifest.json")) {
|
||||
$manifest = file_get_contents($module . "/manifest.json");
|
||||
$manifest = Manifest::getWithVars($manifest);
|
||||
$manifest = getConst($manifest);
|
||||
$info = array_merge($info, $manifest);
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function getModuleInfoBySlug(string $slug): false|array|string
|
||||
{
|
||||
return $this->getModuleInfo($this->getModuleDir($slug));
|
||||
}
|
||||
|
||||
public function isActive(string $slug): bool
|
||||
{
|
||||
$active_modules = Option::where("key", "active_modules")->first();
|
||||
@ -45,8 +51,10 @@ class ModuleService
|
||||
if (in_array($module, $path->modules)) {
|
||||
unset($path->modules[array_search($module, $path->modules)]);
|
||||
$path->modules = array_values($path->modules);
|
||||
$this->runDeactivateScript($this->getModuleInfoBySlug($module));
|
||||
} else {
|
||||
$path->modules[] = $module;
|
||||
$this->runInitScript($this->getModuleInfoBySlug($module));
|
||||
}
|
||||
$active_modules->value = json_encode($path, JSON_UNESCAPED_UNICODE);
|
||||
$active_modules->save();
|
||||
@ -73,6 +81,28 @@ class ModuleService
|
||||
return false;
|
||||
}
|
||||
|
||||
public function runInitScript($mod_info): void
|
||||
{
|
||||
if (isset($mod_info['module_class'])){
|
||||
if (isset($mod_info['module_class_file'])){
|
||||
require_once $mod_info['module_class_file'];
|
||||
}
|
||||
$moduleClass = new $mod_info['module_class']();
|
||||
$moduleClass->init();
|
||||
}
|
||||
}
|
||||
|
||||
public function runDeactivateScript($mod_info): void
|
||||
{
|
||||
if (isset($mod_info['module_class'])){
|
||||
if (isset($mod_info['module_class_file'])){
|
||||
require_once $mod_info['module_class_file'];
|
||||
}
|
||||
$moduleClass = new $mod_info['module_class']();
|
||||
$moduleClass->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
public function getActiveModules(): array
|
||||
{
|
||||
$modules = [];
|
||||
@ -108,4 +138,17 @@ class ModuleService
|
||||
return $routs;
|
||||
}
|
||||
|
||||
public function getModulesMigrationsPaths(): array
|
||||
{
|
||||
$migrationsPaths = [];
|
||||
$modules = $this->getActiveModules();
|
||||
foreach ($modules as $module){
|
||||
if (isset($module['migration_path'])){
|
||||
$migrationsPaths[] = $module['path'] . "/" . $module['migration_path'];
|
||||
}
|
||||
}
|
||||
|
||||
return $migrationsPaths;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user