Ejemplo n.º 1
0
 /**
  * Returns a settings record by Name and Module Id
  * The result is cached.
  *
  * @param type $spaceId
  * @param type $name
  * @param type $moduleId
  * @return \HSetting
  */
 private static function GetRecord($spaceId, $name, $moduleId = "core")
 {
     if ($moduleId == "") {
         $moduleId = "core";
     }
     $cacheId = 'SpaceSetting_' . $spaceId . '_' . $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, 'space_id' => $spaceId);
     if ($moduleId != "") {
         $params['module_id'] = $moduleId;
     } else {
         $condition = "module_id IS NULL";
     }
     $record = SpaceSetting::model()->findByAttributes($params, $condition);
     if ($record == null) {
         $record = new SpaceSetting();
         $record->space_id = $spaceId;
         $record->module_id = $moduleId;
         $record->name = $name;
     } else {
         $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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
 /**
  * Before deletion of a Space
  */
 protected function beforeDelete()
 {
     foreach (SpaceSetting::model()->findAllByAttributes(array('space_id' => $this->id)) as $spaceSetting) {
         $spaceSetting->delete();
     }
     // Disable all enabled modules
     foreach ($this->getAvailableModules() as $moduleId => $module) {
         if ($this->isModuleEnabled($moduleId)) {
             $this->disableModule($moduleId);
         }
     }
     HSearch::getInstance()->deleteModel($this);
     $this->getProfileImage()->delete();
     // Remove all Follwers
     UserFollow::model()->deleteAllByAttributes(array('object_id' => $this->id, 'object_model' => 'Space'));
     //Delete all memberships:
     //First select, then delete - done to make sure that SpaceMembership::beforeDelete() is triggered
     $spaceMemberships = SpaceMembership::model()->findAllByAttributes(array('space_id' => $this->id));
     foreach ($spaceMemberships as $spaceMembership) {
         $spaceMembership->delete();
     }
     UserInvite::model()->deleteAllByAttributes(array('space_invite_id' => $this->id));
     // Delete all content objects of this space
     foreach (Content::model()->findAllByAttributes(array('space_id' => $this->id)) as $content) {
         $content->delete();
     }
     // When this workspace is used in a group as default workspace, delete the link
     foreach (Group::model()->findAllByAttributes(array('space_id' => $this->id)) as $group) {
         $group->space_id = "";
         $group->save();
     }
     Wall::model()->deleteAllByAttributes(array('id' => $this->wall_id));
     return parent::beforeDelete();
 }