/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { if ($this->scenario == 'edit') { \humhub\modules\user\models\GroupAdmin::deleteAll(['group_id' => $this->id]); $adminUsers = array(); foreach (explode(",", $this->adminGuids) as $adminGuid) { // Ensure guids valid characters $adminGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $adminGuid); // Try load user $user = \humhub\modules\user\models\User::findOne(['guid' => $adminGuid]); if ($user != null) { $groupAdmin = new GroupAdmin(); $groupAdmin->user_id = $user->id; $groupAdmin->group_id = $this->id; $groupAdmin->save(); } } } parent::afterSave($insert, $changedAttributes); }
/** * 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]); GroupAdmin::deleteAll(['user_id' => $this->id]); Session::deleteAll(['user_id' => $this->id]); Setting::deleteAll(['user_id' => $this->id]); return parent::beforeDelete(); }