Esempio n. 1
0
 /**
  * Callback to validate module database records.
  *
  * @param Event $event
  */
 public static function onIntegrityCheck($event)
 {
     $integrityController = $event->sender;
     $integrityController->showTestHeadline("Space Module - Spaces (" . Space::find()->count() . " entries)");
     foreach (Space::find()->all() as $space) {
         foreach ($space->applicants as $applicant) {
             if ($applicant->user == null) {
                 if ($integrityController->showFix("Deleting applicant record id " . $applicant->id . " without existing user!")) {
                     $applicant->delete();
                 }
             }
         }
     }
     $integrityController->showTestHeadline("Space Module - Module (" . models\Module::find()->count() . " entries)");
     foreach (models\Module::find()->joinWith('space')->all() as $module) {
         if ($module->space == null) {
             if ($integrityController->showFix("Deleting space module" . $module->id . " without existing space!")) {
                 $module->delete();
             }
         }
     }
     $integrityController->showTestHeadline("Space Module - Memberships (" . models\Membership::find()->count() . " entries)");
     foreach (models\Membership::find()->joinWith('space')->all() as $membership) {
         if ($membership->space == null) {
             if ($integrityController->showFix("Deleting space membership" . $membership->space_id . " without existing space!")) {
                 $membership->delete();
             }
         }
         if ($membership->user == null) {
             if ($integrityController->showFix("Deleting space membership" . $membership->user_id . " without existing user!")) {
                 $membership->delete();
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Sets default enabled/disabled on User or/and Space Modules
  *
  * @throws CHttpException
  */
 public function actionSetAsDefault()
 {
     $moduleId = Yii::$app->request->get('moduleId');
     $module = Yii::$app->moduleManager->getModule($moduleId);
     if ($module == null) {
         throw new HttpException(500, Yii::t('AdminModule.controllers_ModuleController', 'Could not find requested module!'));
     }
     if (!$module instanceof ContentContainerModule) {
         throw new HttpException(500, 'Invalid module type!');
     }
     $model = new \humhub\modules\admin\models\forms\ModuleSetAsDefaultForm();
     $spaceDefaultModule = null;
     if ($module->hasContentContainerType(Space::className())) {
         $spaceDefaultModule = \humhub\modules\space\models\Module::findOne(['space_id' => 0, 'module_id' => $moduleId]);
         if ($spaceDefaultModule === null) {
             $spaceDefaultModule = new \humhub\modules\space\models\Module();
             $spaceDefaultModule->module_id = $moduleId;
             $spaceDefaultModule->space_id = 0;
             $spaceDefaultModule->state = \humhub\modules\space\models\Module::STATE_DISABLED;
         }
         $model->spaceDefaultState = $spaceDefaultModule->state;
     }
     $userDefaultModule = null;
     if ($module->hasContentContainerType(User::className())) {
         $userDefaultModule = \humhub\modules\user\models\Module::findOne(['user_id' => 0, 'module_id' => $moduleId]);
         if ($userDefaultModule === null) {
             $userDefaultModule = new \humhub\modules\user\models\Module();
             $userDefaultModule->module_id = $moduleId;
             $userDefaultModule->user_id = 0;
             $userDefaultModule->state = \humhub\modules\user\models\Module::STATE_DISABLED;
         }
         $model->userDefaultState = $userDefaultModule->state;
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($module->hasContentContainerType(Space::className())) {
             $spaceDefaultModule->state = $model->spaceDefaultState;
             $spaceDefaultModule->save();
         }
         if ($module->hasContentContainerType(User::className())) {
             $userDefaultModule->state = $model->userDefaultState;
             $userDefaultModule->save();
         }
         return $this->renderModalClose();
     }
     return $this->renderAjax('setAsDefault', array('module' => $module, 'model' => $model));
 }
Esempio n. 3
0
 /**
  * Uninstalls a Module
  */
 public function disableModule($moduleId)
 {
     // Not enabled globally
     if (!array_key_exists($moduleId, $this->getAvailableModules())) {
         return false;
     }
     // Already enabled module
     if (!$this->isModuleEnabled($moduleId)) {
         Yii::error("Space->disableModule(" . $moduleId . ") module is not enabled");
         return false;
     }
     // New Way: Handle it directly in module class
     $module = Yii::$app->moduleManager->getModule($moduleId);
     $module->disableContentContainer($this->owner);
     $spaceModule = \humhub\modules\space\models\Module::findOne(['space_id' => $this->owner->id, 'module_id' => $moduleId]);
     if ($spaceModule == null) {
         $spaceModule = new \humhub\modules\space\models\Module();
         $spaceModule->space_id = $this->owner->id;
         $spaceModule->module_id = $moduleId;
     }
     $spaceModule->state = \humhub\modules\space\models\Module::STATE_DISABLED;
     $spaceModule->save();
     return true;
 }
Esempio n. 4
0
 /**
  * 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);
 }