/** * After Save Addons */ public function afterSave($insert, $changedAttributes) { Yii::$app->search->update($this); $user = \humhub\modules\user\models\User::findOne(['id' => $this->created_by]); if ($insert) { // Create new wall record for this space $wall = new Wall(); $wall->object_model = $this->className(); $wall->object_id = $this->id; $wall->save(); $this->wall_id = $wall->id; $this->update(false, ['wall_id']); // Auto add creator as admin $membership = new Membership(); $membership->space_id = $this->id; $membership->user_id = $user->id; $membership->status = Membership::STATUS_MEMBER; $membership->invite_role = 1; $membership->admin_role = 1; $membership->share_role = 1; $membership->save(); $activity = new \humhub\modules\space\activities\Created(); $activity->source = $this; $activity->originator = $user; $activity->create(); } Yii::$app->cache->delete('userSpaces_' . $user->id); return parent::afterSave($insert, $changedAttributes); }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { Yii::$app->search->update($this); $user = \humhub\modules\user\models\User::findOne(['id' => $this->created_by]); if ($insert) { // Auto add creator as admin $membership = new Membership(); $membership->space_id = $this->id; $membership->user_id = $user->id; $membership->status = Membership::STATUS_MEMBER; $membership->group_id = self::USERGROUP_ADMIN; $membership->save(); $activity = new \humhub\modules\space\activities\Created(); $activity->source = $this; $activity->originator = $user; $activity->create(); } Yii::$app->cache->delete('userSpaces_' . $user->id); return parent::afterSave($insert, $changedAttributes); }