/** * Disables a module * * Which means delete all (user-) data created by the module. * */ public function disable() { if (!$this->isEnabled() || $this->isCoreModule) { return false; } // Check this module is a SpaceModule if ($this->isSpaceModule()) { foreach ($this->getSpaceModuleSpaces() as $space) { $space->disableModule($this->getId()); } } // Check this module is a UserModule if ($this->isUserModule()) { foreach ($this->getUserModuleUsers() as $user) { $user->disableModule($this->getId()); } } // Disable module in database $moduleEnabled = ModuleEnabled::model()->findByPk($this->getId()); if ($moduleEnabled != null) { $moduleEnabled->delete(); } 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(); return true; }
/** * Returns a registry record by Name and Module Id * The result is cached. * * @param type $name * @param type $moduleId * @return \HSetting */ private static function GetRecord($name, $moduleId = "") { $cacheId = 'HSetting_' . $name . '_' . $moduleId; // Check if stored in Runtime Cache if (RuntimeCache::Get($cacheId) !== false) { return RuntimeCache::Get($cacheId); } // Check if stored in Cache $cacheValue = Yii::app()->cache->get($cacheId); if ($cacheValue !== false) { return $cacheValue; } $condition = ""; $params = array('name' => $name); if ($moduleId != "") { $params['module_id'] = $moduleId; } else { $condition = "module_id IS NULL or module_id = ''"; } $record = HSetting::model()->findByAttributes($params, $condition); if ($record == null) { $record = new HSetting(); $record->name = $name; $record->module_id = $moduleId; } $expireTime = 3600; if ($record->name != 'expireTime' && $record->module_id != "cache") { $expireTime = HSetting::Get('expireTime', 'cache'); } Yii::app()->cache->set($cacheId, $record, $expireTime); RuntimeCache::Set($cacheId, $record); return $record; }