Beispiel #1
0
 /**
  * Before Delete of a User
  *
  */
 public function beforeDelete()
 {
     // We don't allow deletion of users who owns a space - validate that
     foreach (\humhub\modules\space\models\Membership::GetUserSpaces($this->id) as $space) {
         if ($space->isSpaceOwner($this->id)) {
             throw new Exception("Tried to delete a user which is owner of a space!");
         }
     }
     // Disable all enabled modules
     foreach ($this->getAvailableModules() as $moduleId => $module) {
         if ($this->isModuleEnabled($moduleId)) {
             $this->disableModule($moduleId);
         }
     }
     // Delete profile image
     $this->getProfileImage()->delete();
     // Remove from search index
     Yii::$app->search->delete($this);
     // Cleanup related tables
     Invite::deleteAll(['user_originator_id' => $this->id]);
     Follow::deleteAll(['user_id' => $this->id]);
     Follow::deleteAll(['object_model' => $this->className(), 'object_id' => $this->id]);
     Password::deleteAll(['user_id' => $this->id]);
     Profile::deleteAll(['user_id' => $this->id]);
     GroupUser::deleteAll(['user_id' => $this->id]);
     Session::deleteAll(['user_id' => $this->id]);
     return parent::beforeDelete();
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function beforeDelete()
 {
     foreach (Setting::findAll(['space_id' => $this->id]) as $spaceSetting) {
         $spaceSetting->delete();
     }
     foreach ($this->getAvailableModules() as $moduleId => $module) {
         if ($this->isModuleEnabled($moduleId)) {
             $this->disableModule($moduleId);
         }
     }
     Yii::$app->search->delete($this);
     $this->getProfileImage()->delete();
     \humhub\modules\user\models\Follow::deleteAll(['object_id' => $this->id, 'object_model' => 'Space']);
     foreach (Membership::findAll(['space_id' => $this->id]) as $spaceMembership) {
         $spaceMembership->delete();
     }
     \humhub\modules\user\models\Invite::deleteAll(['space_invite_id' => $this->id]);
     // When this workspace is used in a group as default workspace, delete the link
     foreach (\humhub\modules\user\models\Group::findAll(['space_id' => $this->id]) as $group) {
         $group->space_id = "";
         $group->save();
     }
     return parent::beforeDelete();
 }