示例#1
0
 /**
  * Initializes the module manager
  */
 public function init()
 {
     parent::init();
     if (Yii::app()->params['installed']) {
         // Load all enabled modules
         $cacheId = "enabledModules";
         $cacheValue = Yii::app()->cache->get($cacheId);
         if ($cacheValue === false || !is_array($cacheValue)) {
             foreach (ModuleEnabled::model()->findAll() as $em) {
                 $this->enabledModules[] = $em->module_id;
             }
             Yii::app()->cache->set($cacheId, $this->enabledModules, HSetting::Get('expireTime', 'cache'));
         } else {
             $this->enabledModules = $cacheValue;
         }
     }
     // Intercept this controller
     Yii::app()->interceptor->intercept($this);
 }
示例#2
0
 /**
  * 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;
 }