public static function getEnabledIds() { $enabledModules = Yii::$app->cache->get(self::CACHE_ID_ALL_IDS); if ($enabledModules === false) { $enabledModules = []; foreach (\humhub\models\ModuleEnabled::find()->all() as $em) { $enabledModules[] = $em->module_id; } Yii::$app->cache->set(self::CACHE_ID_ALL_IDS, $enabledModules); } return $enabledModules; }
/** * Module Manager init * * Loads all enabled moduleId's from database */ public function init() { parent::init(); if (!Yii::$app->params['installed']) { return; } if (Yii::$app instanceof console\Application && !Yii::$app->isDatabaseInstalled()) { $this->enabledModules = []; } else { $this->enabledModules = \humhub\models\ModuleEnabled::getEnabledIds(); } }
/** * Updates all modules to the latest available version. * * @param array $args */ public function actionUpdateAll() { // Also install modules which are seems to be installed $installedModules = Yii::$app->moduleManager->getModules(['returnClass' => true]); foreach ($installedModules as $moduleId => $className) { $this->actionUpdate($moduleId); } /** * Looking up modules which are marked as installed but not loaded. * Try to get recent version online. */ foreach (\humhub\models\ModuleEnabled::getEnabledIds() as $moduleId) { if (!in_array($moduleId, array_keys($installedModules))) { // Module seems to be installed - but cannot be loaded // Try force re-install try { $onlineModules = new OnlineModuleManager(); $onlineModules->install($moduleId); print "Reinstalled: " . $moduleId . "\n"; } catch (Exception $ex) { } } } }
/** * 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(); */ }