FEATURE: use module_settings field instaed of config().
This way should be more reliable, because config() is available only after publishing module, however I can't publish module when it does not have config (module.json). In this way I can select all modules from database and generate module.json for each of them.
This commit is contained in:
@@ -43,16 +43,31 @@ class ModuleManager extends ServiceProvider
|
||||
*/
|
||||
private function createModulesJson(Module $module)
|
||||
{
|
||||
$data = config($module->alias);
|
||||
$data['active'] = $module->enabled;
|
||||
$config = json_decode($module->module_settings);
|
||||
|
||||
if (is_null($config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// path to module.json
|
||||
$path = config('modules.paths.modules') . DIRECTORY_SEPARATOR . $data['name'] . DIRECTORY_SEPARATOR . 'module.json';
|
||||
$path = config('modules.paths.modules') . DIRECTORY_SEPARATOR . $config->staticName . DIRECTORY_SEPARATOR . 'module.json';
|
||||
|
||||
// check if module config is writable
|
||||
if (!is_writable($path)) {
|
||||
throw new \ErrorException('Cannot write to ' . $path . '. Module ' . $data['name'] . ' cannot be enabled.');
|
||||
return;
|
||||
}
|
||||
|
||||
// set enabled/disabled status for this module
|
||||
$data = new \stdClass();
|
||||
$data->name = $config->staticName;
|
||||
$data->description = $module->description;
|
||||
$data->alias = $module->alias;
|
||||
$data->providers = $config->providers;
|
||||
$data->aliases = $config->aliases;
|
||||
$data->order = $config->order;
|
||||
$data->files = $config->files;
|
||||
$data->active = $module->enabled;
|
||||
|
||||
// create file
|
||||
file_put_contents($path, json_encode($data));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user