Exemple #1
0
 public static function onSpaceDelete($event)
 {
     $space = $event->sender;
     models\WallEntry::deleteAll(['wall_id' => $space->wall_id]);
     models\Wall::deleteAll(['id' => $space->wall_id]);
     foreach (Content::findAll(['space_id' => $space->id]) as $content) {
         $content->delete();
     }
     return true;
 }
Exemple #2
0
 /**
  * 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);
 }
Exemple #3
0
 public function testAutoWallCreation()
 {
     $user = new User();
     $user->username = "******";
     $user->email = "*****@*****.**";
     $this->assertTrue($user->save());
     $this->assertNotNull($user->wall_id);
     $wall = Wall::findOne(['id' => $user->wall_id]);
     $this->assertNotNull($wall);
 }
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($insert) {
         $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']);
         $contentContainer = new ContentContainer();
         $contentContainer->guid = $this->guid;
         $contentContainer->class = $this->className();
         $contentContainer->pk = $this->getPrimaryKey();
         $contentContainer->wall_id = $this->wall_id;
         if ($this instanceof User) {
             $contentContainer->owner_user_id = $this->id;
         } elseif ($this->hasAttribute('created_by')) {
             $contentContainer->owner_user_id = $this->created_by;
         }
         $contentContainer->save();
         $this->contentcontainer_id = $contentContainer->id;
         $this->update(false, ['contentcontainer_id']);
     }
     parent::afterSave($insert, $changedAttributes);
 }