/** * Disables a module * * @since 1.1 * @param \humhub\components\Module $module */ public function disable(Module $module) { $moduleEnabled = ModuleEnabled::findOne(['module_id' => $module->id]); if ($moduleEnabled != null) { $moduleEnabled->delete(); } if (($key = array_search($module->id, $this->enabledModules)) !== false) { unset($this->enabledModules[$key]); } Yii::$app->setModule($module->id, 'null'); }
/** * Disables a module * * This should delete all data created by this module. * When override this method make sure to invoke the parent implementation AFTER your implementation. */ public function disable() { // Is not enabled if (!Yii::$app->hasModule($this->id)) { return; } // Disable module in database $moduleEnabled = ModuleEnabled::findOne(['module_id' => $this->id]); if ($moduleEnabled != null) { $moduleEnabled->delete(); } /** * Remove database tables */ $migrationPath = $this->getBasePath() . '/migrations'; $uninstallMigration = $migrationPath . '/uninstall.php'; if (file_exists($uninstallMigration)) { /** * Execute Uninstall Migration */ ob_start(); require_once $uninstallMigration; $migration = new \uninstall(); try { $migration->up(); } catch (\yii\db\Exception $ex) { } ob_get_clean(); /** * Delete all Migration Table Entries */ $migrations = opendir($migrationPath); while (false !== ($migration = readdir($migrations))) { if ($migration == '.' || $migration == '..' || $migration == 'uninstall.php') { continue; } Yii::$app->db->createCommand()->delete('migration', ['version' => str_replace('.php', '', $migration)])->execute(); } } /* HSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId())); SpaceSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId())); UserSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId())); // Delete also records with disabled state from SpaceApplicationModule Table foreach (SpaceApplicationModule::model()->findAllByAttributes(array('module_id' => $this->getId())) as $sam) { $sam->delete(); } // Delete also records with disabled state from UserApplicationModule Table foreach (UserApplicationModule::model()->findAllByAttributes(array('module_id' => $this->getId())) as $uam) { $uam->delete(); } ModuleManager::flushCache(); */ }