mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 14:18:27 +01:00
Use new moduleManager in module defaults configuration
This commit is contained in:
parent
c22cc2fcaf
commit
9e2449cf39
@ -15,6 +15,8 @@ use humhub\modules\admin\libs\OnlineModuleManager;
|
||||
use humhub\modules\content\components\ContentContainerModule;
|
||||
use humhub\modules\user\models\User;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\admin\models\forms\ModuleSetAsDefaultForm;
|
||||
use humhub\modules\content\components\ContentContainerModuleManager;
|
||||
|
||||
/**
|
||||
* Module Controller controls all third party modules in a humhub installation.
|
||||
@ -300,45 +302,13 @@ class ModuleController extends Controller
|
||||
throw new HttpException(500, 'Invalid module type!');
|
||||
}
|
||||
|
||||
$model = new \humhub\modules\admin\models\forms\ModuleSetAsDefaultForm();
|
||||
|
||||
$spaceDefaultModule = null;
|
||||
if ($module->hasContentContainerType(Space::className())) {
|
||||
$spaceDefaultModule = \humhub\modules\space\models\Module::find()->where(['module_id' => $moduleId])->andWhere(['IS', 'space_id', new \yii\db\Expression('NULL')])->one();
|
||||
if ($spaceDefaultModule === null) {
|
||||
$spaceDefaultModule = new \humhub\modules\space\models\Module();
|
||||
$spaceDefaultModule->module_id = $moduleId;
|
||||
$spaceDefaultModule->state = \humhub\modules\space\models\Module::STATE_DISABLED;
|
||||
}
|
||||
$model->spaceDefaultState = $spaceDefaultModule->state;
|
||||
}
|
||||
|
||||
$userDefaultModule = null;
|
||||
if ($module->hasContentContainerType(User::className())) {
|
||||
$userDefaultModule = \humhub\modules\user\models\Module::find()->where(['module_id' => $moduleId])->andWhere(['IS', 'user_id', new \yii\db\Expression('NULL')])->one();
|
||||
if ($userDefaultModule === null) {
|
||||
$userDefaultModule = new \humhub\modules\user\models\Module();
|
||||
$userDefaultModule->module_id = $moduleId;
|
||||
$userDefaultModule->state = \humhub\modules\user\models\Module::STATE_DISABLED;
|
||||
}
|
||||
$model->userDefaultState = $userDefaultModule->state;
|
||||
}
|
||||
$model = new ModuleSetAsDefaultForm();
|
||||
$model->spaceDefaultState = ContentContainerModuleManager::getDefaultState(Space::class, $moduleId);
|
||||
$model->userDefaultState = ContentContainerModuleManager::getDefaultState(User::class, $moduleId);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||
if ($module->hasContentContainerType(Space::className())) {
|
||||
$spaceDefaultModule->state = $model->spaceDefaultState;
|
||||
if (!$spaceDefaultModule->save()) {
|
||||
throw new HttpException('Could not save: ' . print_r($spaceDefaultModule->getErrors(), 1));
|
||||
}
|
||||
}
|
||||
|
||||
if ($module->hasContentContainerType(User::className())) {
|
||||
$userDefaultModule->state = $model->userDefaultState;
|
||||
if (!$userDefaultModule->save()) {
|
||||
throw new HttpException('Could not save: ' . print_r($userDefaultModule->getErrors(), 1));
|
||||
}
|
||||
}
|
||||
|
||||
ContentContainerModuleManager::setDefaultState(User::class, $moduleId, $model->userDefaultState);
|
||||
ContentContainerModuleManager::setDefaultState(Space::class, $moduleId, $model->spaceDefaultState);
|
||||
return $this->renderModalClose();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user