Enh: Added humhub\components\ModuleManager::EVENT_BEFORE_MODULE_ENABLE and humhub\components\ModuleManager::EVENT_AFTER_MODULE_ENABLE events

Enh: Added `humhub\components\ModuleManager::EVENT_BEFORE_MODULE_DISABLE` and `humhub\components\ModuleManager::EVENT_AFTER_MODULE_DISABLE` events
This commit is contained in:
buddh4 2018-05-24 20:08:13 +02:00
parent 0157b88a03
commit 1e0850fafd
4 changed files with 34 additions and 13 deletions

View File

@ -60,10 +60,4 @@ class AssetManager extends \yii\web\AssetManager
$bundle->publish($this);
}
}
public function rePublish()
{
}
}

View File

@ -25,6 +25,25 @@ use humhub\models\ModuleEnabled;
*/
class ModuleManager extends Component
{
/**
* @event triggered before a module is enabled
*/
const EVENT_BEFORE_MODULE_ENABLE = 'beforeModuleEnabled';
/**
* @event triggered after a module is enabled
*/
const EVENT_AFTER_MODULE_ENABLE = 'afterModuleEnabled';
/**
* @event triggered before a module is disabled
*/
const EVENT_BEFORE_MODULE_DISABLE = 'beforeModuleDisabled';
/**
* @event triggered after a module is disabled
*/
const EVENT_AFTER_MODULE_DISABLE = 'afterModuleDisabled';
/**
* Create a backup on module folder deletion
@ -72,7 +91,7 @@ class ModuleManager extends Component
if (Yii::$app instanceof console\Application && !Yii::$app->isDatabaseInstalled()) {
$this->enabledModules = [];
} else {
$this->enabledModules = \humhub\models\ModuleEnabled::getEnabledIds();
$this->enabledModules = ModuleEnabled::getEnabledIds();
}
}
@ -320,15 +339,16 @@ class ModuleManager extends Component
*/
public function enable(Module $module)
{
$moduleEnabled = ModuleEnabled::findOne(['module_id' => $module->id]);
if ($moduleEnabled == null) {
$moduleEnabled = new ModuleEnabled();
$moduleEnabled->module_id = $module->id;
$moduleEnabled->save();
$this->trigger(static::EVENT_BEFORE_MODULE_ENABLE, new ModuleEvent(['module' => $module]));
if (!ModuleEnabled::findOne(['module_id' => $module->id])) {
(new ModuleEnabled(['module_id' => $module->id]))->save();
}
$this->enabledModules[] = $module->id;
$this->register($module->getBasePath());
$this->trigger(static::EVENT_AFTER_MODULE_ENABLE, new ModuleEvent(['module' => $module]));
}
public function enableModules($modules = [])
@ -349,6 +369,8 @@ class ModuleManager extends Component
*/
public function disable(Module $module)
{
$this->trigger(static::EVENT_BEFORE_MODULE_DISABLE, new ModuleEvent(['module' => $module]));
$moduleEnabled = ModuleEnabled::findOne(['module_id' => $module->id]);
if ($moduleEnabled != null) {
$moduleEnabled->delete();
@ -358,7 +380,9 @@ class ModuleManager extends Component
unset($this->enabledModules[$key]);
}
Yii::$app->setModule($module->id, 'null');
Yii::$app->setModule($module->id, null);
$this->trigger(static::EVENT_AFTER_MODULE_DISABLE, new ModuleEvent(['module' => $module]));
}
public function disableModules($modules = [])

View File

@ -6,6 +6,8 @@ HumHub Change Log
- Enh: Added user email to javascript user config
- Fix: Module Assets are not republished after module update
- Enh: Added `humhub\components\ModuleManager::EVENT_BEFORE_MODULE_ENABLE` and `humhub\components\ModuleManager::EVENT_AFTER_MODULE_ENABLE` events
- Enh: Added `humhub\components\ModuleManager::EVENT_BEFORE_MODULE_DISABLE` and `humhub\components\ModuleManager::EVENT_AFTER_MODULE_DISABLE` events
1.2.7 (May 23, 2018)
-----------------------

View File

@ -72,6 +72,7 @@ class ModuleController extends Controller
*/
public function actionEnable()
{
/** @var $module Module */
$this->forcePostRequest();
$moduleId = Yii::$app->request->get('moduleId');