Registering new conversation activity

  1. 5 years ago

    I need to execute some code every time a new conversation is being created. The documentation does not fully explain on how to get this done with ET::ActivityModel(). Could you please explain this more?

    The activity model is not what you want — it's used for creating notifications.

    To execute code every time a new conversation is created, you need to hook onto an event in the conversation model's create method. (This will be more obvious once I finish the List of Events in the documentation!)

    public function handler_conversationModel_createAfter($model, $conversation, $postId, $content)
    {
        // do stuff here
    }

    There is currently no createBefore method, but there should be. I'm planning to do a big review of events at some stage, probably for 1.0.0g5. But I can add this one now if you need it?

    (Edit: fixed event function name.)

  2. Toby

    9 May 2014 Administrator Answer
    Edited 5 years ago by Toby

    The activity model is not what you want — it's used for creating notifications.

    To execute code every time a new conversation is created, you need to hook onto an event in the conversation model's create method. (This will be more obvious once I finish the List of Events in the documentation!)

    public function handler_conversationModel_createAfter($model, $conversation, $postId, $content)
    {
        // do stuff here
    }

    There is currently no createBefore method, but there should be. I'm planning to do a big review of events at some stage, probably for 1.0.0g5. But I can add this one now if you need it?

    (Edit: fixed event function name.)

  3. Edited 5 years ago by Tristan

    Nope, createAfter is all I need. I want to rebuild the sitemap after a new conversation has been posted.

  4. Edited 5 years ago by Tristan

    @Toby I am not getting handler_conversationController_createAfter() to execute my code.

    public function handler_conversationController_createAfter($model, $conversation, $postId, $content)
    {
        file_put_contents(PATH_ROOT."/test", "");
    }

    The above code resides just after the setup() method.

    Does not put an empty file named test in the root dir after I created an conversation. Any idea?

  5. Toby

    10 May 2014 Administrator

    My bad — should be handler_conversationModel_createAfter.

 

or Sign Up to reply!