/** * 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(); */ }
/** * Uninstalls a module * * You may overwrite this method to add more cleanup stuff. * * This method shall: * - Delete all module files * - Delete all modules tables, database changes */ public function uninstall() { if ($this->isCoreModule) { throw new CException("Could not uninstall core modules!"); return; } if ($this->isEnabled()) { $this->disable(); } // Use uninstall migration, when found $uninstallMigration = $this->getPath() . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR . 'uninstall.php'; if (file_exists($uninstallMigration)) { Yii::import("application.commands.shell.*"); ob_start(); require_once $uninstallMigration; $migration = new uninstall(); $migration->setDbConnection(Yii::app()->db); try { $migration->up(); } catch (Exception $ex) { } ob_get_clean(); } // Delete all executed migration by module $command = Yii::app()->db->createCommand('DELETE FROM migration WHERE module = :moduleId'); $command->execute(array(':moduleId' => $this->getId())); Yii::app()->moduleManager->removeModuleFolder($this->getId()); ModuleManager::flushCache(); }
/** * 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() { /** * 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(); } } foreach (\humhub\modules\content\models\ContentContainerSetting::findAll(['module_id' => $this->id]) as $containerSetting) { $containerSetting->delete(); } foreach (\humhub\models\Setting::findAll(['module_id' => $this->id]) as $containerSetting) { $containerSetting->delete(); } foreach (\humhub\modules\user\models\Module::findAll(['module_id' => $this->id]) as $userModule) { $userModule->delete(); } foreach (\humhub\modules\space\models\Module::findAll(['module_id' => $this->id]) as $spaceModule) { $spaceModule->delete(); } Yii::$app->moduleManager->disable($this); }