Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Import Comments from Database

hello! hope you can help me and excuse me ahead time for my bad English.

i'm trying to understand how and where Vanilla read the database to import/save Comments from/to GDN_Comment table. simply, i would like to customize this process as i want.

i already kept an eye on the API (Vanilla's) but unfortunatelly i didn't find anything of useful...
...maybe i was looking for the wrong thing? dunno.

anyway i'm not asking your help to create a script for me, i'm asking for which files i must look at and edit.

thanks for your attention.


  • BleistivtBleistivt Moderator
    edited March 2015

    You can use the event BeforeSaveComment of the comment model for that.

    So the event handler would be called:

    public function CommentModel_BeforeSaveComment_Handler($Sender) {

    where $Sender->EventArguments['FormPostValues'] contains the row to be saved to the database, which you can modify.

    The DiscussionModel fires the same event, btw.

    edit: I just read that you want to modify them after they are read from the DB too, so that would be


    $Sender->EventArguments['Comments'] contains the comments.

  • @Bleistivt - thank you very much for your answer. i perfectly understand what you are suggesting, but i don't think that that answered to my question. don't misunderstand please, your help is appreciated, simply i don't think that that solved my question.

    example: let's think about users' private messages/conversations.
    in order to handle some calls from the database, you need to look at:
    "vanilla\applications\conversations\views\messages\messages.php" - like 43

    that's what i meant..

    i mean to find the exact line where you can look at an explicit dealing with the database. my objective is to find and edit a single value, not to overwrite the whole Array. if i understood correctly, EventArguments['FormPostValues'] is an Array (isn't it?), but its info must be handled somewhere.. right? where..

    kindly, could you confirm if i should look at the following file?

    thanks for your patience.

  • R_JR_J Ex-Fanboy Munich Admin

    You are right concerning the file to look at. It is the CommentModel. But save yourself from trouble by altering file this and that. In order to understand what to do, you have to look at the files and then write a plugin to change what you like.

    <?php if (!defined('APPLICATION')) die();
    $PluginInfo['Aah'] = array(
      'Name' => 'Aah!',
      'Description' => 'Just a barebone plugin for testing',
      'Version' => '0.1',
      'Author' => 'Robin'
    class AahPlugin extends Gdn_Plugin {
        public function commentModel_beforeSave_handler ($sender) {
            $sender->EventArguments['FormPostValues']['Body'] = 'Everyone now says the same ;-)';

    This is all you need to change a field before it is written to db, but don't use this plugin in your productive environment: before a comment is saved, the body is set to that example sentence. So looking at your forum would become very boring =)

    It just shows how things work.

    Do you mind explaining what you try to achieve?

  • redpillarredpillar New
    edited March 2015

    @R_J - thanks for your suggestions.
    and, no, i don't mind to answer to your question.

    i have been told to update a very old forum made with PHPNuke and dedicated to engineering purposes. the website is huge in fact of content (you can imagine: demo scripts, quotes etc.). i already created my own script to clean all posts from their silly tags and bbSecurityCodes - Vanilla won't ever support those information anyway, correct?

    that said, let's move on. - i will always want to be able to distinguish new posts from old ones. so i encoded most of the old messages (base64). in this way i won't have to worry about any of the missing special html characters. shortly, now, i have got a full encoded database. at this moment i have no time to optimize my script and make a proper conversion.

    that's why i urgently needed to know how-and-where to catch Vanilla's export/import functions for comments.


  • R_JR_J Ex-Fanboy Munich Admin

    I thought export/import is just an awkward expression but you really mean that, don't you? So you want to add some kind of flag to base64 encoded discussions/comments that you import? I would suggest you (ab)use the field format and insert "base64" in there, although I think it would be better to save them as HTML in your db.

  • BleistivtBleistivt Moderator
    edited March 2015

    @redpillar said:
    that said, let's move on. - i will always want to be able to distinguish new posts from old ones. so i encoded most of the old messages (base64). in this way i won't have to worry about any of the missing special html characters.

    This only creates unnecessary complexity.

    You can change the "Format" column on these comments to "Raw", which prevents any HTML processing.

    Anyway, what you want to do can easily be wrapped into a plugin. It will only save you time. Try to never hack the core.

    line 12 in @R_J's code:

    $sender->EventArguments['FormPostValues']['Body'] = base64_encode($sender->EventArguments['FormPostValues']['Body']);

    let us know if you need more help.

  • i didn't ask for any script, but i got some anyway. that's awesome.

    @Bleistivt, @R_J - please, pay attention to my words as well.
    "at this moment i have no time to optimize my script and make a proper conversion."

    obviously i won't leave a fully encoded database. on the contrary i admit that that should be really stupid - time-to-time i will fix it - right now i must focus on the design part, that's my job. thanks for your understanding.

    @Bleistivt - surely i will need further help to implement some common javascript libraries. i cannot ever know what "they" want to do with Vanilla after the restyling.

  • @Bleistivt - you were right. i just realized how to copy the comments directly from the old database to the new one without encoding everything. that said, i have done and finished successfully my first made-in-home-parser from PHPNuke to Vanilla.

    thank you all for your help and attention.


Sign In or Register to comment.